Grafana客制化无限下钻
- 1.使用场景:DB对应InfluxDB
- 2.插入infliux逻辑
- 3.展示数据
- 4.Router Service
我要用Grafana展示两种DB的数据,一种是Relational Database,另一种是Sap Database(如ERP,BW等)。众所周知,RDB结构很理想,Database -> schema ->table or view > column ,而Sap DB数据结构相对来说比较复杂,Database level对应的就是 BW_System,Sap_System,其他的则对应table level
2.插入infliux逻辑下面的则对应column level
- 将查出的Database level的数据将parentId设为0,
- 将查出的Schema level 的parentId 设为对应Database的id
- 将查出的Table(View) level的parentId设为对应Schema的id
- 将查出的Column level的parentId设为对应Table的id
- 第一个Dashboard通过插入时的tag作为筛选条件,将parentId = 0的全部查出
.addField("content", transform(commonData.getContent())) .addField("contentOld", transform(commonData.getContentOld())) .addField("updateTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(commonData.getUpdateTime())) .tag("integratorTag", k) .tag("pareTagId", commonData.getParentId().intValue() + "") .build());
将objectId设置超链,点击后获取objectId的值给到url,link到第二个Dashboard
- 第二个Dashboard相对简单,link自己,也是携带objectId作为parentId
问题1:对于Sap DB,table level的下一层还可能是 table level
问题2:因为是先有Dashboard,后有的link,column level还有在跳转一次空Dashboard
此处使用java开发了Router Service
来判断grafana的请求是分配给第二个Dashboard,还是第三个Dashboard
- 添加了第三个Dashboard
完全复制第二个Dashboard,但是override没有data link
4.Router Service
依赖
org.springframework.boot spring-boot-starter-web
Controller
@RequestMapping("/parseUrl") public ModelAndView parseUrl(HttpServletRequest request, HttpServletResponse response) { //获取所有参数,map的key是你自己定义的 String queryString = request.getQueryString(); String[] split = queryString.split("&"); MapresultMap = new HashMap(); for (String element : split) { String[] every = element.split("="); resultMap.put(every[0],every[1]); } String newUrl = ""; if (resultMap.get("objectType").contains("Field") || resultMap.get("objectType").contains("Column")) { System.out.println("column level"); newUrl = "grafana url xxx/showbottom?orgId=1&var-parentId=" + resultMap.get("parentId")+"&var-rollbackId="+resultMap.get("rollbackId"); } else { System.out.println( "table level"); newUrl = "grafana url xxxx/showmiddle?orgId=1&var-parentId=" + resultMap.get("objectId")+"&var-rollbackId="+resultMap.get("parentId"); } RedirectView redirectView = new RedirectView(newUrl); ModelAndView mv = new ModelAndView(redirectView); return mv; }
- 同时我用link作为他的返回上一级
- 也是要判断爸爸是table level还是 Database level (针对sap)
上面的url路径 :http://localhost:8087/router/rollback?parentId=${parentId}
@RequestMapping("/rollback") public ModelAndView rollback(HttpServletRequest request, HttpServletResponse response) { String queryString = request.getQueryString(); String[] split = queryString.split("&"); MapresultMap = new HashMap(); for (String element : split) { String[] every = element.split("="); resultMap.put(every[0],every[1]); } String parentId = resultMap.get("parentId"); int grandId = routerService.getGrandId(parentId); String newUrl = ""; if (grandId == 0) { System.out.println("top level"); newUrl = "grafana url xxxx/deltawwst/showtop?orgId=1"; } else { System.out.println("middle level"); newUrl = "grafana url xxxx/showmiddle?orgId=1&var-parentId=" + grandId; } RedirectView redirectView = new RedirectView(newUrl); ModelAndView mv = new ModelAndView(redirectView); return mv; }
这个就灵活的去查吧,连接你自己的DB
int grandId = routerService.getGrandId(parentId);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)