Authored by FengRuwei

simple inflxdb insert

package com.monitor.common.contants;
public class InfluxDBContants {
/**
* influxdb监控数据源
*/
public static final String YOMO_MONITOR = "yoho_monitor";
public static final String YOMO_REPORT = "yoho_report";
public static final String YOHO_ORDER = "yoho_order";
public static final String YOHO_ALARM = "yoho_alarm";
/**
* influxdb 表
*/
public static final String YOMO_TB_JAVAAPI = "yoho_javaapi_statics";
}
\ No newline at end of file
... ...
package com.monitor.influxdb.mapper;
import com.alibaba.fastjson.JSONObject;
/**
* Created by fruwei on 2016/6/21.
*/
public interface IJavaApiStaticsMapper {
public void insertJavaApiStatics(String influxDBName,JSONObject statics);
}
... ...
package com.monitor.influxdb.mapper.impl;
import com.alibaba.fastjson.JSONObject;
import com.monitor.common.contants.InfluxDBContants;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by fruwei on 2016/6/21.
*/
@Component
public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
@Autowired
private InluxDBSingle inluxDBSingle;
@Override
public void insertJavaApiStatics(String influxDBName, JSONObject statics) {
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOHO_ALARM).retentionPolicy("default")
.build();
Point point = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
.addField("java_api_info", statics.get("javaApiInfo").toString())
.addField("mobject_info", statics.get("mobject").toString())
.addField("start", statics.getLongValue("start"))
.addField("end", statics.getLongValue("end")).build();
batchPoints.point(point);
if (influxDBName == null) {
influxDBName = inluxDBSingle.getDBNames().get(0);
}
inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);
}
}
... ...
... ... @@ -19,7 +19,7 @@ public class ScheduledPlan {
JavaApiClient javaApiClient;
@Scheduled(fixedRate=60000*3)
@Scheduled(fixedRate=10000)
public void run() {
log.info("task start...");
... ...
package com.monitor.javaserver.handle.impl;
import com.alibaba.fastjson.JSONObject;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.common.JavaApiStatics;
import com.monitor.javaserver.handle.IJavaApiHadnler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* Created by fruwei on 2016/6/20.
*/
@Component("influxDBJavaApiHandler")
public class InfluxDBJavaApiHandler implements IJavaApiHadnler{
Logger log= LoggerFactory.getLogger(InfluxDBJavaApiHandler.class);
public class InfluxDBJavaApiHandler implements IJavaApiHadnler {
Logger log = LoggerFactory.getLogger(InfluxDBJavaApiHandler.class);
@Autowired
private JavaApiStaticsMapper javaApiStaticsMapper;
@Override
public void handler(JavaApiStatics javaApiStatics) {
log.info("handle result: {}",javaApiStatics);
//TODO handle
log.info("handle result: {}", javaApiStatics);
JSONObject jsonObject = new JSONObject();
jsonObject.put("javaApiInfo", javaApiStatics.getJavaApiInfo());
jsonObject.put("mobject", javaApiStatics.getMObjectInfo());
jsonObject.put("statrt", javaApiStatics.getStartTime());
jsonObject.put("end", javaApiStatics.getEndTime());
javaApiStaticsMapper.insertJavaApiStatics(null, jsonObject);
}
... ...
# ******************** influxdb common configs ********************
influxdb.num=2
influxdb.name=aws;qcloud
influxdb.ip=http://127.0.0.1:8086;http://10.66.4.25:8086
influxdb.ip=http://123.206.79.151:8086;http://10.66.4.25:8086
influxdb.user=root;root
influxdb.pwd=root;root
influxdb.connect.timeout=15;15
... ...