Authored by zhengyouwei

zookeep write

package com.monitor.common;
/**
* Created by zhengyouwei on 2016/6/13.
*/
public class Test {
}
package com.monitor.common.contants;
public class InfluxDBContants {
/**
* influxdb安装源
*/
public static final String AWS = "aws";
public static final String Q_CLOUD = "qcloud";
public static final String ALARM = "alarm";
/**
* influxdb监控数据源
... ... @@ -11,14 +20,16 @@ public class InfluxDBContants {
public static final String YOHO_ORDER = "yoho_order";
public static final String YOHO_ALARM = "yoho_alarm";
public static final String APP_ALARM = "app_alarm";
public static final String MIDDLEWARE_ALARM = "middleware_alarm";
/**
* influxdb 表
*/
public static final String YOMO_TB_JAVAAPI = "yoho_javaapi_statics";
public static final String ZOOKEEPER_ALARM= "zookeerp_alarm";
... ...
... ... @@ -67,15 +67,6 @@ public class InluxDBSingle {
return map;
}
/**
* 获取所有的DB name,用于选择
*
* @return
*/
public List<String> getDBNames() {
return new ArrayList<String>(map.keySet());
}
private String nums;
private String names;
... ...
package com.monitor.influxdb.mapper;
public interface IpAccessMapper {
public void insert(String ip, String event);
public void insertFailed(String ip, String event);
public int getIpCnt(String ip);
}
package com.monitor.influxdb.mapper.impl;
import com.monitor.common.contants.InfluxDBContants;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.mapper.IZookeeperMapper;
import com.monitor.influxdb.model.ZookeeperInfo;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/**
* Created by yoho on 2016/6/21.
*/
... ... @@ -15,8 +21,19 @@ public class ZookeeperMapper implements IZookeeperMapper{
@Autowired
private InluxDBSingle inluxDBSingle;
Random random = new Random();
@Override
public void insert(String influxDBName, ZookeeperInfo zkInfo) {
Point point = Point.measurement(InfluxDBContants.ZOOKEEPER_ALARM)
.addField("id", zkInfo.getId())
.addField("hostIp", zkInfo.getHostIp())
.addField("isLive", zkInfo.getIsLive())
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
.build();
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
.write(InfluxDBContants.MIDDLEWARE_ALARM, "default", point);
}
}
... ...