public JVMMetricsListDataVO getYGCHappendCountAndCostTime()

in backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java [254:304]


  public JVMMetricsListDataVO getYGCHappendCountAndCostTime(Connection connection)
      throws BaseException {
    String name = "YGC发生次数及总耗时";
    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:"
            + port
            + "\".\"jvm.gc.pause_count\".\"action=end of minor GC\".\"cause=Allocation Failure\", "
            + "root._metric.\"127.0.0.1:"
            + port
            + "\".\"jvm.gc.pause_count\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\" "
            + "order by time desc limit 1";
    String timeSQL =
        "select * from "
            + "root._metric.\"127.0.0.1:"
            + port
            + "\".\"jvm.gc.pause_total\".\"action=end of minor GC\".\"cause=Allocation Failure\", "
            + "root._metric.\"127.0.0.1:"
            + port
            + "\".\"jvm.gc.pause_total\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\" "
            + "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;
    String s1 = countValues.get(1);
    String s2 = countValues.get(2);
    s1 = s1.substring(0, s1.indexOf('.'));
    s2 = s2.substring(0, s2.indexOf('.'));
    int count = Integer.parseInt(s1) + Integer.parseInt(s2);
    double time =
        (Double.parseDouble(timeValues.get(1)) + Double.parseDouble(timeValues.get(2))) / 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;
  }