博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
grafana+SimpleJson配置图表
阅读量:6804 次
发布时间:2019-06-26

本文共 6007 字,大约阅读时间需要 20 分钟。

hot3.png

package com.cn.hnust.controller;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;@Controller@RequestMapping("/json")public class JsonController {	//设置数据源	@RequestMapping()	@ResponseBody	public Map list(HttpServletRequest request,HttpServletResponse response) {		response.setHeader("Access-Control-Allow-Headers", "accept, content-type");        response.setHeader("Access-Control-Allow-Methods", "POST");        response.setHeader("Access-Control-Allow-Origin", "*");        response.setHeader("Accept", "application/json");        response.setHeader("Content-Type", "application/json");        response.setHeader("Authorization", "Bearer eyJrIjoidGFIOW41aHRoMXZ5aTkxcDBNYUxteDk3TU9zVUhoSkUiLCJuIjoiZ3JhZmFuYV90ZXN0IiwiaWQiOjF9");        Map
map = new HashMap
(); map.put("result", "200 ok"); return map; } //设置参数 @RequestMapping("/search") @ResponseBody public List search(HttpServletRequest request,HttpServletResponse response) { response.setHeader("Access-Control-Allow-Headers", "accept, content-type"); response.setHeader("Access-Control-Allow-Methods", "POST"); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Accept", "application/json"); response.setHeader("Content-Type", "application/json"); response.setHeader("Authorization", "Bearer eyJrIjoidGFIOW41aHRoMXZ5aTkxcDBNYUxteDk3TU9zVUhoSkUiLCJuIjoiZ3JhZmFuYV90ZXN0IiwiaWQiOjF9"); List
result = new ArrayList
(); result.add("CPU"); result.add("RAM"); result.add("LOAD"); result.add("SWAP"); result.add("DISK"); result.add("NET"); return result; } //查询 @RequestMapping("/query") @ResponseBody public List query(@RequestBody Map
params, HttpServletRequest request,HttpServletResponse response) { List
> result = new ArrayList
>() ; List
targetList = (List) params.get("targets"); for (Map targetMap : targetList){ String target = (String)targetMap.get("target"); //Map scopedVars = (Map) params.get("scopedVars"); //Map IP = (Map) scopedVars.get("IP"); //String nodeIP = (String) IP.get("text"); if (target.equals("CPU")){ result.add(strjson());//放入json数据 }else if (target.equals("RAM")){ result.add(null);//放入json数据 }else if (target.equals("LOAD")) { result.add(null); }else if (target.equals("SWAP")){ result.add(null); }else if(target.equals("DISK")){ result.add(null); }else if (target.equals("NET")){ result.add(null); } } response.setHeader("Access-Control-Allow-Headers", "accept, content-type"); response.setHeader("Access-Control-Allow-Methods", "POST"); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Accept", "application/json"); response.setHeader("Content-Type", "application/json"); response.setHeader("Authorization", "Bearer eyJrIjoidGFIOW41aHRoMXZ5aTkxcDBNYUxteDk3TU9zVUhoSkUiLCJuIjoiZ3JhZmFuYV90ZXN0IiwiaWQiOjF9"); Collections.sort(result, new Comparator
>() { public int compare(Map
o1, Map
o2) { String name1 = String.valueOf(o1.get("target").toString()) ; String name2 = String.valueOf(o2.get("target").toString()) ; return name1.compareTo(name2); } }); return result; } private Map
strjson() { //String str = "{\"A\":{\"tables\":[{\"columns\":[{\"text\":\"序列\",\"sort\":true,\"desc\":true,\"title\":\"序列\",\"style\":{\"alias\":\"\",\"colorMode\":null,\"colors\":[\"rgba(245, 54, 54, 0.9)\",\"rgba(237, 129, 40, 0.89)\",\"rgba(50, 172, 45, 0.97)\"],\"decimals\":2,\"pattern\":\"/.*/\",\"thresholds\":[],\"type\":\"number\",\"unit\":\"short\"},\"hidden\":false,\"$$hashKey\":\"object:644\"},{\"text\":\"水果名称12\",\"title\":\"水果名称12\",\"style\":{\"alias\":\"\",\"colorMode\":null,\"colors\":[\"rgba(245, 54, 54, 0.9)\",\"rgba(237, 129, 40, 0.89)\",\"rgba(50, 172, 45, 0.97)\"],\"decimals\":2,\"pattern\":\"/.*/\",\"thresholds\":[],\"type\":\"number\",\"unit\":\"short\"},\"hidden\":false,\"$$hashKey\":\"object:645\"},{\"text\":\"价钱\",\"title\":\"价钱\",\"style\":{\"alias\":\"\",\"colorMode\":null,\"colors\":[\"rgba(245, 54, 54, 0.9)\",\"rgba(237, 129, 40, 0.89)\",\"rgba(50, 172, 45, 0.97)\"],\"decimals\":2,\"pattern\":\"/.*/\",\"thresholds\":[],\"type\":\"number\",\"unit\":\"short\"},\"hidden\":false,\"$$hashKey\":\"object:646\"},{\"text\":\"重量(kg)\",\"title\":\"重量(kg)\",\"style\":{\"alias\":\"\",\"colorMode\":null,\"colors\":[\"rgba(245, 54, 54, 0.9)\",\"rgba(237, 129, 40, 0.89)\",\"rgba(50, 172, 45, 0.97)\"],\"decimals\":2,\"pattern\":\"/.*/\",\"thresholds\":[],\"type\":\"number\",\"unit\":\"short\"},\"hidden\":false,\"$$hashKey\":\"object:647\"},{\"text\":\"总价钱\",\"title\":\"总价钱\",\"style\":{\"alias\":\"\",\"colorMode\":null,\"colors\":[\"rgba(245, 54, 54, 0.9)\",\"rgba(237, 129, 40, 0.89)\",\"rgba(50, 172, 45, 0.97)\"],\"decimals\":2,\"pattern\":\"/.*/\",\"thresholds\":[],\"type\":\"number\",\"unit\":\"short\"},\"hidden\":false,\"$$hashKey\":\"object:648\"}],\"rows\":[[1,\"水果01\",4,2,8],[2,\"水果02\",5,2,10],[3,\"水果03\",6,2,12],[4,\"水果04\",7,2,14],[5,\"水果05\",8,2,16]]}]}}"; Map
map = new HashMap<>(); JSONArray ja = new JSONArray(); for (int i = 0; i < 10; i++) { JSONObject jb = new JSONObject(); jb.put("num", 10*i); jb.put("createTime", "2019-05-09T"+(11+i)+":01:01"); ja.add(jb); } map.put("reasult", ja); return map; } //添加注解 @RequestMapping("/annotations") @ResponseBody public Map Annotations() { Map
map = new HashMap
(); map.put("result", "200 ok"); return map; }}

 

