in backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java [345:410]
public JVMMetricsListDataVO getFGCHappendCountAndCostTime(Connection connection)
throws BaseException {
String name = "FGC发生次数及总耗时";
String metricType = "垃圾回收";
String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
SessionPool sessionPool = getSessionPool(connection);
int port = connection.getPort();
// TODO bug 修复后删除
if (port == 6668) {
port = 8086;
}
String countSQL =
"select * from "
+
// "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_count\".\"action=end of
// major GC\".\"cause=Allocation Failure\", " +
"root._metric.\"127.0.0.1:"
+ port
+ "\".\"jvm.gc.pause_count\".\"action=end of major GC\".\"cause=Metadata GC Threshold\" "
+
// "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_count\".\"action=end of
// major GC\".\"cause=Ergonomics\" " +
"order by time desc limit 1";
String timeSQL =
"select * from "
+
// "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_total\".\"action=end of
// major GC\".\"cause=Allocation Failure\", " +
"root._metric.\"127.0.0.1:"
+ port
+ "\".\"jvm.gc.pause_total\".\"action=end of major GC\".\"cause=Metadata GC Threshold\" "
+
// "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_total\".\"action=end of
// major GC\".\"cause=Ergonomics\" " +
"order by time desc limit 1";
List<String> countValues = executeQueryOneLine(sessionPool, countSQL);
List<String> timeValues = executeQueryOneLine(sessionPool, timeSQL);
long lastestTimeStamp = Long.parseLong(countValues.get(0));
String latestScratchTime = simpleDateFormat.format(lastestTimeStamp);
Integer detailAvailable = 2;
// TODO: IOTDB BUG 等待修复
String s1 = countValues.get(1).equals("null") ? "0.0" : countValues.get(1);
// String s2 = countValues.get(2).equals("null") ? "0.0" : countValues.get(2);
// String s3 = countValues.get(3).equals("null") ? "0.0" : countValues.get(3);
s1 = s1.substring(0, s1.indexOf('.'));
// s2 = s2.substring(0, s2.indexOf('.'));
// s3 = s3.substring(0, s3.indexOf('.'));
// int count = Integer.parseInt(s1) + Integer.parseInt(s2) + Integer.parseInt(s3);
int count = Integer.parseInt(s1);
// TODO: IOTDB BUG 等待修复
double d1 = timeValues.get(1).equals("null") ? 0.0 : Double.parseDouble(timeValues.get(1));
// double d2 = timeValues.get(2).equals("null")? 0.0 : Double.parseDouble(timeValues.get(2));
// double d3 = timeValues.get(3).equals("null")? 0.0 : Double.parseDouble(timeValues.get(3));
// double time = d1 + d2 + d3;
double time = (d1) / 1000;
String latestResult = count + "次 " + time + "s";
JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO();
jvmMetricsListDataVO.setMetricType(metricType);
jvmMetricsListDataVO.setDetailAvailable(detailAvailable);
jvmMetricsListDataVO.setLatestResult(latestResult);
jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime);
jvmMetricsListDataVO.setName(name);
return jvmMetricsListDataVO;
}