Showing
6 changed files
with
99 additions
and
6 deletions
1 | +package com.monitor.common.contants; | ||
2 | + | ||
3 | +public class InfluxDBContants { | ||
4 | + | ||
5 | + /** | ||
6 | + * influxdb监控数据源 | ||
7 | + */ | ||
8 | + public static final String YOMO_MONITOR = "yoho_monitor"; | ||
9 | + | ||
10 | + public static final String YOMO_REPORT = "yoho_report"; | ||
11 | + | ||
12 | + public static final String YOHO_ORDER = "yoho_order"; | ||
13 | + | ||
14 | + public static final String YOHO_ALARM = "yoho_alarm"; | ||
15 | + | ||
16 | + | ||
17 | + /** | ||
18 | + * influxdb 表 | ||
19 | + */ | ||
20 | + public static final String YOMO_TB_JAVAAPI = "yoho_javaapi_statics"; | ||
21 | + | ||
22 | + | ||
23 | + | ||
24 | + | ||
25 | + | ||
26 | +} |
monitor-service-influxdb/src/main/java/com/monitor/influxdb/mapper/impl/JavaApiStaticsMapper.java
0 → 100644
1 | +package com.monitor.influxdb.mapper.impl; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.monitor.common.contants.InfluxDBContants; | ||
5 | +import com.monitor.influxdb.InluxDBSingle; | ||
6 | +import com.monitor.influxdb.mapper.IJavaApiStaticsMapper; | ||
7 | +import org.influxdb.dto.BatchPoints; | ||
8 | +import org.influxdb.dto.Point; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Component; | ||
11 | + | ||
12 | +/** | ||
13 | + * Created by fruwei on 2016/6/21. | ||
14 | + */ | ||
15 | +@Component | ||
16 | +public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { | ||
17 | + | ||
18 | + @Autowired | ||
19 | + private InluxDBSingle inluxDBSingle; | ||
20 | + | ||
21 | + @Override | ||
22 | + public void insertJavaApiStatics(String influxDBName, JSONObject statics) { | ||
23 | + | ||
24 | + | ||
25 | + BatchPoints batchPoints = BatchPoints | ||
26 | + .database(InfluxDBContants.YOHO_ALARM).retentionPolicy("default") | ||
27 | + .build(); | ||
28 | + Point point = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI) | ||
29 | + .addField("java_api_info", statics.get("javaApiInfo").toString()) | ||
30 | + .addField("mobject_info", statics.get("mobject").toString()) | ||
31 | + .addField("start", statics.getLongValue("start")) | ||
32 | + .addField("end", statics.getLongValue("end")).build(); | ||
33 | + batchPoints.point(point); | ||
34 | + if (influxDBName == null) { | ||
35 | + influxDBName = inluxDBSingle.getDBNames().get(0); | ||
36 | + } | ||
37 | + inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB() | ||
38 | + .write(batchPoints); | ||
39 | + | ||
40 | + | ||
41 | + } | ||
42 | +} |
@@ -19,7 +19,7 @@ public class ScheduledPlan { | @@ -19,7 +19,7 @@ public class ScheduledPlan { | ||
19 | JavaApiClient javaApiClient; | 19 | JavaApiClient javaApiClient; |
20 | 20 | ||
21 | 21 | ||
22 | - @Scheduled(fixedRate=60000*3) | 22 | + @Scheduled(fixedRate=10000) |
23 | public void run() { | 23 | public void run() { |
24 | log.info("task start..."); | 24 | log.info("task start..."); |
25 | 25 |
1 | package com.monitor.javaserver.handle.impl; | 1 | package com.monitor.javaserver.handle.impl; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper; | ||
3 | import com.monitor.javaserver.common.JavaApiStatics; | 5 | import com.monitor.javaserver.common.JavaApiStatics; |
4 | import com.monitor.javaserver.handle.IJavaApiHadnler; | 6 | import com.monitor.javaserver.handle.IJavaApiHadnler; |
5 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
6 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
7 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
8 | 11 | ||
9 | /** | 12 | /** |
10 | * Created by fruwei on 2016/6/20. | 13 | * Created by fruwei on 2016/6/20. |
11 | */ | 14 | */ |
12 | @Component("influxDBJavaApiHandler") | 15 | @Component("influxDBJavaApiHandler") |
13 | -public class InfluxDBJavaApiHandler implements IJavaApiHadnler{ | ||
14 | - Logger log= LoggerFactory.getLogger(InfluxDBJavaApiHandler.class); | 16 | +public class InfluxDBJavaApiHandler implements IJavaApiHadnler { |
17 | + Logger log = LoggerFactory.getLogger(InfluxDBJavaApiHandler.class); | ||
18 | + | ||
19 | + @Autowired | ||
20 | + private JavaApiStaticsMapper javaApiStaticsMapper; | ||
15 | 21 | ||
16 | @Override | 22 | @Override |
17 | public void handler(JavaApiStatics javaApiStatics) { | 23 | public void handler(JavaApiStatics javaApiStatics) { |
18 | - log.info("handle result: {}",javaApiStatics); | ||
19 | - //TODO handle | 24 | + log.info("handle result: {}", javaApiStatics); |
25 | + | ||
20 | 26 | ||
27 | + JSONObject jsonObject = new JSONObject(); | ||
28 | + jsonObject.put("javaApiInfo", javaApiStatics.getJavaApiInfo()); | ||
29 | + jsonObject.put("mobject", javaApiStatics.getMObjectInfo()); | ||
30 | + jsonObject.put("statrt", javaApiStatics.getStartTime()); | ||
31 | + jsonObject.put("end", javaApiStatics.getEndTime()); | ||
32 | + javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject); | ||
21 | 33 | ||
22 | 34 | ||
23 | } | 35 | } |
1 | # ******************** influxdb common configs ******************** | 1 | # ******************** influxdb common configs ******************** |
2 | influxdb.num=2 | 2 | influxdb.num=2 |
3 | influxdb.name=aws;qcloud | 3 | influxdb.name=aws;qcloud |
4 | -influxdb.ip=http://127.0.0.1:8086;http://10.66.4.25:8086 | 4 | +influxdb.ip=http://123.206.79.151:8086;http://10.66.4.25:8086 |
5 | influxdb.user=root;root | 5 | influxdb.user=root;root |
6 | influxdb.pwd=root;root | 6 | influxdb.pwd=root;root |
7 | influxdb.connect.timeout=15;15 | 7 | influxdb.connect.timeout=15;15 |
-
Please register or login to post a comment