...
|
...
|
@@ -7,6 +7,8 @@ import com.monitor.middleware.nginx.model.ApiStaModel; |
|
|
import com.monitor.middleware.rabbitmq.component.InfluxComp;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.*;
|
...
|
...
|
@@ -17,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap; |
|
|
* Created by yoho on 2016/6/28.
|
|
|
*/
|
|
|
public class BaseLogJob implements Callable {
|
|
|
public static final Logger DEBUG = LoggerFactory.getLogger(BaseLogJob.class);
|
|
|
|
|
|
private static ConcurrentHashMap<String, Integer> KINDEXMAPS = new ConcurrentHashMap<>();
|
|
|
|
...
|
...
|
@@ -61,7 +64,7 @@ public class BaseLogJob implements Callable { |
|
|
|
|
|
private List<ApiStaModel> sortMap(HashMap<String, ApiStaModel> map) {
|
|
|
|
|
|
List<ApiStaModel> sortedList = new ArrayList<>();
|
|
|
List<ApiStaModel> sortedList = new ArrayList<>();
|
|
|
|
|
|
List<Map.Entry<String, ApiStaModel>> entryList = new ArrayList<>(map.entrySet());
|
|
|
|
...
|
...
|
@@ -83,15 +86,14 @@ public class BaseLogJob implements Callable { |
|
|
private void queryData() {
|
|
|
String sql = "select * from " + measureName + " where time > now() - " + InterVar.SCANINTERVAL;
|
|
|
|
|
|
DEBUG.debug("Start to execute query command : {}", sql);
|
|
|
|
|
|
QueryResult result = influxComp.doQuery(sql, InterVar.DBNAME);
|
|
|
|
|
|
//parse result to api series model
|
|
|
buildApiModel(apiSeriesModelList, result.getResults().get(0).getSeries());
|
|
|
}
|
|
|
|
|
|
|
|
|
public void calNignxView(List<ApiSeriesModel> apiSeriesModelList) {
|
|
|
|
|
|
DEBUG.info("Success to query {} items from {}", apiSeriesModelList.size(), measureName);
|
|
|
}
|
|
|
|
|
|
//计算api内部占比 logip分类 errorcode分类
|
...
|
...
|
@@ -110,15 +112,15 @@ public class BaseLogJob implements Callable { |
|
|
}
|
|
|
|
|
|
|
|
|
public HashMap<String, String> calMapPercent(int total, HashMap<String, Integer> countMap) {
|
|
|
private HashMap<String, String> calMapPercent(int total, HashMap<String, Integer> countMap) {
|
|
|
|
|
|
HashMap<String, String> percentMap = new HashMap<>();
|
|
|
|
|
|
for (Map.Entry<String, Integer> oneCount : countMap.entrySet()) {
|
|
|
|
|
|
double percent = 100*oneCount.getValue() / (double) total;
|
|
|
double percent = 100 * oneCount.getValue() / (double) total;
|
|
|
|
|
|
percentMap.put(oneCount.getKey(), format.format(percent)+"%");
|
|
|
percentMap.put(oneCount.getKey(), format.format(percent) + "%");
|
|
|
}
|
|
|
|
|
|
return percentMap;
|
...
|
...
|
@@ -133,9 +135,9 @@ public class BaseLogJob implements Callable { |
|
|
|
|
|
oneEntry.getValue().setCount(count);
|
|
|
|
|
|
double percent = 100*count / (double) total;
|
|
|
double percent = 100 * count / (double) total;
|
|
|
|
|
|
oneEntry.getValue().setTotalPercent(format.format(percent)+"%");
|
|
|
oneEntry.getValue().setTotalPercent(format.format(percent) + "%");
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -229,97 +231,7 @@ public class BaseLogJob implements Callable { |
|
|
}
|
|
|
|
|
|
|
|
|
/* public static void main(String[] args) {
|
|
|
//String sql = "select * from cluster_info where time > now() - 2d";
|
|
|
|
|
|
InfluxComp influxComp = new InfluxComp("http://172.16.6.104:8086", "root", "root");
|
|
|
|
|
|
influxComp.init();
|
|
|
|
|
|
Random random=new Random();
|
|
|
Point point=Point.measurement(InterVar.SERACCESSMEASURE)
|
|
|
.addField("http_host","api.yoho.cn")
|
|
|
.addField("log_file","api.yoho.cn_access.log")
|
|
|
.addField("log_ip","172.16.6.104")
|
|
|
.addField("request_method","GET")
|
|
|
.addField("request_status","499")
|
|
|
.addField("request_url","/haha HTTP/1.1")
|
|
|
.addField("upstream","172.16.6.105:8800")
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
|
|
|
.build();
|
|
|
|
|
|
|
|
|
String request_url="/?app_version=4.0.0&client_secret=b7eaa613a3ccfda51b697964a276bcba&client_type=android&gender=&limit=60&method=app.SpaceOrders.push&os_version=android5.0%3ASM-G9006V&page=1&screen_size=1080x1920&type=1&v=7&yh_channel=1 HTTP/1.1";
|
|
|
|
|
|
|
|
|
Point point1=Point.measurement(InterVar.SERACCESSMEASURE)
|
|
|
.addField("http_host","api.yoho.cn")
|
|
|
.addField("log_file","api.yoho.cn_access.log")
|
|
|
.addField("log_ip","172.16.6.104")
|
|
|
.addField("request_method","GET")
|
|
|
.addField("request_status","500")
|
|
|
.addField("request_url",request_url)
|
|
|
.addField("upstream","172.16.6.105:8800")
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
|
|
|
.build();
|
|
|
|
|
|
BatchPoints points=BatchPoints.database(InterVar.DBNAME).retentionPolicy("default").build();
|
|
|
|
|
|
points.point(point);
|
|
|
points.point(point1);
|
|
|
|
|
|
influxComp.getInfluxDBClient().write(points);
|
|
|
*//*Point ponit=Point.measurement(InterVar.ERRORMEASURE)
|
|
|
.addField("err_msg","Lua error 45646576456")
|
|
|
.addField("err_severity","error")
|
|
|
.addField("log_ip","172.16.6.104")
|
|
|
.addField("log_time","2016/06/29 20:40:25")
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
|
|
|
.build();
|
|
|
|
|
|
Point ponit1=Point.measurement(InterVar.ERRORMEASURE)
|
|
|
.addField("err_msg","Lua error 1231231")
|
|
|
.addField("err_severity","error")
|
|
|
.addField("log_ip","172.16.6.104")
|
|
|
.addField("log_time","2016/06/29 20:40:25")
|
|
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS)
|
|
|
.build();
|
|
|
|
|
|
BatchPoints batchPoints=BatchPoints.database(InterVar.DBNAME).retentionPolicy("default").build();
|
|
|
|
|
|
batchPoints.point(ponit);
|
|
|
|
|
|
batchPoints.point(ponit1);
|
|
|
|
|
|
influxComp.getInfluxDBClient().write(batchPoints);
|
|
|
|
|
|
|
|
|
*//**//**//**//* influxComp.getInfluxDBClient().createDatabase(InterVar.DBNAME);
|
|
|
|
|
|
*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//*
|
|
|
|
|
|
QueryResult result = influxComp.doQuery(sql, "rabbitmq_info");
|
|
|
|
|
|
List<String> columns = result.getResults().get(0).getSeries().get(0).getColumns();
|
|
|
|
|
|
System.out.println(columns);
|
|
|
|
|
|
List<Object> values = result.getResults().get(0).getSeries().get(0).getValues().get(0);
|
|
|
|
|
|
System.out.println(values);
|
|
|
|
|
|
String v = result.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString();
|
|
|
|
|
|
System.out.println(v);*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//*
|
|
|
|
|
|
|
|
|
System.out.println(new ApiJob().queryRequest("/?app_version=4.6.0.1606220001&client_secret=d039fbc04704d0679eb59c8c82593ddb&client_type=iphone&is_read=N&method=app.inbox.getTotal&os_version=9.3.2&screen_size=375x667&uid=3930397&v=7 HTTP/1.1"));
|
|
|
|
|
|
System.out.println(new ApiJob().queryRequest("/ HTTP/1.1"));*//*
|
|
|
}*/
|
|
|
|
|
|
|
|
|
protected String queryRequest(String request_url) {
|
|
|
private String queryRequest(String request_url) {
|
|
|
if (request_url.contains("&method=")) {
|
|
|
|
|
|
String[] afterUrl = request_url.split("&method=", 2);
|
...
|
...
|
@@ -348,6 +260,18 @@ public class BaseLogJob implements Callable { |
|
|
}
|
|
|
}
|
|
|
|
|
|
protected String buildAlarmMsg() {
|
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
builder.append("{");
|
|
|
builder.append("云:").append(type).append(";");
|
|
|
builder.append("总计:").append(this.apiSeriesModelList.size()).append(";");
|
|
|
builder.append("top接口:");
|
|
|
builder.append(this.resultList.get(0).getApiKey()).append(" : ").append(this.resultList.get(0).getApiSeriesModelList().size()).append(";");
|
|
|
builder.append("}");
|
|
|
return builder.toString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object call() throws Exception {
|
|
|
doTask();
|
...
|
...
|
|