Authored by FengRuwei

查询influxdb javaapi statics

... ... @@ -2,10 +2,9 @@ package com.monitor.influxdb.mapper;
import com.alibaba.fastjson.JSONObject;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.response.JavaApiStatusRep;
import com.monitor.model.request.JavaApiStatusReq;
import java.util.List;
import java.util.Map;
/**
* Created by fruwei on 2016/6/21.
... ... @@ -15,8 +14,8 @@ public interface IJavaApiStaticsMapper {
public void insertJavaApiStatics(String influxDBName, JSONObject statics);
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, Map<String, Integer> query);
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, JavaApiStatusReq query);
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<Map<String, Integer>> query);
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> query);
}
... ...
... ... @@ -5,6 +5,7 @@ import com.monitor.common.contants.InfluxDBContants;
import com.monitor.influxdb.InluxDBSingle;
import com.monitor.influxdb.mapper.IJavaApiStaticsMapper;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiStatusReq;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
... ... @@ -68,12 +69,12 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
}
@Override
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, Map<String, Integer> param) {
int api_id = param.get("api_id");
int mobj_id = param.get("mobj_id");
public JavaApiStaticsModel selectlatestJavaApiStatics(String influxDBName, JavaApiStatusReq param) {
int api_id = param.getServiceId();
int mobj_id = param.getMObjectId();
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 += " and api_id=" + api_id;
sql += " and mobj_id=" + mobj_id;
sql += " order by time desc limit 1";
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
... ... @@ -89,14 +90,14 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
try {
QueryResult.Series series = rel.getSeries().get(0);
Boolean status = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
Boolean is_exception = (Boolean) series.getValues().get(0).get(series.getColumns().indexOf("is_exception"));
if (status == true) {
javaApiStaticsModel.setStatus(1);
} else
if (is_exception == true) {
javaApiStaticsModel.setStatus(0);
} else
javaApiStaticsModel.setStatus(1);
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
return javaApiStaticsModel;
... ... @@ -104,15 +105,14 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper {
}
@Override
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<Map<String, Integer>> paramList) {
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
//TODO 后期改批量查询
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<>();
for (Map<String, Integer> param : paramList) {
for (JavaApiStatusReq param : paramList) {
JavaApiStaticsModel model = selectlatestJavaApiStatics(influxDBName, param);
javaApiStaticsModels.add(model);
}
... ...
package com.monitor.javaserver.status.impl;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.status.IJavaApiStatusService;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
... ... @@ -14,6 +17,10 @@ import java.util.Random;
*/
@Component
public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
@Autowired
JavaApiStaticsMapper javaApiStaticsMapper;
@Override
public JavaApiStatusRep getJavaApiStatus(JavaApiStatusReq req) {
JavaApiStatusRep rep = new JavaApiStatusRep();
... ... @@ -34,17 +41,29 @@ public class JavaAppiStatusServiceImpl implements IJavaApiStatusService {
public List<JavaApiStatusRep> getJavaApiStatusList(List<JavaApiStatusReq> reqList) {
List<JavaApiStatusRep> repList = new ArrayList<JavaApiStatusRep>();
//模拟
for (JavaApiStatusReq req : reqList) {
List<JavaApiStaticsModel> modelList = javaApiStaticsMapper.selectlatestJavaApiStaticsList(null, reqList);
for (JavaApiStaticsModel req : modelList) {
JavaApiStatusRep rep = new JavaApiStatusRep();
rep.setServiceId(req.getServiceId());
rep.setMObjectId(req.getMObjectId());
Random rd = new Random();
rep.setStatus((100 + rd.nextInt(100)) % 2);
rep.setStatus(req.getStatus());
repList.add(rep);
}
// //模拟
// for (JavaApiStatusReq req : reqList) {
// JavaApiStatusRep rep = new JavaApiStatusRep();
// rep.setServiceId(req.getServiceId());
// rep.setMObjectId(req.getMObjectId());
//
// Random rd = new Random();
// rep.setStatus((100 + rd.nextInt(100)) % 2);
// repList.add(rep);
// }
return repList;
}
... ...
... ... @@ -3,6 +3,8 @@ package com.monitor;
import com.monitor.influxdb.mapper.impl.JavaApiStaticsMapper;
import com.monitor.javaserver.common.JavaApiStatics;
import com.monitor.model.domain.JavaApiStaticsModel;
import com.monitor.model.request.JavaApiStatusReq;
import com.monitor.model.response.JavaApiStatusRep;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
... ... @@ -34,9 +36,10 @@ public class JavaApiInfluxDBTest {
@Test
public void testQuery() {
Map<String, Integer> param = new HashMap<>();
param.put("api_id", 21);
param.put("mobj_id", 43);
JavaApiStatusReq param = new JavaApiStatusReq();
param.setServiceId(21);
param.setServiceId(43);
JavaApiStaticsModel rel = javaApiStaticsMapper.selectlatestJavaApiStatics(null, param);
logger.info(rel.toString());
... ... @@ -47,14 +50,14 @@ public class JavaApiInfluxDBTest {
@Test
public void testBatchQuery() {
List<Map<String, Integer> > listParam=new ArrayList<>();
Map<String, Integer> param1 = new HashMap<>();
param1.put("api_id", 21);
param1.put("mobj_id", 43);
List<JavaApiStatusReq> listParam = new ArrayList<>();
JavaApiStatusReq param1 = new JavaApiStatusReq();
param1.setServiceId(21);
param1.setServiceId(43);
listParam.add(param1);
Map<String, Integer> param2 = new HashMap<>();
param2.put("api_id", 19);
param2.put("mobj_id", 134);
JavaApiStatusReq param2 = new JavaApiStatusReq();
param2.setServiceId(19);
param2.setServiceId(134);
listParam.add(param2);
... ...