...
|
...
|
@@ -3,6 +3,7 @@ package com.monitor.influxdb.mapper.impl; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.monitor.common.contants.InfluxDBContants;
|
|
|
import com.monitor.common.util.DateFormatUtil;
|
|
|
import com.monitor.common.util.QueryResultUtil;
|
|
|
import com.monitor.influxdb.InluxDBSingle;
|
|
|
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
|
|
|
import com.monitor.model.domain.JavaApiStaticsModel;
|
...
|
...
|
@@ -11,6 +12,8 @@ import org.influxdb.dto.BatchPoints; |
|
|
import org.influxdb.dto.Point;
|
|
|
import org.influxdb.dto.Query;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
...
|
...
|
@@ -26,6 +29,7 @@ import java.util.concurrent.TimeUnit; |
|
|
@Component
|
|
|
public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
|
|
|
|
|
|
Logger log = LoggerFactory.getLogger(JavaApiStaticsMapper.class);
|
|
|
@Autowired
|
|
|
private InluxDBSingle inluxDBSingle;
|
|
|
|
...
|
...
|
@@ -141,6 +145,7 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
if (mobj_id > 0)
|
|
|
sql += " and mobj_id= " + mobj_id;
|
|
|
sql += " order by time desc LIMIT " + limitCount + " OFFSET " + offsetCount;
|
|
|
log.info("sql:{}", sql);
|
|
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
|
|
|
|
|
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query);
|
...
|
...
|
@@ -150,13 +155,16 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
QueryResult.Result rel = result.getResults().get(0);
|
|
|
|
|
|
|
|
|
if (rel.getSeries() == null) {
|
|
|
return list;
|
|
|
}
|
|
|
QueryResult.Series series = rel.getSeries().get(0);
|
|
|
int size = series.getValues().size();
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
|
|
Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
|
|
|
long startTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("start")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(0).get(series.getColumns().indexOf("end")));
|
|
|
Boolean is_exception = (Boolean) series.getValues().get(i).get(series.getColumns().indexOf("is_exception"));
|
|
|
long startTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("start")));
|
|
|
long endTime = Math.round((Double) series.getValues().get(i).get(series.getColumns().indexOf("end")));
|
|
|
long costTime = (endTime - startTime);
|
|
|
|
|
|
|
...
|
...
|
@@ -166,31 +174,31 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
javaApiStaticsModel.setCostTime((int) costTime);
|
|
|
|
|
|
|
|
|
int a_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("api_id"))).intValue();
|
|
|
int m_id = ((Double) series.getValues().get(0).get(series.getColumns().indexOf("mobj_id"))).intValue();
|
|
|
int a_id = ((Double) series.getValues().get(i).get(series.getColumns().indexOf("api_id"))).intValue();
|
|
|
int m_id = ((Double) series.getValues().get(i).get(series.getColumns().indexOf("mobj_id"))).intValue();
|
|
|
|
|
|
javaApiStaticsModel.setServiceId(a_id);
|
|
|
javaApiStaticsModel.setMObjectId(m_id);
|
|
|
|
|
|
|
|
|
String m_ip = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_ip"));
|
|
|
String m_port = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_port"));
|
|
|
String m_name = (String) series.getValues().get(0).get(series.getColumns().indexOf("mobj_name"));
|
|
|
String m_ip = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_ip"));
|
|
|
String m_port = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_port"));
|
|
|
String m_name = (String) series.getValues().get(i).get(series.getColumns().indexOf("mobj_name"));
|
|
|
javaApiStaticsModel.setMIp(m_ip);
|
|
|
javaApiStaticsModel.setMPort(m_port);
|
|
|
javaApiStaticsModel.setMName(m_name);
|
|
|
|
|
|
String time = (String) series.getValues().get(0).get(series.getColumns().indexOf("time"));
|
|
|
String time = (String) series.getValues().get(i).get(series.getColumns().indexOf("time"));
|
|
|
|
|
|
javaApiStaticsModel.setTime(DateFormatUtil.displayFormat(time));
|
|
|
|
|
|
if (is_exception == true) {
|
|
|
javaApiStaticsModel.setStatus(0);
|
|
|
String exception = (String) series.getValues().get(0).get(series.getColumns().indexOf("exception"));
|
|
|
String exception = (String) series.getValues().get(i).get(series.getColumns().indexOf("exception"));
|
|
|
javaApiStaticsModel.setException(exception);
|
|
|
} else {
|
|
|
javaApiStaticsModel.setStatus(1);
|
|
|
String response = (String) series.getValues().get(0).get(series.getColumns().indexOf("response"));
|
|
|
String response = (String) series.getValues().get(i).get(series.getColumns().indexOf("response"));
|
|
|
javaApiStaticsModel.setResponse(response);
|
|
|
}
|
|
|
list.add(javaApiStaticsModel);
|
...
|
...
|
@@ -198,5 +206,21 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public int countJavaApiStaticHis(String influxDBName, int api_id, int mobj_id, String timeStart, String timeEnd) {
|
|
|
String sql = "select count(api_id) from " + InfluxDBContants.YOMO_TB_JAVAAPI;
|
|
|
sql += " where time >= '" + timeStart + "' and time<= '" + timeEnd + "' ";
|
|
|
if (api_id > 0)
|
|
|
sql += " and api_id= " + api_id;
|
|
|
if (mobj_id > 0)
|
|
|
sql += " and mobj_id= " + mobj_id;
|
|
|
|
|
|
|
|
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
|
|
|
|
|
QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB().query(query);
|
|
|
|
|
|
return QueryResultUtil.getCount(result);
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|