转载于:https://my.oschina.net/lisc2016/blog/3047585

你可能感兴趣的文章
即将搭载人工智能芯片的华为Mate10,究竟会为业界带来什么?
查看>>
Android实现登录小demo
查看>>
AgentWeb是基于Android WebView一个功能完善小型浏览器库
查看>>
开放数据中心联盟推8个云计算应用模型
查看>>
学习数据分析的“里程碑”是什么?
查看>>
数据科学与DevOps之间的差距还有救吗?
查看>>
信息化一周回顾:金融业大数据十大趋势
查看>>
Http、TCP/IP协议与Socket之间的区别
查看>>
文思海辉:智慧数据避免企业成为大数据时代落伍者
查看>>
迅雷发布“星域CDN” 做条颠覆市场的鲶鱼
查看>>
英国《数字经济法案》
查看>>
Asp.net与Flex交互测试记录
查看>>
运维前线:一线运维专家的运维方法、技巧与实践1.8 运维自动化依赖的团队模型...
查看>>
《树莓派渗透测试实战》——第1章 树莓派和Kali Linux基础知识
查看>>
《圣殿祭司的ASP.NET4.0专家技术手册》----1-7 HTML5与CSS3的支持
查看>>
数据结构之链表
查看>>
八年了必须放手了,我不是你妈妈
查看>>
Eric S. Raymond 五部曲
查看>>
《Ansible权威指南 》一2.7 本章小结
查看>>
《iOS编程指南》——2.4节安装iOS SDK
查看>>