public JVMMetricsListDataVO getCurrentThreadsCount()

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


  public JVMMetricsListDataVO getCurrentThreadsCount(Connection connection) throws BaseException {
    String name = "JVM当前线程数";
    String metricType = "线程";
    String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    Integer detailAvailable = 1;
    int port = connection.getPort();
    // TODO bug 修复后删除
    if (port == 6668) {
      port = 8086;
    }
    String sql =
        "select * from "
            + "root._metric.\"127.0.0.1:"
            + port
            + "\".\"jvm.threads.daemon\", "
            + "root._metric.\"127.0.0.1:"
            + port
            + "\".\"jvm.threads.live\" "
            + "order by time desc limit 1";
    SessionPool sessionPool = getSessionPool(connection);
    List<String> values = executeQueryOneLine(sessionPool, sql);
    long lastestTimeStamp = Long.parseLong(values.get(0));
    String s1 = values.get(2);
    String s2 = values.get(1);
    s1 = s1.substring(0, s1.indexOf('.'));
    s2 = s2.substring(0, s2.indexOf('.'));
    int totalThreadCount = Integer.parseInt(s1);
    int demoThreadCount = Integer.parseInt(s2);
    String latestScratchTime = simpleDateFormat.format(lastestTimeStamp);
    String latestResult =
        "前台:"
            + (totalThreadCount - demoThreadCount)
            + "个,后台:"
            + demoThreadCount
            + "个,线程总数:"
            + totalThreadCount
            + "个";
    JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO();
    jvmMetricsListDataVO.setMetricType(metricType);
    jvmMetricsListDataVO.setDetailAvailable(detailAvailable);
    jvmMetricsListDataVO.setLatestResult(latestResult);
    jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime);
    jvmMetricsListDataVO.setName(name);
    return jvmMetricsListDataVO;
  }