|
@@ -40,29 +40,22 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -40,29 +40,22 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
40
|
public void insertJavaApiStatics(String influxDBName, JSONObject statics) {
|
40
|
public void insertJavaApiStatics(String influxDBName, JSONObject statics) {
|
41
|
|
41
|
|
42
|
|
42
|
|
43
|
- BatchPoints batchPoints = BatchPoints
|
|
|
44
|
- .database(InfluxDBContants.APP_ALARM).retentionPolicy("default")
|
|
|
45
|
- .build();
|
43
|
+// BatchPoints batchPoints = BatchPoints
|
|
|
44
|
+// .database(InfluxDBContants.APP_ALARM).retentionPolicy("default")
|
|
|
45
|
+// .build();
|
46
|
Point.Builder pointBuilder = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
|
46
|
Point.Builder pointBuilder = Point.measurement(InfluxDBContants.YOMO_TB_JAVAAPI)
|
47
|
- .tag("api_id", "api_id")
|
|
|
48
|
- .tag("mobj_id", "mobj_id")
|
|
|
49
|
- .tag("api_name", "api_name")
|
|
|
50
|
- .tag("api_url", "api_url")
|
|
|
51
|
- .tag("mobj_ip", "mobj_ip")
|
|
|
52
|
- .tag("is_exception", "is_exception")
|
|
|
53
|
- .addField("api_id", statics.getIntValue("api_id"))
|
|
|
54
|
- .addField("api_name", statics.getString("api_name"))
|
|
|
55
|
- .addField("api_type", statics.getIntValue("api_type"))
|
47
|
+ .tag("api_id", statics.getString("api_id"))
|
|
|
48
|
+ .tag("mobj_id", statics.getString("mobj_id"))
|
|
|
49
|
+ .tag("api_name", statics.getString("api_name"))
|
56
|
.addField("api_url", statics.getString("api_url"))
|
50
|
.addField("api_url", statics.getString("api_url"))
|
|
|
51
|
+ .tag("mobj_ip", statics.getString("mobj_ip"))
|
|
|
52
|
+ .tag("is_exception", statics.getString("is_exception"))
|
|
|
53
|
+ .addField("api_type", statics.getIntValue("api_type"))
|
57
|
.addField("mobj_name", statics.getString("mobj_name"))
|
54
|
.addField("mobj_name", statics.getString("mobj_name"))
|
58
|
- .addField("mobj_ip", statics.getString("mobj_ip"))
|
|
|
59
|
- .addField("mobj_id", statics.getIntValue("mobj_id"))
|
|
|
60
|
.addField("mobj_port", statics.getString("mobj_port"))
|
55
|
.addField("mobj_port", statics.getString("mobj_port"))
|
61
|
.addField("start_time", statics.getLongValue("start"))
|
56
|
.addField("start_time", statics.getLongValue("start"))
|
62
|
.addField("end_time", statics.getLongValue("end"))
|
57
|
.addField("end_time", statics.getLongValue("end"))
|
63
|
- .addField("is_exception", statics.getBooleanValue("is_exception"))
|
|
|
64
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS);
|
58
|
.time(System.currentTimeMillis() * 1000000 + random.nextInt(999999), TimeUnit.NANOSECONDS);
|
65
|
-
|
|
|
66
|
if (statics.getBooleanValue("is_exception") == true) {
|
59
|
if (statics.getBooleanValue("is_exception") == true) {
|
67
|
pointBuilder.addField("exception", statics.getString("exception"));
|
60
|
pointBuilder.addField("exception", statics.getString("exception"));
|
68
|
} else {
|
61
|
} else {
|
|
@@ -70,10 +63,10 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -70,10 +63,10 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
70
|
}
|
63
|
}
|
71
|
|
64
|
|
72
|
Point point = pointBuilder.build();
|
65
|
Point point = pointBuilder.build();
|
73
|
- batchPoints.point(point);
|
66
|
+// batchPoints.point(point);
|
74
|
|
67
|
|
75
|
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
|
68
|
inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB()
|
76
|
- .write(batchPoints);
|
69
|
+ .write(InfluxDBContants.APP_ALARM, "default", point);
|
77
|
|
70
|
|
78
|
|
71
|
|
79
|
}
|
72
|
}
|
|
@@ -87,9 +80,13 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -87,9 +80,13 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
87
|
sql += " and mobj_id=" + mobj_id;
|
80
|
sql += " and mobj_id=" + mobj_id;
|
88
|
sql += " order by time desc limit 1";
|
81
|
sql += " order by time desc limit 1";
|
89
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
82
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
90
|
-
|
|
|
91
|
- QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
92
|
-
|
83
|
+ QueryResult result = null;
|
|
|
84
|
+ try {
|
|
|
85
|
+ result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
86
|
+ } catch (Exception e) {
|
|
|
87
|
+ log.warn("influxdb query error ", e);
|
|
|
88
|
+ return null;
|
|
|
89
|
+ }
|
93
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
90
|
JavaApiStaticsModel javaApiStaticsModel = new JavaApiStaticsModel();
|
94
|
javaApiStaticsModel.setServiceId(api_id);
|
91
|
javaApiStaticsModel.setServiceId(api_id);
|
95
|
javaApiStaticsModel.setMObjectId(mobj_id);
|
92
|
javaApiStaticsModel.setMObjectId(mobj_id);
|
|
@@ -137,6 +134,28 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -137,6 +134,28 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
137
|
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
|
134
|
public List<JavaApiStaticsModel> selectlatestJavaApiStaticsList(String influxDBName, List<JavaApiStatusReq> paramList) {
|
138
|
|
135
|
|
139
|
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
|
136
|
List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
|
|
|
137
|
+
|
|
|
138
|
+
|
|
|
139
|
+ List<JavaApiStatusReq> splitReqList = new ArrayList<JavaApiStatusReq>();
|
|
|
140
|
+ for (JavaApiStatusReq param : paramList) {
|
|
|
141
|
+ splitReqList.add(param);
|
|
|
142
|
+ if (splitReqList.size() >= 20) {
|
|
|
143
|
+ javaApiStaticsModels.addAll(selectlatestJavaApiStaticsList_batch_split(influxDBName, splitReqList));
|
|
|
144
|
+ splitReqList.clear();
|
|
|
145
|
+ }
|
|
|
146
|
+ }
|
|
|
147
|
+ if (splitReqList.size() > 0) {
|
|
|
148
|
+ javaApiStaticsModels.addAll(selectlatestJavaApiStaticsList_batch_split(influxDBName, splitReqList));
|
|
|
149
|
+ }
|
|
|
150
|
+
|
|
|
151
|
+ return javaApiStaticsModels;
|
|
|
152
|
+
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+
|
|
|
156
|
+ private List<JavaApiStaticsModel> selectlatestJavaApiStaticsList_batch_split(String influxDBName, List<JavaApiStatusReq> paramList) {
|
|
|
157
|
+
|
|
|
158
|
+ List<JavaApiStaticsModel> javaApiStaticsModels = new ArrayList<JavaApiStaticsModel>();
|
140
|
StringBuilder sb = new StringBuilder();
|
159
|
StringBuilder sb = new StringBuilder();
|
141
|
for (JavaApiStatusReq param : paramList) {
|
160
|
for (JavaApiStatusReq param : paramList) {
|
142
|
int api_id = param.getServiceId();
|
161
|
int api_id = param.getServiceId();
|
|
@@ -146,9 +165,15 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -146,9 +165,15 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
146
|
sb.append(" and mobj_id=" + mobj_id);
|
165
|
sb.append(" and mobj_id=" + mobj_id);
|
147
|
sb.append(" order by time desc limit 1;");
|
166
|
sb.append(" order by time desc limit 1;");
|
148
|
}
|
167
|
}
|
|
|
168
|
+ log.info(sb.toString());
|
149
|
Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM);
|
169
|
Query query = new Query(sb.toString(), InfluxDBContants.APP_ALARM);
|
150
|
-
|
|
|
151
|
- QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
170
|
+ QueryResult result = null;
|
|
|
171
|
+ try {
|
|
|
172
|
+ result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
173
|
+ } catch (Exception e) {
|
|
|
174
|
+ log.warn("influx db select error ,", e);
|
|
|
175
|
+ return javaApiStaticsModels;
|
|
|
176
|
+ }
|
152
|
|
177
|
|
153
|
for (QueryResult.Result queryResult : result.getResults()) {
|
178
|
for (QueryResult.Result queryResult : result.getResults()) {
|
154
|
if (queryResult.getSeries() == null)
|
179
|
if (queryResult.getSeries() == null)
|
|
@@ -187,11 +212,10 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -187,11 +212,10 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
187
|
log.warn("batch select latest java api info failed ", e);
|
212
|
log.warn("batch select latest java api info failed ", e);
|
188
|
}
|
213
|
}
|
189
|
}
|
214
|
}
|
190
|
-
|
|
|
191
|
-
|
|
|
192
|
return javaApiStaticsModels;
|
215
|
return javaApiStaticsModels;
|
193
|
}
|
216
|
}
|
194
|
|
217
|
|
|
|
218
|
+
|
195
|
@Override
|
219
|
@Override
|
196
|
public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, JavaApiHisReq req) {
|
220
|
public List<JavaApiStaticsModel> selectJavaApiStaticHis(String influxDBName, JavaApiHisReq req) {
|
197
|
int api_id = req.getApiId();
|
221
|
int api_id = req.getApiId();
|
|
@@ -225,9 +249,14 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -225,9 +249,14 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
225
|
log.info("sql:{}", sql);
|
249
|
log.info("sql:{}", sql);
|
226
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
250
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
227
|
|
251
|
|
228
|
- QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
229
|
-
|
252
|
+ QueryResult result = null;
|
230
|
List<JavaApiStaticsModel> list = new ArrayList<JavaApiStaticsModel>();
|
253
|
List<JavaApiStaticsModel> list = new ArrayList<JavaApiStaticsModel>();
|
|
|
254
|
+ try {
|
|
|
255
|
+ result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
256
|
+ } catch (Exception e) {
|
|
|
257
|
+ log.warn("influxdb query error ", e);
|
|
|
258
|
+ return list;
|
|
|
259
|
+ }
|
231
|
|
260
|
|
232
|
QueryResult.Result rel = result.getResults().get(0);
|
261
|
QueryResult.Result rel = result.getResults().get(0);
|
233
|
|
262
|
|
|
@@ -314,9 +343,13 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
|
@@ -314,9 +343,13 @@ public class JavaApiStaticsMapper implements IJavaApiStaticsMapper { |
314
|
|
343
|
|
315
|
|
344
|
|
316
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
345
|
Query query = new Query(sql, InfluxDBContants.APP_ALARM);
|
317
|
-
|
|
|
318
|
- QueryResult result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
319
|
-
|
346
|
+ QueryResult result = null;
|
|
|
347
|
+ try {
|
|
|
348
|
+ result = inluxDBSingle.getInfluxDBByName(InfluxDBContants.ALARM).getInfluxDB().query(query);
|
|
|
349
|
+ } catch (Exception e) {
|
|
|
350
|
+ log.warn("influxdb query error ", e);
|
|
|
351
|
+ return 0;
|
|
|
352
|
+ }
|
320
|
return QueryResultUtil.getCount(result);
|
353
|
return QueryResultUtil.getCount(result);
|
321
|
}
|
354
|
}
|
322
|
|
355
|
|