Authored by zhengyouwei

zookeep write

1 -package com.monitor.common;  
2 -  
3 -/**  
4 - * Created by zhengyouwei on 2016/6/13.  
5 - */  
6 -public class Test {  
7 -}  
1 package com.monitor.common.contants; 1 package com.monitor.common.contants;
2 2
3 public class InfluxDBContants { 3 public class InfluxDBContants {
  4 + /**
  5 + * influxdb安装源
  6 + */
  7 + public static final String AWS = "aws";
  8 +
  9 + public static final String Q_CLOUD = "qcloud";
  10 +
  11 + public static final String ALARM = "alarm";
  12 +
4 13
5 /** 14 /**
6 * influxdb监控数据源 15 * influxdb监控数据源
@@ -11,14 +20,16 @@ public class InfluxDBContants { @@ -11,14 +20,16 @@ public class InfluxDBContants {
11 20
12 public static final String YOHO_ORDER = "yoho_order"; 21 public static final String YOHO_ORDER = "yoho_order";
13 22
14 - public static final String YOHO_ALARM = "yoho_alarm"; 23 + public static final String APP_ALARM = "app_alarm";
15 24
  25 + public static final String MIDDLEWARE_ALARM = "middleware_alarm";
16 26
17 /** 27 /**
18 * influxdb 表 28 * influxdb 表
19 */ 29 */
20 public static final String YOMO_TB_JAVAAPI = "yoho_javaapi_statics"; 30 public static final String YOMO_TB_JAVAAPI = "yoho_javaapi_statics";
21 31
  32 + public static final String ZOOKEEPER_ALARM= "zookeerp_alarm";
22 33
23 34
24 35
@@ -67,15 +67,6 @@ public class InluxDBSingle { @@ -67,15 +67,6 @@ public class InluxDBSingle {
67 return map; 67 return map;
68 } 68 }
69 69
70 - /**  
71 - * 获取所有的DB name,用于选择  
72 - *  
73 - * @return  
74 - */  
75 - public List<String> getDBNames() {  
76 - return new ArrayList<String>(map.keySet());  
77 - }  
78 -  
79 private String nums; 70 private String nums;
80 71
81 private String names; 72 private String names;
1 -package com.monitor.influxdb.mapper;  
2 -  
3 -  
4 -public interface IpAccessMapper {  
5 -  
6 - public void insert(String ip, String event);  
7 -  
8 - public void insertFailed(String ip, String event);  
9 -  
10 - public int getIpCnt(String ip);  
11 -  
12 -}  
1 package com.monitor.influxdb.mapper.impl; 1 package com.monitor.influxdb.mapper.impl;
2 2
  3 +import com.monitor.common.contants.InfluxDBContants;
3 import com.monitor.influxdb.InluxDBSingle; 4 import com.monitor.influxdb.InluxDBSingle;
4 import com.monitor.influxdb.mapper.IZookeeperMapper; 5 import com.monitor.influxdb.mapper.IZookeeperMapper;
5 import com.monitor.influxdb.model.ZookeeperInfo; 6 import com.monitor.influxdb.model.ZookeeperInfo;
  7 +import org.influxdb.dto.BatchPoints;
  8 +import org.influxdb.dto.Point;
6 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
8 11
  12 +import java.util.Random;
  13 +import java.util.concurrent.TimeUnit;
  14 +
9 /** 15 /**
10 * Created by yoho on 2016/6/21. 16 * Created by yoho on 2016/6/21.
11 */ 17 */
@@ -15,8 +21,19 @@ public class ZookeeperMapper implements IZookeeperMapper{ @@ -15,8 +21,19 @@ public class ZookeeperMapper implements IZookeeperMapper{
15 @Autowired 21 @Autowired
16 private InluxDBSingle inluxDBSingle; 22 private InluxDBSingle inluxDBSingle;
17 23
  24 + Random random = new Random();
  25 +
18 @Override 26 @Override
19 public void insert(String influxDBName, ZookeeperInfo zkInfo) { 27 public void insert(String influxDBName, ZookeeperInfo zkInfo) {
20 28
  29 + Point point = Point.measurement(InfluxDBContants.ZOOKEEPER_ALARM)
  30 + .addField("id", zkInfo.getId())
  31 + .addField("hostIp", zkInfo.getHostIp())
  32 + .addField("isLive", zkInfo.getIsLive())
  33 + .time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
  34 + .build();
  35 + inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
  36 + .write(InfluxDBContants.MIDDLEWARE_ALARM, "default", point);
  37 +
21 } 38 }
22 } 39 }