...
|
...
|
@@ -4,11 +4,20 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.monitor.common.contants.InfluxDBContants;
|
|
|
import com.monitor.influxdb.InluxDBSingle;
|
|
|
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
|
|
|
import com.monitor.model.domain.JavaApiStaticsModel;
|
|
|
import org.influxdb.dto.BatchPoints;
|
|
|
import org.influxdb.dto.Point;
|
|
|
import org.influxdb.dto.Query;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by fruwei on 2016/6/21.
|
|
|
*/
|
...
|
...
|
@@ -18,6 +27,8 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
@Autowired
|
|
|
private InluxDBSingle inluxDBSingle;
|
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
|
@Override
|
|
|
public void insertJavaApiStatics(String influxDBName, JSONObject statics) {
|
|
|
|
...
|
...
|
@@ -25,7 +36,9 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
BatchPoints batchPoints = BatchPoints
|
|
|
.database(InfluxDBContants.APP_ALARM).retentionPolicy("default")
|
|
|
.build();
|
|
|
Point point = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
|
|
|
Point.Builder pointBuilder = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
|
|
|
.tag("api_id", "api_id")
|
|
|
.tag("mobj_id", "mobj_id")
|
|
|
.addField("api_id", statics.getIntValue("api_id"))
|
|
|
.addField("api_name", statics.getString("api_name"))
|
|
|
.addField("api_type", statics.getIntValue("api_type"))
|
...
|
...
|
@@ -37,14 +50,75 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
.addField("start", statics.getLongValue("end"))
|
|
|
.addField("end", statics.getLongValue("end"))
|
|
|
.addField("is_exception", statics.getBooleanValue("is_exception"))
|
|
|
.addField("exception", statics.getString("exception"))
|
|
|
.build();
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS);
|
|
|
|
|
|
if (statics.getBooleanValue("is_exception") == true) {
|
|
|
pointBuilder.addField("exception", statics.getString("exception"));
|
|
|
} else {
|
|
|
pointBuilder.addField("response", statics.getString("response"));
|
|
|
}
|
|
|
|
|
|
Point point = pointBuilder.build();
|
|
|
batchPoints.point(point);
|
|
|
|
|
|
inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
|
|
|
.write(batchPoints);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, Map<String, Integer> param) {
|
|
|
int api_id = param.get("api_id");
|
|
|
int mobj_id = param.get("mobj_id");
|
|
|
String sql = "select * from " + InfluxDBContants.YOMO_TB_JAVAAPI + " where time > now() - 1h ";
|
|
|
sql += " and api_id=" + param.get("api_id");
|
|
|
sql += " and mobj_id=" + param.get("mobj_id");
|
|
|
sql += " order by time desc limit 1";
|
|
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
|
|
|
|
|
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query);
|
|
|
|
|
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
|
|
javaApiStaticsModel.setServiceId(api_id);
|
|
|
javaApiStaticsModel.setMObjectId(mobj_id);
|
|
|
javaApiStaticsModel.setStatus(0);
|
|
|
|
|
|
QueryResult.Result rel = result.getResults().get(0);
|
|
|
|
|
|
try {
|
|
|
QueryResult.Series series = rel.getSeries().get(0);
|
|
|
|
|
|
Boolean status = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
|
|
|
|
|
|
if (status == true) {
|
|
|
javaApiStaticsModel.setStatus(1);
|
|
|
} else
|
|
|
javaApiStaticsModel.setStatus(0);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return javaApiStaticsModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<Map<String, Integer>> paramList) {
|
|
|
|
|
|
//TODO 后期改批量查询
|
|
|
|
|
|
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<>();
|
|
|
|
|
|
for (Map<String, Integer> param : paramList) {
|
|
|
JavaApiStaticsModel model = selectlatestJavaApiStatics(influxDBName, param);
|
|
|
javaApiStaticsModels.add(model);
|
|
|
}
|
|
|
|
|
|
return javaApiStaticsModels;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|