From ff960d2e6461a99d1d18c2c735c71bb0941cb01b Mon Sep 17 00:00:00 2001 From: loveher147 Date: Thu, 26 May 2022 14:48:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E5=B1=95=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 该版本适配低于0.13版本的iotdb并提供数据库管理功能,但不提供监控管理(低于0.13版本iotdb不支持监控); - 仍然存在部分接口返回后端假数据,等待清华提供接口后替换为真实数据。 --- backend/pom.xml | 4 +- .../admin/common/exception/ErrorCode.java | 4 + .../admin/controller/FileController.java | 11 + .../admin/controller/IotDBController.java | 15 +- .../model/dto/AuthorityPrivilegeDTO.java | 1 + .../iotdb/admin/model/vo/DataCountVO.java | 5 +- .../iotdb/admin/service/IotDBService.java | 20 +- .../admin/service/impl/IotDBServiceImpl.java | 1841 ++++++++++++++++- backend/src/main/resources/sqlite/iotdb.db | Bin 36864 -> 53248 bytes 9 files changed, 1846 insertions(+), 55 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 45d3bea6..e3fb378e 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -145,7 +145,7 @@ org.apache.iotdb iotdb-session - 0.12.1 + 0.12.5 logback-classic @@ -157,7 +157,7 @@ org.apache.iotdb iotdb-jdbc - 0.12.1 + 0.12.5 logback-classic diff --git a/backend/src/main/java/org/apache/iotdb/admin/common/exception/ErrorCode.java b/backend/src/main/java/org/apache/iotdb/admin/common/exception/ErrorCode.java index 20843385..7e045939 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/common/exception/ErrorCode.java +++ b/backend/src/main/java/org/apache/iotdb/admin/common/exception/ErrorCode.java @@ -158,6 +158,10 @@ public class ErrorCode { public static final String SET_GROUP_FAIL = "IOTDB-0022"; public static final String SET_GROUP_FAIL_MSG = "Failed to create storage group"; + public static final String SET_GROUP_FAIL_EXISTS = "IOTDB-0095"; + public static final String SET_GROUP_FAIL__EXISTS_MSG = + "Failed to create storage group, the storage group already exists"; + public static final String DELETE_GROUP_FAIL = "IOTDB-0023"; public static final String DELETE_GROUP_FAIL_MSG = "Failed to delete storage group"; diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/FileController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/FileController.java index ea0106be..33aea37a 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/controller/FileController.java +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/FileController.java @@ -115,6 +115,17 @@ public ResponseEntity downloadTemplateFile() throws BaseException { return getResponseEntity(resource); } + @ApiOperation("Download the query log file") + @GetMapping("/downloadQueryLogFile") + public ResponseEntity downloadQueryLogFile( + @RequestParam String SQLStatement, @RequestParam Long timeStamp) throws BaseException { + Resource resource = new ClassPathResource("file/[Fake]QueryLog.txt"); + if (!resource.exists()) { + throw new BaseException(ErrorCode.FILE_NOT_FOUND, ErrorCode.FILE_NOT_FOUND_MSG); + } + return getResponseEntity(resource); + } + private ResponseEntity getResponseEntity(Resource resource) { String contentType = "application/octet-stream"; diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java index 612816e4..5b4d0d00 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java @@ -85,10 +85,13 @@ public BaseVO getDataCount( @GetMapping("/dataModel") @ApiOperation("Get IoTDB data model") public BaseVO getDataModel( - @PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException { + @PathVariable("serverId") Integer serverId, + @RequestParam(value = "path", required = false, defaultValue = "root") String path, + HttpServletRequest request) + throws BaseException { check(request, serverId); Connection connection = connectionService.getById(serverId); - DataModelVO dataModelVO = iotDBService.getDataModel(connection); + DataModelVO dataModelVO = iotDBService.getDataModel(connection, path); return BaseVO.success("Get IoTDB data model successfully", dataModelVO); } @@ -164,7 +167,6 @@ public BaseVO saveStorageGroup( checkTtl(ttl, ttlUnit); Integer groupId = groupDTO.getGroupId(); groupDTO.setGroupName(groupName); - List groupNames = iotDBService.getAllStorageGroups(connection); if (groupId == null) { if (!groupNames.contains(groupDTO.getGroupName())) { @@ -1121,9 +1123,7 @@ private void check(HttpServletRequest request, Integer serverId) throws BaseExce private void checkParameter(String groupName) throws BaseException { String checkName = StringUtils.removeStart(groupName, "root").toLowerCase(); - if (!groupName.matches("^root\\.[^ ]+$") - || checkName.contains(".root.") - || checkName.matches("^[^ ]*\\.root$")) { + if (groupName.contains(".root.") || groupName.contains(".root")) { throw new BaseException(ErrorCode.NO_SUP_CONTAIN_ROOT, ErrorCode.NO_SUP_CONTAIN_ROOT_MSG); } if (checkName.contains(".as.") @@ -1229,6 +1229,9 @@ private String getTTL(Long time) { } private void checkTtl(Long ttl, String unit) throws BaseException { + if (ttl == null || unit == null) { + return; + } if (Long.MAX_VALUE / switchTime(unit) < ttl) { throw new BaseException(ErrorCode.TTL_OVER, ErrorCode.TTL_OVER_MSG); } diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/AuthorityPrivilegeDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/AuthorityPrivilegeDTO.java index 4a7ea78a..ed3b8e10 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/dto/AuthorityPrivilegeDTO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/AuthorityPrivilegeDTO.java @@ -26,6 +26,7 @@ @Data public class AuthorityPrivilegeDTO implements Serializable { + private List privileges; private List cancelPrivileges; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataCountVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataCountVO.java index cdef28c5..fc2c2e73 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataCountVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataCountVO.java @@ -25,8 +25,9 @@ @Data public class DataCountVO implements Serializable { - private Integer groupCount; + private Integer storageGroupCount; private Integer deviceCount; - private Integer measurementCount; + private Integer monitorCount; private Integer dataCount; + private String version; } diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java index 70cd585e..0b050d73 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java @@ -30,7 +30,7 @@ public interface IotDBService { DataCountVO getDataCount(Connection connection) throws BaseException; - DataModelVO getDataModel(Connection connection) throws BaseException; + DataModelVO getDataModel(Connection connection, String path) throws BaseException; List getAllStorageGroups(Connection connection) throws BaseException; @@ -162,4 +162,22 @@ List queryAll(Connection connection, List sqls, Long timest void updatePwd(Connection connection, IotDBUser iotDBUser) throws BaseException; void stopQuery(Integer serverId, Long timestamp) throws BaseException; + + QueryInfoDTO getQueryInfoListByQueryClassificationId( + Connection connection, + Integer queryClassificationId, + Integer pageSize, + Integer pageNum, + String filterString, + Long startTime, + Long endTime, + Integer executionResult) + throws BaseException; + + MetricsDataForDiagramVO getMetricDataByMetricId(Connection connection, Integer metricId) + throws BaseException; + + List getTopQueryMetricsData(); + + List getSlowQueryMetricsData(); } diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java index 803c4f59..e904462f 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java @@ -23,6 +23,7 @@ import org.apache.iotdb.admin.common.exception.ErrorCode; import org.apache.iotdb.admin.model.dto.*; import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.metricsDo.QueryDataDo; import org.apache.iotdb.admin.model.vo.*; import org.apache.iotdb.admin.service.IotDBService; import org.apache.iotdb.rpc.IoTDBConnectionException; @@ -38,9 +39,11 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.lang.reflect.Field; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date; @@ -96,22 +99,43 @@ public DataCountVO getDataCount(Connection connection) throws BaseException { SessionPool sessionPool = null; try { sessionPool = getSessionPool(connection); + String iotdbVersion = executeQueryOneValue(sessionPool, "show version"); + logger.info("执行成功,获得iotdb版本号:" + iotdbVersion); + int versionFlag = 0; + if (iotdbVersion.contains("0.12.")) { + versionFlag = 12; + } else if (iotdbVersion.contains("0.13.") || iotdbVersion.contains("0.14.")) { + versionFlag = 13; + } String groupCountStr = executeQueryOneValue(sessionPool, "count storage group"); int groupCount = Integer.parseInt(groupCountStr); String deviceCountStr = executeQueryOneValue(sessionPool, "count devices"); int deviceCount = Integer.parseInt(deviceCountStr); String measurementCountStr = executeQueryOneValue(sessionPool, "count timeseries"); int measurementCount = Integer.parseInt(measurementCountStr); - List dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root"); + List dataCountList = new ArrayList<>(); + if (versionFlag == 13) { + dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root.**"); + } else if (versionFlag == 12) { + try { + dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root.*"); + // dataCountList = executeQueryOneLine(sessionPool, "select count(*) from + // root.*"); + } catch (BaseException e) { + logger.error("发生错误!!!"); + e.printStackTrace(); + } + } int dataCount = 0; for (String dataCountStr : dataCountList) { dataCount += Integer.parseInt(dataCountStr); } DataCountVO dataCountVO = new DataCountVO(); - dataCountVO.setGroupCount(groupCount); + dataCountVO.setStorageGroupCount(groupCount); dataCountVO.setDeviceCount(deviceCount); - dataCountVO.setMeasurementCount(measurementCount); + dataCountVO.setMonitorCount(measurementCount); dataCountVO.setDataCount(dataCount); + dataCountVO.setVersion(iotdbVersion); return dataCountVO; } catch (NumberFormatException e) { throw new BaseException(ErrorCode.GET_DATA_COUNT_FAIL, ErrorCode.GET_DATA_COUNT_FAIL_MSG); @@ -121,20 +145,39 @@ public DataCountVO getDataCount(Connection connection) throws BaseException { } @Override - public DataModelVO getDataModel(Connection connection) throws BaseException { + public DataModelVO getDataModel(Connection connection, String path) throws BaseException { SessionPool sessionPool = null; try { sessionPool = getSessionPool(connection); - DataModelVO root = new DataModelVO("root"); - assembleDataModel(root, "root", sessionPool); - root.setGroupCount(getGroupCount(sessionPool)); - root.setPath("root"); + DataModelVO root = new DataModelVO(path); + setNodeInfo(root, sessionPool, path); + List childrenDataModel = getChildrenDataModel(root, path, sessionPool); + root.setChildren(childrenDataModel); + root.setGroupCount(path.equals("root") ? getGroupCount(sessionPool) : null); + root.setPath(path); return root; } finally { closeSessionPool(sessionPool); } } + private List getChildrenDataModel( + DataModelVO root, String path, SessionPool sessionPool) throws BaseException { + Set childrenNode = getChildrenNode(path, sessionPool); + if (childrenNode == null) { + return null; + } + List childrenlist = new ArrayList<>(); + + // TODO: 大量IO + for (String child : childrenNode) { + DataModelVO childNode = new DataModelVO(child); + setNodeInfo(childNode, sessionPool, path + "." + child); + childrenlist.add(childNode); + } + return childrenlist; + } + private void assembleDataModel(DataModelVO node, String prefixPath, SessionPool sessionPool) throws BaseException { Set childrenNode = getChildrenNode(prefixPath, sessionPool); @@ -152,22 +195,51 @@ private void assembleDataModel(DataModelVO node, String prefixPath, SessionPool private Set getChildrenNode(String prefixPath, SessionPool sessionPool) throws BaseException { String sql = "show storage group " + prefixPath; + sql = sql.replace(',', '.'); List children = executeQueryOneColumn(sessionPool, sql); - if (children.size() == 0 || (children.size() == 1 && children.get(0).equals(prefixPath))) { + String dealedPrefixPath = prefixPath.replace(',', '.'); + if (children.size() == 0 + || (children.size() == 1 && children.get(0).equals(dealedPrefixPath))) { sql = "show timeseries " + prefixPath; + sql = sql.replace(',', '.'); children = executeQueryOneColumn(sessionPool, sql); - if (children.size() == 0 || (children.size() == 1 && children.get(0).equals(prefixPath))) { + if (children.size() == 0 + || (children.size() == 1 && children.get(0).equals(dealedPrefixPath))) { return null; } } Set childrenNode = new HashSet<>(); for (String child : children) { + child = dealChildNode(child); child = StringUtils.removeStart(child, prefixPath + ".").split("\\.")[0]; childrenNode.add(child); } return childrenNode; } + private String dealChildNode(String child) { + int left = 0, right = 0; + int length = child.length(); + while (right < length) { + char tempChar = child.charAt(right); + if (tempChar != '"' && left == right) { + left++; + right++; + } else if ((tempChar == '"' && left == right) || (tempChar != '"' && left != right)) { + right++; + } else if (tempChar == '"' && left != right) { + String preSubStr = child.substring(0, left); + String midSubStr = child.substring(left, right + 1); + String tailSubStr = child.substring(right + 1, length); + String newMidSubStr = midSubStr.replace('.', ','); + child = preSubStr + newMidSubStr + tailSubStr; + right++; + left = right; + } + } + return child; + } + private Integer getGroupCount(SessionPool sessionPool) throws BaseException { String sql = "count storage group"; String value = executeQueryOneValue(sessionPool, sql); @@ -176,7 +248,19 @@ private Integer getGroupCount(SessionPool sessionPool) throws BaseException { } private Integer getDeviceCount(SessionPool sessionPool, String groupName) throws BaseException { - String sql = "count devices " + groupName; + String iotdbVersion = executeQueryOneValue(sessionPool, "show version"); + int versionFlag = 0; + if (iotdbVersion.contains("0.12.")) { + versionFlag = 12; + } else if (iotdbVersion.contains("0.13.") || iotdbVersion.contains("0.14.")) { + versionFlag = 13; + } + String sql = null; + if (versionFlag == 13) { + sql = "count devices " + groupName + ".**"; + } else if (versionFlag == 12) { + sql = "count devices " + groupName; + } String value = executeQueryOneValue(sessionPool, sql); Integer count = Integer.valueOf(value); return count; @@ -184,7 +268,19 @@ private Integer getDeviceCount(SessionPool sessionPool, String groupName) throws private Integer getMeasurementsCount(SessionPool sessionPool, String deviceName) throws BaseException { - String sql = "count timeseries " + deviceName; + String iotdbVersion = executeQueryOneValue(sessionPool, "show version"); + int versionFlag = 0; + if (iotdbVersion.contains("0.12.")) { + versionFlag = 12; + } else if (iotdbVersion.contains("0.13.") || iotdbVersion.contains("0.14.")) { + versionFlag = 13; + } + String sql = null; + if (versionFlag == 13) { + sql = "count timeseries " + deviceName + ".**"; + } else if (versionFlag == 12) { + sql = "count timeseries " + deviceName; + } String value = executeQueryOneValue(sessionPool, sql); Integer count = Integer.valueOf(value); return count; @@ -231,6 +327,7 @@ private boolean isMeasurement(SessionPool sessionPool, String path) throws BaseE private void setNodeInfo(DataModelVO dataModelVO, SessionPool sessionPool, String path) throws BaseException { + path = path.replace(',', '.'); dataModelVO.setPath(path); if (isGroup(sessionPool, path)) { dataModelVO.setDeviceCount(getDeviceCount(sessionPool, path)); @@ -258,14 +355,24 @@ private String getLastValue(SessionPool sessionPool, String timeseries) throws B + timeseries.substring(index + 1) + ") from " + timeseries.substring(0, index); - String value = executeQueryOneValue(sessionPool, sql); + String value = "0"; + try { + value = executeQueryOneValue(sessionPool, sql); + } catch (BaseException e) { + e.printStackTrace(); + } return value; } private Integer getOneDataCount(SessionPool sessionPool, String timeseries) throws BaseException { int index = timeseries.lastIndexOf("."); String sql = "select count(*) from " + timeseries.substring(0, index); - String countStr = executeQueryOneLine(sessionPool, sql, "count(" + timeseries + ")"); + String countStr = "0"; + try { + countStr = executeQueryOneLine(sessionPool, sql, "count(" + timeseries + ")"); + } catch (BaseException e) { + e.printStackTrace(); + } return Integer.parseInt(countStr); } @@ -349,7 +456,14 @@ private Set getChildrenNode(String prefixPath, String type, SessionPool public void saveStorageGroup(Connection connection, String groupName) throws BaseException { SessionPool sessionPool = getSessionPool(connection); try { - sessionPool.setStorageGroup(groupName); + String iotdbVersion = executeQueryOneValue(sessionPool, "show version"); + int versionFlag = 0; + if (iotdbVersion.contains("0.12.")) { + sessionPool.executeNonQueryStatement("set storage group " + groupName); + } else if (iotdbVersion.contains("0.13.") || iotdbVersion.contains("0.14.")) { + sessionPool.executeNonQueryStatement("create storage group " + groupName); + } + // sessionPool.setStorageGroup(groupName); } catch (StatementExecutionException e) { if (e.getStatusCode() == 602) { throw new BaseException(ErrorCode.NO_PRI_SET_GROUP, ErrorCode.NO_PRI_SET_GROUP_MSG); @@ -362,7 +476,8 @@ public void saveStorageGroup(Connection connection, String groupName) throws Bas logger.error(e.getMessage()); } catch (IoTDBConnectionException e) { logger.error(e.getMessage()); - throw new BaseException(ErrorCode.SET_GROUP_FAIL, ErrorCode.SET_GROUP_FAIL_MSG); + throw new BaseException( + ErrorCode.SET_GROUP_FAIL_EXISTS, ErrorCode.SET_GROUP_FAIL__EXISTS_MSG); } finally { closeSessionPool(sessionPool); } @@ -907,15 +1022,29 @@ private void upsertAuthorityPrivilege( String name, String privilegesStr) throws BaseException { - String sql = - operationType - + " " - + userOrRole - + " " - + name - + " privileges '" - + privilegesStr - + "' on root"; + String show_version = executeQueryOneValue(sessionPool, "show version"); + String sql = null; + if (show_version.contains("0.13") || show_version.contains("0.14")) { + sql = + operationType + + " " + + userOrRole + + " " + + name + + " privileges " + + privilegesStr + + " on root"; + } else if (show_version.contains("0.12")) { + sql = + operationType + + " " + + userOrRole + + " " + + name + + " privileges '" + + privilegesStr + + "' on root"; + } try { sessionPool.executeNonQueryStatement(sql); } catch (StatementExecutionException e) { @@ -1444,7 +1573,9 @@ private void checkValue(String value) throws BaseException { private void upsertMeasurementAlias(SessionPool sessionPool, String timeseries, String alias) throws BaseException { - if (alias == null || "null".equals(alias) || StringUtils.isBlank(alias)) { + // 需要改为" "值。 + if (alias == null || "null".equals(alias)) { + // if (alias == null || "null".equals(alias) || StringUtils.isBlank(alias)) { return; } if (alias.matches("^as$") || alias.matches("^\\d+$") || alias.matches("^like$")) { @@ -2305,6 +2436,1610 @@ public void stopQuery(Integer serverId, Long timestamp) throws BaseException { throw new BaseException(ErrorCode.NO_QUERY, ErrorCode.NO_QUERY_MSG); } + @Override + public QueryInfoDTO getQueryInfoListByQueryClassificationId( + Connection connection, + Integer queryClassificationId, + Integer pageSize, + Integer pageNum, + String filterString, + Long startTime, + Long endTime, + Integer executionResult) + throws BaseException { + SessionPool sessionPool = getSessionPool(connection); + // TODO 【清华】需要获得查询语句详细信息的接口 + QueryInfoDTO queryInfoDTO = new QueryInfoDTO(); + // FakeData + // *********************************************************** + List queryDataVOS = new ArrayList<>(); + switch (queryClassificationId % 2) { + case 0: + for (int i = 0; i < 200; i++) { + QueryData1VO queryDataVO = new QueryData1VO(); + long currentTimeMillis = System.currentTimeMillis(); + queryDataVO.setId(i); + queryDataVO.setStatement( + "select * from root._metric.'127.0.0.1:8086'.'process_cpu_time'.'name=process'"); + queryDataVO.setRunningTime(currentTimeMillis); + queryDataVO.setIsSlowQuery(i % 2 == 0 ? false : true); + queryDataVO.setTotalTime((int) (currentTimeMillis % 100)); + queryDataVO.setAnalysisTime((int) (currentTimeMillis % 50)); + queryDataVO.setPrecompiledTime((int) (currentTimeMillis % 30)); + queryDataVO.setOptimizedTime((int) (currentTimeMillis % 20)); + queryDataVO.setExecutionTime((int) (currentTimeMillis % 10)); + queryDataVO.setExecutionResult(i % 2 == 0 ? 1 : 2); + queryDataVOS.add(queryDataVO); + } + break; + case 1: + for (int i = 0; i < 200; i++) { + QueryDataVO queryDataVO = new QueryDataVO(); + long currentTimeMillis = System.currentTimeMillis(); + queryDataVO.setId(i); + queryDataVO.setStatement( + "select * from root._metric.'127.0.0.1:8086'.'process_cpu_time'.'name=process'"); + queryDataVO.setRunningTime(currentTimeMillis); + queryDataVO.setIsSlowQuery(i % 2 == 0 ? false : true); + queryDataVO.setTotalTime((int) (currentTimeMillis % 100)); + queryDataVO.setAnalysisTime((int) (currentTimeMillis % 50)); + queryDataVO.setExecutionTime((int) (currentTimeMillis % 10)); + queryDataVO.setExecutionResult(i % 2 == 0 ? 1 : 2); + queryDataVOS.add(queryDataVO); + } + break; + } + // *********************************************************** + int queryDataVOSSize = queryDataVOS.size(); + int count = 0; + Long latestTimeStamp = 0L; + List filteredQueryDataVOS = new ArrayList<>(); + if (queryDataVOSSize > 0) { + if ((filterString != null && filterString.length() != 0) + || (startTime != -1) + || (endTime != -1) + || (executionResult != null)) { + QueryDataDo queryDataDo = + filterQueryData( + queryDataVOS, pageSize, pageNum, filterString, startTime, endTime, executionResult); + + count = queryDataDo.getCount(); + latestTimeStamp = queryDataDo.getLatestTimeStamp(); + filteredQueryDataVOS = queryDataDo.getQueryDataVOs(); + } else { + for (QueryDataVO queryDataVO : queryDataVOS) { + count++; + latestTimeStamp = Math.max(latestTimeStamp, queryDataVO.getRunningTime()); + if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) { + filteredQueryDataVOS.add(queryDataVO); + } + } + } + } + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + List filteredQueryDataStrVOS = new ArrayList<>(); + if (queryClassificationId % 2 == 0) { + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + QueryDataStrVO1 queryDataStrVO = new QueryDataStrVO1(); + BeanUtils.copyProperties(queryDataVO, queryDataStrVO); + queryDataStrVO.setRunningTime(simpleDateFormat.format(queryDataVO.getRunningTime())); + filteredQueryDataStrVOS.add(queryDataStrVO); + } + } else { + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + QueryDataStrVO queryDataStrVO = new QueryDataStrVO(); + BeanUtils.copyProperties(queryDataVO, queryDataStrVO); + queryDataStrVO.setRunningTime(simpleDateFormat.format(queryDataVO.getRunningTime())); + filteredQueryDataStrVOS.add(queryDataStrVO); + } + } + + queryInfoDTO.setTotalCount(count); + queryInfoDTO.setLatestRunningTime(latestTimeStamp); + queryInfoDTO.setFilteredQueryDataStrVOSList(filteredQueryDataStrVOS); + queryInfoDTO.setTotalPage(count % pageSize == 0 ? count / pageSize : count / pageSize + 1); + return queryInfoDTO; + } + + @Override + public MetricsDataForDiagramVO getMetricDataByMetricId(Connection connection, Integer metricId) + throws BaseException { + SessionPool sessionPool = getSessionPool(connection); + SessionDataSetWrapper sessionDataSetWrapper = null; + String url = connection.getHost(); + Integer port = 0; + // TODO: 【清华】端口8086实际上是动态的从connection表中获取,但iotdb-0.13.0存在bug,导致写入的指标位置不对,等待修复,先暂时写死 + String show_version = executeQueryOneValue(sessionPool, "show version"); + if (show_version.contains("0.13") || show_version.contains("0.14")) { + port = 8086; + } else if (show_version.contains("0.12")) { + port = 6667; + url = "0.0.0.0"; + } + // TODO: 指标先写死,后面根据指标Id判断用哪个timeSeries拼串为SQL查得值。 + MetricsChartDataVO metricsChartDataVO = null; + MetricsDataForDiagramVO metricsDataForDiagramVO = new MetricsDataForDiagramVO(); + switch (metricId) { + case 0: + metricsChartDataVO = getJVMGCDiagramData(sessionPool, sessionDataSetWrapper, url, port); + break; + case 1: + metricsChartDataVO = getJVMLoadDiagramData(sessionPool, sessionDataSetWrapper, url, port); + break; + case 2: + metricsChartDataVO = getYGCTimeAndReason(sessionPool, sessionDataSetWrapper, url, port); + break; + case 3: + metricsChartDataVO = getFGCTimeAndReason(sessionPool, sessionDataSetWrapper, url, port); + break; + case 4: + metricsChartDataVO = getVariableThreadCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 5: + metricsChartDataVO = + getVariableTimeThreadCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 6: + metricsChartDataVO = getMemUsedSize(sessionPool, sessionDataSetWrapper, url, port); + break; + case 7: + metricsChartDataVO = getBufferSize(sessionPool, sessionDataSetWrapper, url, port); + break; + case 8: + metricsChartDataVO = getCPUTime(sessionPool, sessionDataSetWrapper, url, port); + break; + case 9: + metricsChartDataVO = getDiskIO(sessionPool, sessionDataSetWrapper, url, port); + break; + case 10: + metricsChartDataVO = getFileCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 11: + metricsChartDataVO = getFileSize(sessionPool, sessionDataSetWrapper, url, port); + break; + case 12: + metricsChartDataVO = getWriteCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 13: + metricsChartDataVO = getQueryCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 14: + metricsChartDataVO = getInterfaceCount(sessionPool, sessionDataSetWrapper, url, port); + break; + case 15: + metricsChartDataVO = getInterfaceTime(sessionPool, sessionDataSetWrapper, url, port); + break; + } + metricsDataForDiagramVO.setChartData(metricsChartDataVO); + metricsDataForDiagramVO.setMetricId(metricId); + return metricsDataForDiagramVO; + } + + private MetricsChartDataVO getInterfaceTime( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + // TODO:假数据 + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("Interface1"); + metricnameList.add("Interface2"); + metricnameList.add("Interface3"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List interface1 = new ArrayList<>(); + List interface2 = new ArrayList<>(); + List interface3 = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + // try { + // sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + // int batchSize = sessionDataSetWrapper.getBatchSize(); + // if (batchSize > 0) { + // int count = 0; + // while (sessionDataSetWrapper.hasNext()) { + // count++; + // RowRecord rowRecord = sessionDataSetWrapper.next(); + // long timestamp = rowRecord.getTimestamp(); + // List fields1 = rowRecord.getFields(); + // String pattern1 = "HH:mm"; + // SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + // timeList.add(simpleDateFormat1.format(timestamp)); + // buffer.add( + // getNetFileSizeDescription( + // (getLongFromString( + // (Float.parseFloat(fields1.get(0).toString()) + // + Float.parseFloat(fields1.get(1).toString())) + // + "")))); + // } + // Collections.reverse(buffer); + // Collections.reverse(max); + // dataList.put(metricnameList.get(0), buffer); + // dataList.put(metricnameList.get(1), max); + // Collections.reverse(timeList); + // metricsChartDataVO.setTimeList(timeList); + // metricsChartDataVO.setMetricnameList(metricnameList); + // metricsChartDataVO.setDataList(dataList); + // } + // } catch (IoTDBConnectionException e) { + // e.printStackTrace(); + // } catch (StatementExecutionException e) { + // e.printStackTrace(); + // } + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + long timestamp = System.currentTimeMillis(); + for (int i = 0; i < 16; i++) { + timeList.add(simpleDateFormat1.format(timestamp)); + timestamp -= 60000; + interface1.add("300"); + interface2.add("200"); + interface3.add("500"); + } + Collections.reverse(timeList); + Collections.reverse(interface1); + Collections.reverse(interface2); + Collections.reverse(interface3); + dataList.put(metricnameList.get(0), interface1); + dataList.put(metricnameList.get(1), interface2); + dataList.put(metricnameList.get(2), interface3); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + return metricsChartDataVO; + } + + private MetricsChartDataVO getInterfaceCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("Close Operation"); + metricnameList.add("Execute Query Statement"); + metricnameList.add("Execute Statement"); + metricnameList.add("Get Properties"); + metricnameList.add("Insert Record"); + metricnameList.add("Close Session"); + metricnameList.add("Open Session"); + metricnameList.add("Request Statement Id"); + metricnameList.add("Fetch Results"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List close_Operation = new ArrayList<>(); + List execute_Query_Statement = new ArrayList<>(); + List execute_Statement = new ArrayList<>(); + List get_Properties = new ArrayList<>(); + List insert_Record = new ArrayList<>(); + List close_Session = new ArrayList<>(); + List open_Session = new ArrayList<>(); + List request_Statement_Id = new ArrayList<>(); + List fetch_Results = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=closeOperation\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=executeQueryStatement\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=executeStatement\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=getProperties\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=insertRecord\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=closeSession\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=openSession\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=requestStatementId\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"entry_total\".\"name=fetchResults\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + close_Operation.add(fields1.get(0).toString()); + execute_Query_Statement.add(fields1.get(1).toString()); + execute_Statement.add(fields1.get(2).toString()); + get_Properties.add(fields1.get(3).toString()); + insert_Record.add(fields1.get(4).toString()); + close_Session.add(fields1.get(5).toString()); + open_Session.add(fields1.get(6).toString()); + request_Statement_Id.add(fields1.get(7).toString()); + fetch_Results.add(fields1.get(8).toString()); + } + Collections.reverse(close_Operation); + Collections.reverse(execute_Query_Statement); + Collections.reverse(execute_Statement); + Collections.reverse(get_Properties); + Collections.reverse(insert_Record); + Collections.reverse(close_Session); + Collections.reverse(open_Session); + Collections.reverse(request_Statement_Id); + Collections.reverse(fetch_Results); + dataList.put(metricnameList.get(0), close_Operation); + dataList.put(metricnameList.get(1), execute_Query_Statement); + dataList.put(metricnameList.get(2), execute_Statement); + dataList.put(metricnameList.get(3), get_Properties); + dataList.put(metricnameList.get(4), insert_Record); + dataList.put(metricnameList.get(5), close_Session); + dataList.put(metricnameList.get(6), open_Session); + dataList.put(metricnameList.get(7), request_Statement_Id); + dataList.put(metricnameList.get(8), fetch_Results); + Collections.reverse(timeList); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getQueryCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + // TODO:假数据 + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("success"); + metricnameList.add("fail"); + metricnameList.add("total"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List success = new ArrayList<>(); + List fail = new ArrayList<>(); + List total = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + // try { + // sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + // int batchSize = sessionDataSetWrapper.getBatchSize(); + // if (batchSize > 0) { + // int count = 0; + // while (sessionDataSetWrapper.hasNext()) { + // count++; + // RowRecord rowRecord = sessionDataSetWrapper.next(); + // long timestamp = rowRecord.getTimestamp(); + // List fields1 = rowRecord.getFields(); + // String pattern1 = "HH:mm"; + // SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + // timeList.add(simpleDateFormat1.format(timestamp)); + // buffer.add( + // getNetFileSizeDescription( + // (getLongFromString( + // (Float.parseFloat(fields1.get(0).toString()) + // + Float.parseFloat(fields1.get(1).toString())) + // + "")))); + // } + // Collections.reverse(buffer); + // Collections.reverse(max); + // dataList.put(metricnameList.get(0), buffer); + // dataList.put(metricnameList.get(1), max); + // Collections.reverse(timeList); + // metricsChartDataVO.setTimeList(timeList); + // metricsChartDataVO.setMetricnameList(metricnameList); + // metricsChartDataVO.setDataList(dataList); + // } + // } catch (IoTDBConnectionException e) { + // e.printStackTrace(); + // } catch (StatementExecutionException e) { + // e.printStackTrace(); + // } + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + long timestamp = System.currentTimeMillis(); + for (int i = 0; i < 16; i++) { + timeList.add(simpleDateFormat1.format(timestamp)); + timestamp -= 60000; + success.add("100"); + fail.add("200"); + total.add("300"); + } + Collections.reverse(timeList); + Collections.reverse(success); + Collections.reverse(fail); + Collections.reverse(total); + dataList.put(metricnameList.get(0), success); + dataList.put(metricnameList.get(1), fail); + dataList.put(metricnameList.get(2), total); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + return metricsChartDataVO; + } + + private MetricsChartDataVO getWriteCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + // TODO:假数据 + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("success"); + metricnameList.add("fail"); + metricnameList.add("total"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List success = new ArrayList<>(); + List fail = new ArrayList<>(); + List total = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + // try { + // sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + // int batchSize = sessionDataSetWrapper.getBatchSize(); + // if (batchSize > 0) { + // int count = 0; + // while (sessionDataSetWrapper.hasNext()) { + // count++; + // RowRecord rowRecord = sessionDataSetWrapper.next(); + // long timestamp = rowRecord.getTimestamp(); + // List fields1 = rowRecord.getFields(); + // String pattern1 = "HH:mm"; + // SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + // timeList.add(simpleDateFormat1.format(timestamp)); + // buffer.add( + // getNetFileSizeDescription( + // (getLongFromString( + // (Float.parseFloat(fields1.get(0).toString()) + // + Float.parseFloat(fields1.get(1).toString())) + // + "")))); + // } + // Collections.reverse(buffer); + // Collections.reverse(max); + // dataList.put(metricnameList.get(0), buffer); + // dataList.put(metricnameList.get(1), max); + // Collections.reverse(timeList); + // metricsChartDataVO.setTimeList(timeList); + // metricsChartDataVO.setMetricnameList(metricnameList); + // metricsChartDataVO.setDataList(dataList); + // } + // } catch (IoTDBConnectionException e) { + // e.printStackTrace(); + // } catch (StatementExecutionException e) { + // e.printStackTrace(); + // } + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + long timestamp = System.currentTimeMillis(); + for (int i = 0; i < 16; i++) { + timeList.add(simpleDateFormat1.format(timestamp)); + timestamp -= 60000; + success.add("10"); + fail.add("20"); + total.add("30"); + } + Collections.reverse(timeList); + Collections.reverse(success); + Collections.reverse(fail); + Collections.reverse(total); + dataList.put(metricnameList.get(0), success); + dataList.put(metricnameList.get(1), fail); + dataList.put(metricnameList.get(2), total); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + return metricsChartDataVO; + } + + private MetricsChartDataVO getFileSize( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("wal"); + metricnameList.add("tsfile_seq"); + metricnameList.add("tsfile_unseq"); + metricnameList.add("total"); + List unitList = new ArrayList<>(); + unitList.add("MB"); + List wal = new ArrayList<>(); + List tsfile_seq = new ArrayList<>(); + List tsfile_unseq = new ArrayList<>(); + List total = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=wal\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=seq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + wal.add(getNetFileSizeDescription((long) Float.parseFloat(fields1.get(0).toString()))); + tsfile_seq.add( + getNetFileSizeDescription((long) Float.parseFloat(fields1.get(1).toString()))); + tsfile_unseq.add( + getNetFileSizeDescription((long) Float.parseFloat(fields1.get(2).toString()))); + total.add( + getNetFileSizeDescription( + (long) + (Float.parseFloat(fields1.get(0).toString()) + + Float.parseFloat(fields1.get(1).toString()) + + Float.parseFloat(fields1.get(2).toString())))); + } + Collections.reverse(timeList); + Collections.reverse(wal); + Collections.reverse(tsfile_seq); + Collections.reverse(tsfile_unseq); + Collections.reverse(total); + dataList.put(metricnameList.get(0), wal); + dataList.put(metricnameList.get(1), tsfile_seq); + dataList.put(metricnameList.get(2), tsfile_unseq); + dataList.put(metricnameList.get(3), total); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getFileCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("wal"); + metricnameList.add("tsfile_seq"); + metricnameList.add("tsfile_unseq"); + metricnameList.add("total"); + List unitList = new ArrayList<>(); + unitList.add("个"); + List wal = new ArrayList<>(); + List tsfile_seq = new ArrayList<>(); + List tsfile_unseq = new ArrayList<>(); + List total = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=wal\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=seq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + String s1 = fields1.get(0).toString(); + wal.add(s1.substring(0, s1.indexOf('.'))); + String s2 = fields1.get(1).toString(); + tsfile_seq.add(s2.substring(0, s2.indexOf('.'))); + String s3 = fields1.get(2).toString(); + tsfile_unseq.add(s3.substring(0, s3.indexOf('.'))); + total.add( + (Integer.parseInt(s1.substring(0, s1.indexOf('.'))) + + Integer.parseInt(s2.substring(0, s2.indexOf('.')))) + + Integer.parseInt(s3.substring(0, s3.indexOf('.'))) + + "个"); + } + Collections.reverse(timeList); + Collections.reverse(wal); + Collections.reverse(tsfile_seq); + Collections.reverse(tsfile_unseq); + Collections.reverse(total); + dataList.put(metricnameList.get(0), wal); + dataList.put(metricnameList.get(1), tsfile_seq); + dataList.put(metricnameList.get(2), tsfile_unseq); + dataList.put(metricnameList.get(3), total); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getDiskIO( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + // TODO : 假数据 等待接口 + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("io"); + List unitList = new ArrayList<>(); + unitList.add("次/s"); + List io = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + // try { + // sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + // int batchSize = sessionDataSetWrapper.getBatchSize(); + // if (batchSize > 0) { + // int count = 0; + // while (sessionDataSetWrapper.hasNext()) { + // count++; + // RowRecord rowRecord = sessionDataSetWrapper.next(); + // long timestamp = rowRecord.getTimestamp(); + // List fields1 = rowRecord.getFields(); + // String pattern1 = "HH:mm"; + // SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + // timeList.add(simpleDateFormat1.format(timestamp)); + // buffer.add( + // getNetFileSizeDescription( + // (getLongFromString( + // (Float.parseFloat(fields1.get(0).toString()) + // + Float.parseFloat(fields1.get(1).toString())) + // + "")))); + // } + // Collections.reverse(buffer); + // Collections.reverse(max); + // dataList.put(metricnameList.get(0), buffer); + // dataList.put(metricnameList.get(1), max); + // Collections.reverse(timeList); + // metricsChartDataVO.setTimeList(timeList); + // metricsChartDataVO.setMetricnameList(metricnameList); + // metricsChartDataVO.setDataList(dataList); + // } + // } catch (IoTDBConnectionException e) { + // e.printStackTrace(); + // } catch (StatementExecutionException e) { + // e.printStackTrace(); + // } + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + long timestamp = System.currentTimeMillis(); + for (int i = 0; i < 16; i++) { + timeList.add(simpleDateFormat1.format(timestamp)); + timestamp -= 60000; + io.add("20"); + } + Collections.reverse(timeList); + Collections.reverse(io); + dataList.put(metricnameList.get(0), io); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + return metricsChartDataVO; + } + + private MetricsChartDataVO getBufferSize( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("buffer"); + metricnameList.add("max"); + List unitList = new ArrayList<>(); + unitList.add("MB"); + List buffer = new ArrayList<>(); + List max = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=direct\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.total.capacity\".\"id=mapped\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.total.capacity\".\"id=direct\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + buffer.add( + getNetFileSizeDescription( + (getLongFromString( + (Float.parseFloat(fields1.get(0).toString()) + + Float.parseFloat(fields1.get(1).toString())) + + "")))); + max.add( + getNetFileSizeDescription( + (getLongFromString( + (Float.parseFloat(fields1.get(2).toString()) + + Float.parseFloat(fields1.get(3).toString())) + + "")))); + } + Collections.reverse(buffer); + Collections.reverse(max); + dataList.put(metricnameList.get(0), buffer); + dataList.put(metricnameList.get(1), max); + Collections.reverse(timeList); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getMemUsedSize( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("storage"); + metricnameList.add("max"); + List unitList = new ArrayList<>(); + unitList.add("MB"); + List storage = new ArrayList<>(); + List max = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Compressed Class Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Code Cache\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Metaspace\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Old Gen\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Eden Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Survivor Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Compressed Class Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Code Cache\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Metaspace\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Old Gen\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Eden Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Survivor Space\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + storage.add( + getNetFileSizeDescription( + (getLongFromString( + (Float.parseFloat(fields1.get(6).toString()) + + Float.parseFloat(fields1.get(7).toString()) + + Float.parseFloat(fields1.get(8).toString()) + + Float.parseFloat(fields1.get(9).toString()) + + Float.parseFloat(fields1.get(10).toString()) + + Float.parseFloat(fields1.get(11).toString())) + + "")))); + max.add( + getNetFileSizeDescription( + (getLongFromString( + (Float.parseFloat(fields1.get(0).toString()) + + Float.parseFloat(fields1.get(1).toString()) + + Float.parseFloat(fields1.get(2).toString()) + + Float.parseFloat(fields1.get(3).toString()) + + Float.parseFloat(fields1.get(4).toString()) + + Float.parseFloat(fields1.get(5).toString())) + + "")))); + } + Collections.reverse(storage); + Collections.reverse(max); + dataList.put(metricnameList.get(0), storage); + dataList.put(metricnameList.get(1), max); + Collections.reverse(timeList); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getVariableTimeThreadCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("new"); + metricnameList.add("canrunning"); + metricnameList.add("running"); + metricnameList.add("block"); + metricnameList.add("die"); + metricnameList.add("dormancy"); + List unitList = new ArrayList<>(); + unitList.add("个"); + List newState = new ArrayList<>(); + List canrunning = new ArrayList<>(); + List running = new ArrayList<>(); + List block = new ArrayList<>(); + List die = new ArrayList<>(); + List dormancy = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=new\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=waiting\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=runnable\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=blocked\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=timed-waiting\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=terminated\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + String s1 = fields1.get(0).toString(); + newState.add(s1.substring(0, s1.indexOf('.'))); + String s2 = fields1.get(1).toString(); + canrunning.add(s2.substring(0, s2.indexOf('.'))); + String s3 = fields1.get(2).toString(); + running.add(s3.substring(0, s3.indexOf('.'))); + String s4 = fields1.get(3).toString(); + block.add(s4.substring(0, s4.indexOf('.'))); + String s5 = fields1.get(4).toString(); + die.add(s5.substring(0, s5.indexOf('.'))); + String s6 = fields1.get(5).toString(); + dormancy.add(s6.substring(0, s6.indexOf('.'))); + } + Collections.reverse(timeList); + Collections.reverse(newState); + Collections.reverse(canrunning); + Collections.reverse(running); + Collections.reverse(block); + Collections.reverse(die); + Collections.reverse(dormancy); + dataList.put(metricnameList.get(0), newState); + dataList.put(metricnameList.get(1), canrunning); + dataList.put(metricnameList.get(2), running); + dataList.put(metricnameList.get(3), block); + dataList.put(metricnameList.get(4), die); + dataList.put(metricnameList.get(5), dormancy); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getVariableThreadCount( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("front"); + metricnameList.add("end"); + metricnameList.add("total"); + List unitList = new ArrayList<>(); + unitList.add("个"); + List front = new ArrayList<>(); + List end = new ArrayList<>(); + List total = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + 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 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + String s1 = fields1.get(0).toString(); + end.add(s1.substring(0, s1.indexOf('.'))); + String s2 = fields1.get(1).toString(); + total.add(s2.substring(0, s2.indexOf('.'))); + front.add( + (Integer.parseInt(s2.substring(0, s2.indexOf('.'))) + - Integer.parseInt(s1.substring(0, s1.indexOf('.')))) + + ""); + } + Collections.reverse(timeList); + Collections.reverse(front); + Collections.reverse(end); + Collections.reverse(total); + dataList.put(metricnameList.get(0), front); + dataList.put(metricnameList.get(1), end); + dataList.put(metricnameList.get(2), total); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getCPUTime( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + // TODO:【接口缺失,等待确认增加】 + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("模块1"); + metricnameList.add("模块2"); + metricnameList.add("模块3"); + metricnameList.add("模块4"); + metricnameList.add("模块5"); + List unitList = new ArrayList<>(); + unitList.add("%"); + List module1 = new ArrayList<>(); + List module2 = new ArrayList<>(); + List module3 = new ArrayList<>(); + List module4 = new ArrayList<>(); + List module5 = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + 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"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + // try { + // sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + // int batchSize = sessionDataSetWrapper.getBatchSize(); + // if (batchSize > 0) { + // int count = 0; + // while (sessionDataSetWrapper.hasNext()) { + // count++; + // RowRecord rowRecord = sessionDataSetWrapper.next(); + // long timestamp = rowRecord.getTimestamp(); + // List fields1 = rowRecord.getFields(); + // String pattern1 = "HH:mm"; + // SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + // timeList.add(simpleDateFormat1.format(timestamp)); + // String s1 = fields1.get(0).toString(); + // end.add(s1.substring(0, s1.indexOf('.'))); + // String s2 = fields1.get(1).toString(); + // total.add(s2.substring(0, s2.indexOf('.'))); + // front.add((Integer.parseInt(s2.substring(0, + // s2.indexOf('.')))-Integer.parseInt(s1.substring(0, s1.indexOf('.')))) + ""); + // } + // dataList.put(metricnameList.get(0), front); + // dataList.put(metricnameList.get(1), end); + // dataList.put(metricnameList.get(2), total); + // metricsChartDataVO.setTimeList(timeList); + // metricsChartDataVO.setMetricnameList(metricnameList); + // metricsChartDataVO.setDataList(dataList); + // } + // } catch (IoTDBConnectionException e) { + // e.printStackTrace(); + // } catch (StatementExecutionException e) { + // e.printStackTrace(); + // } + module1.add("15" + "%"); + module2.add("25" + "%"); + module3.add("20" + "%"); + module4.add("30" + "%"); + module5.add("10" + "%"); + + dataList.put(metricnameList.get(0), module1); + dataList.put(metricnameList.get(1), module2); + dataList.put(metricnameList.get(2), module3); + dataList.put(metricnameList.get(3), module3); + dataList.put(metricnameList.get(4), module3); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + return metricsChartDataVO; + } + + private MetricsChartDataVO getYGCTimeAndReason( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("Metadata GC Threshold"); + metricnameList.add("Allocation Failure"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List metadata_GC_Threshold_Reason = new ArrayList<>(); + List Allocation_Failure_Reason = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_total\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_total\".\"action=end of minor GC\".\"cause=Allocation Failure\" " + + "order by time desc limit 1"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + metadata_GC_Threshold_Reason.add(Float.parseFloat(fields1.get(0).toString()) + ""); + Allocation_Failure_Reason.add(Float.parseFloat(fields1.get(1).toString()) + ""); + } + dataList.put(metricnameList.get(0), metadata_GC_Threshold_Reason); + dataList.put(metricnameList.get(1), Allocation_Failure_Reason); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getFGCTimeAndReason( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("Metadata GC Threshold"); + List unitList = new ArrayList<>(); + unitList.add("ms"); + List metadata_GC_Threshold_Reason = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "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"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + metadata_GC_Threshold_Reason.add(Float.parseFloat(fields1.get(0).toString()) + ""); + } + dataList.put(metricnameList.get(0), metadata_GC_Threshold_Reason); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private MetricsChartDataVO getJVMLoadDiagramData( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("load"); + metricnameList.add("unload"); + List unitList = new ArrayList<>(); + unitList.add("个"); + List load = new ArrayList<>(); + List unload = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.classes.loaded\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.classes.unloaded\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + String s1 = fields1.get(0).toString(); + load.add(s1.substring(0, s1.indexOf('.'))); + String s2 = fields1.get(1).toString(); + unload.add(s2.substring(0, s2.indexOf('.'))); + } + Collections.reverse(load); + Collections.reverse(unload); + dataList.put(metricnameList.get(0), load); + dataList.put(metricnameList.get(1), unload); + Collections.reverse(timeList); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + @Override + public List getTopQueryMetricsData() { + // TODO [清华]提供获取Top SQL语句信息的接口 + // FakeData + List queryMetricsVOS = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + QueryMetricsVO queryMetricsVO = new QueryMetricsVO(); + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String timeStamp = simpleDateFormat.format(System.currentTimeMillis()); + queryMetricsVO.setSQLStatement("SELECT * FROM root.* where time > " + timeStamp); + queryMetricsVO.setRunningTime(timeStamp); + queryMetricsVO.setExecutionTime(200 - 10 * i); + queryMetricsVOS.add(queryMetricsVO); + } + return queryMetricsVOS; + } + + @Override + public List getSlowQueryMetricsData() { + // TODO [清华]提供获取Slow SQL语句信息的接口 + // FakeData + List queryMetricsVOS = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + QueryMetricsVO queryMetricsVO = new QueryMetricsVO(); + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String timeStamp = simpleDateFormat.format(System.currentTimeMillis()); + queryMetricsVO.setSQLStatement("SELECT * FROM root.* where time > " + timeStamp); + queryMetricsVO.setRunningTime(timeStamp); + queryMetricsVO.setExecutionTime(1000 - 10 * i); + queryMetricsVOS.add(queryMetricsVO); + } + return queryMetricsVOS; + } + + private MetricsChartDataVO getJVMGCDiagramData( + SessionPool sessionPool, + SessionDataSetWrapper sessionDataSetWrapper, + String url, + Integer port) { + List timeList = new ArrayList<>(); + List metricnameList = new ArrayList<>(); + metricnameList.add("fgc次数"); + metricnameList.add("ygc次数"); + metricnameList.add("fgc耗时"); + metricnameList.add("ygc耗时"); + List unitList = new ArrayList<>(); + unitList.add("次"); + unitList.add("ms"); + List majorGCCount = new ArrayList<>(); + List minorGCCount = new ArrayList<>(); + List majorGCTime = new ArrayList<>(); + List minorGCTime = new ArrayList<>(); + HashMap> dataList = new HashMap<>(); + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_count\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\", " + + "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 major GC\".\"cause=Metadata GC Threshold\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_total\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\", " + + "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 major GC\".\"cause=Metadata GC Threshold\" " + + "order by time desc limit 16"; + MetricsChartDataVO metricsChartDataVO = new MetricsChartDataVO(); + try { + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + int batchSize = sessionDataSetWrapper.getBatchSize(); + if (batchSize > 0) { + int count = 0; + while (sessionDataSetWrapper.hasNext()) { + count++; + RowRecord rowRecord = sessionDataSetWrapper.next(); + long timestamp = rowRecord.getTimestamp(); + List fields1 = rowRecord.getFields(); + String pattern1 = "HH:mm"; + SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1); + timeList.add(simpleDateFormat1.format(timestamp)); + String s1 = fields1.get(2).toString(); + s1 = s1.substring(0, s1.indexOf('.')); + String s2 = fields1.get(0).toString(); + s2 = s2.substring(0, s2.indexOf('.')); + String s3 = fields1.get(1).toString(); + s3 = s3.substring(0, s3.indexOf('.')); + majorGCCount.add(s1 + "次"); + minorGCCount.add((Integer.parseInt(s2) + Integer.parseInt(s3)) + "次"); + majorGCTime.add(Float.parseFloat(fields1.get(5).toString()) + "ms"); + minorGCTime.add( + (Float.parseFloat(fields1.get(3).toString()) + + Float.parseFloat(fields1.get(4).toString())) + + "ms"); + } + Collections.reverse(majorGCCount); + Collections.reverse(minorGCCount); + Collections.reverse(majorGCTime); + Collections.reverse(minorGCTime); + dataList.put(metricnameList.get(0), majorGCCount); + dataList.put(metricnameList.get(1), minorGCCount); + dataList.put(metricnameList.get(2), majorGCTime); + dataList.put(metricnameList.get(3), minorGCTime); + Collections.reverse(timeList); + metricsChartDataVO.setTimeList(timeList); + metricsChartDataVO.setMetricnameList(metricnameList); + metricsChartDataVO.setDataList(dataList); + metricsChartDataVO.setUnitList(unitList); + } + } catch (IoTDBConnectionException e) { + e.printStackTrace(); + } catch (StatementExecutionException e) { + e.printStackTrace(); + } + return metricsChartDataVO; + } + + private QueryDataDo filterQueryData( + List queryDataVOS, + Integer pageSize, + Integer pageNum, + String filterString, + Long startTime, + Long endTime, + Integer executionResult) { + List filteredQueryDataVOS = new ArrayList<>(); + filteredQueryDataVOS.addAll(queryDataVOS); + if (filterString != null) { + List tempList = new ArrayList<>(); + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + if (queryDataVO.getStatement().contains(filterString)) { + tempList.add(queryDataVO); + } + } + filteredQueryDataVOS.clear(); + filteredQueryDataVOS.addAll(tempList); + } + if (startTime != -1) { + List tempList = new ArrayList<>(); + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + if (queryDataVO.getRunningTime() >= startTime) { + tempList.add(queryDataVO); + } + } + filteredQueryDataVOS.clear(); + filteredQueryDataVOS.addAll(tempList); + } + if (endTime != -1) { + List tempList = new ArrayList<>(); + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + if (queryDataVO.getRunningTime() <= endTime) { + tempList.add(queryDataVO); + } + } + filteredQueryDataVOS.clear(); + filteredQueryDataVOS.addAll(tempList); + } + if (executionResult != null) { + List tempList = new ArrayList<>(); + if (executionResult == 0) { + tempList.addAll(filteredQueryDataVOS); + } else { + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + if (queryDataVO.getExecutionResult().equals(executionResult)) { + tempList.add(queryDataVO); + } + } + } + filteredQueryDataVOS.clear(); + filteredQueryDataVOS.addAll(tempList); + } + + System.out.println(filteredQueryDataVOS.size()); + int count = 0; + Long latestTimeStamp = 0L; + List pageFilteredQueryDataVOS = new ArrayList<>(); + for (QueryDataVO queryDataVO : filteredQueryDataVOS) { + count++; + if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) { + pageFilteredQueryDataVOS.add(queryDataVO); + } + latestTimeStamp = Math.max(latestTimeStamp, queryDataVO.getRunningTime()); + } + + QueryDataDo queryDataDo = new QueryDataDo(); + queryDataDo.setCount(count); + queryDataDo.setLatestTimeStamp(latestTimeStamp); + queryDataDo.setQueryDataVOs(pageFilteredQueryDataVOS); + return queryDataDo; + } + private void grantOrRevoke( String grantOrRevoke, String userOrRole, @@ -2342,20 +4077,17 @@ private void grantOrRevokePaths( List paths, SessionPool sessionPool) throws BaseException { + String sql = null; + String show_version = executeQueryOneValue(sessionPool, "show version"); + if (show_version.contains("0.13") || show_version.contains("0.14")) { + sql = grantOrRevoke + " " + userOrRole + " " + name + " privileges " + privilege + " on "; + } else if (show_version.contains("0.12")) { + sql = grantOrRevoke + " " + userOrRole + " " + name + " privileges '" + privilege + "' on "; + } if (notNullAndNotZero(paths)) { for (String groupPath : paths) { - String sql = - grantOrRevoke - + " " - + userOrRole - + " " - + name - + " privileges '" - + privilege - + "' on " - + groupPath; try { - sessionPool.executeNonQueryStatement(sql); + sessionPool.executeNonQueryStatement(sql + groupPath); } catch (StatementExecutionException e) { logger.error(e.getMessage()); if (e.getStatusCode() == 602) { @@ -2504,7 +4236,7 @@ private SqlResultVO executeQuery(SessionPool sessionPool, String sql, String not RowRecord rowRecord = sessionDataSetWrapper.next(); if (timeFlag) { long timestamp = rowRecord.getTimestamp(); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); Date date = new Date(timestamp); String timeStr = simpleDateFormat.format(date); strList.add(timeStr); @@ -2746,9 +4478,9 @@ private List handleEncodingStr(List encoding) throws BaseExc case "PLAIN": list.add(TSEncoding.PLAIN); break; - case "PLAIN_DICTIONARY": - list.add(TSEncoding.PLAIN_DICTIONARY); - break; + // case "PLAIN_DICTIONARY": + // list.add(TSEncoding.DICTIONARY); + // break; case "RLE": list.add(TSEncoding.RLE); break; @@ -2783,9 +4515,9 @@ private TSEncoding handleEncodingStr(String encoding) throws BaseException { case "PLAIN": tsEncoding = TSEncoding.PLAIN; break; - case "PLAIN_DICTIONARY": - tsEncoding = TSEncoding.PLAIN_DICTIONARY; - break; + // case "PLAIN_DICTIONARY": + // tsEncoding = TSEncoding.DICTIONARY; + // break; case "RLE": tsEncoding = TSEncoding.RLE; break; @@ -2966,4 +4698,25 @@ private void closeResultSet(SessionDataSetWrapper sessionDataSetWrapper) { sessionDataSetWrapper.close(); } } + + private static String getNetFileSizeDescription(long size) { + StringBuffer bytes = new StringBuffer(); + DecimalFormat format = new DecimalFormat("###.0"); + double i = (size / (1024.0 * 1024.0)); + bytes.append(format.format(i)); + if (bytes.toString().equals(".0")) { + return "0.0"; + } + return bytes.toString(); + } + + private static long getLongFromString(String timeStr) { + long count = Long.parseLong(timeStr.substring(timeStr.indexOf("E") + 1)); + double time = Double.parseDouble(timeStr.substring(0, timeStr.indexOf("E"))); + while (count > 0) { + time *= 10; + count--; + } + return (long) time; + } } diff --git a/backend/src/main/resources/sqlite/iotdb.db b/backend/src/main/resources/sqlite/iotdb.db index 970084984f4e5f3c1168bbb3fc088e34b67fb1a3..26e0b2555b4195342e6b8885410327b553985045 100644 GIT binary patch delta 1189 zcmZuwO>7%Q6rT02S?_M_XO|>yTA@s~vYgQ1G;yk?LIIh0QY_N7*{qRsGK)R93;s!W zH=*T{Yz3DJ39KBD$fZJ@xS+})6(o+WgoM;f1qYe~3W6g+9Jn&Oi5&|uqmkac_q}iC zee-7bUTF6o|H=8p0YWIsmckat)>3yin>s+57ypVzK1PaILGV6I#}?$bqi>GfQTC;W zVntex9EQKW?_CZH(rDOr}!Y2NzxQttM?z*S2a-!|rTt4%^Wco#YIH zjod411gpa#6;DTHj8&_yVyo@a2DPzPG_Y1)Tf-&2a6PAQ;Md3o&XtW~L1RSMiDt|O zIqe;@MOEz5Tkas|II?Zg_o}TWo1 z*nnyV>tvPaL|Y;2EN!`e46DMgU&=i2fgW+kx%|sjw1H-YU>^_`Qw= zVWsvSN^P#|-RSKrjnT7jAQAE*IDkLkQ}_(KQKE(~UhXkLaxvqC{ zGA{G!h~su_vq7stgGnNv(`uV$7OGxG~enafwtDR!sh`s)(& zWGay2PjT7I!lf&j#cXEj%DIstT$bUUqS>xD-FxuztEDqC9I<;m=HM~>0>8r%9Q6{r z-@pt07xahBPjJWdLf>W-yu?pPt=lejT!x8vb4gBSd4EE;6pr~nn1?3_{)S)S33ES! zRfXr#b9K5Mv}`=YqjYDJ+9ne&@F*M$o6Tmh@$)6Pi`Zp;gP-9Md=Fp4m+%?f?IlW^ zupN^GG$lE-$=b2%+-$}o{@!Xk)DHF$Q9xr--E!U)pApcrQj504uy52hw?Gik1?ipb kR<+hN9fvv!FQD^*gTdsGfF^=XqZZ?QRv+o!u&G)97oPV)a{vGU delta 457 zcmZozz}&EaX@a!iS_TFNP9TN>)rmUBvTGUif)jYT^%*!gk23IA@oVrIai#Gl@HBDH z<~+JtP~a^G7f|xAxVk!Hv+?Am-15?_&Oxq@A+8D`j!r(V3dJS)MTzOD@##hRr3I7U zaY}4H%9+O~AucJ&*sNKSn3R*6l3JFT3?Yb@tu7jG;A5~ghYY@4TX=ZJ_b zVqoK+&d7h4|2hA3{$2d*`A_rLZ59m3;8){c#30FmVoiKXdVEQ40Vg}NIAdXHYEdN% z|M$sD^wos~xR}*Zl}^5^uPSkefsua)5b@vPzs>g;0fF8-$v642ow1Cbp%iyfetroE z=T?@a7MHLBLur#dlc=cp Date: Mon, 30 May 2022 10:40:30 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E5=B1=95=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 该版本适配低于0.13版本的iotdb并提供数据库管理功能,但不提供监控管理(低于0.13版本iotdb不支持监控); - 仍然存在部分接口返回后端假数据,等待清华提供接口后替换为真实数据。 --- .../admin/controller/IotDBController.java | 57 +- .../admin/controller/MetricsController.java | 170 ++ .../iotdb/admin/mapper/ViewModeMapper.java | 13 + .../admin/model/dto/DataModelDetailDTO.java | 15 + .../iotdb/admin/model/dto/QueryInfoDTO.java | 19 + .../iotdb/admin/model/entity/ViewMode.java | 30 + .../admin/model/metricsDo/QueryDataDo.java | 18 + .../iotdb/admin/model/vo/DataModelVO.java | 10 + .../iotdb/admin/model/vo/GroupInfo.java | 16 + .../iotdb/admin/model/vo/GroupInfoVO.java | 6 +- .../admin/model/vo/JVMMetricsListDataVO.java | 14 + .../vo/MetircsQueryClassificationVO.java | 15 + .../admin/model/vo/MetricsChartDataVO.java | 23 + .../admin/model/vo/MetricsConnectionVO.java | 15 + .../admin/model/vo/MetricsDataCountVO.java | 20 + .../model/vo/MetricsDataForDiagramVO.java | 16 + .../admin/model/vo/MetricsDataForListVO.java | 16 + .../admin/model/vo/MetricsListDataVO.java | 17 + .../admin/model/vo/QueryClassificationVO.java | 14 + .../iotdb/admin/model/vo/QueryData1VO.java | 15 + .../admin/model/vo/QueryDataForListVO.java | 16 + .../iotdb/admin/model/vo/QueryDataStrVO.java | 21 + .../iotdb/admin/model/vo/QueryDataStrVO1.java | 15 + .../iotdb/admin/model/vo/QueryDataVO.java | 21 + .../iotdb/admin/model/vo/QueryInfoVO.java | 19 + .../iotdb/admin/model/vo/QueryMetricsVO.java | 14 + .../iotdb/admin/service/IotDBService.java | 3 + .../admin/service/MetricsResultService.java | 23 + .../iotdb/admin/service/MetricsService.java | 41 + .../admin/service/impl/IotDBServiceImpl.java | 60 + .../impl/MetricsResultServiceImpl.java | 283 +++ .../service/impl/MetricsServiceImpl.java | 1746 +++++++++++++++++ 32 files changed, 2764 insertions(+), 17 deletions(-) create mode 100644 backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java create mode 100644 backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java index 5b4d0d00..89309134 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java @@ -95,28 +95,57 @@ public BaseVO getDataModel( return BaseVO.success("Get IoTDB data model successfully", dataModelVO); } + @GetMapping("/dataModel/detail") + @ApiOperation("Get IoTDB data model in detail") + public BaseVO getDataModelDetail( + @PathVariable("serverId") Integer serverId, + @RequestParam(value = "path", required = false, defaultValue = "root") String path, + @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, + HttpServletRequest request) + throws BaseException { + check(request, serverId); + Connection connection = connectionService.getById(serverId); + DataModelVO dataModelVO = iotDBService.getDataModelDetail(connection, path, pageSize, pageNum); + return BaseVO.success("Get IoTDB data model successfully", dataModelVO); + } + @GetMapping("/storageGroups/info") @ApiOperation("Get information of the storage group list") - public BaseVO> getAllStorageGroupsInfo( - @PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException { + public BaseVO getAllStorageGroupsInfo( + @PathVariable("serverId") Integer serverId, + @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, + HttpServletRequest request) + throws BaseException { check(request, serverId); Connection connection = connectionService.getById(serverId); List groupNames = iotDBService.getAllStorageGroups(connection); - List groupInfoList = new ArrayList<>(); - if (groupNames == null || groupNames.size() == 0) { - return BaseVO.success("Get successfully", groupInfoList); + List subGroupNames = new ArrayList<>(); + int size = groupNames.size(); + int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize; + int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize; + if (size > pageStart) { + subGroupNames = groupNames.subList(pageStart, pageEnd); + } + List groupInfoList = new ArrayList<>(); + GroupInfoVO groupInfoVO = new GroupInfoVO(); + if (subGroupNames == null || subGroupNames.size() == 0) { + return BaseVO.success("Get successfully", groupInfoVO); } String host = connection.getHost(); - List deviceCounts = iotDBService.getDevicesCount(connection, groupNames); - List descriptions = groupService.getGroupDescription(host, groupNames); - for (int i = 0; i < groupNames.size(); i++) { - GroupInfoVO groupInfoVO = new GroupInfoVO(); - groupInfoVO.setGroupName(groupNames.get(i)); - groupInfoVO.setDeviceCount(deviceCounts.get(i)); - groupInfoVO.setDescription(descriptions.get(i)); - groupInfoList.add(groupInfoVO); + List deviceCounts = iotDBService.getDevicesCount(connection, subGroupNames); + List descriptions = groupService.getGroupDescription(host, subGroupNames); + for (int i = 0; i < subGroupNames.size(); i++) { + GroupInfo groupInfo = new GroupInfo(); + groupInfo.setGroupName(subGroupNames.get(i)); + groupInfo.setDeviceCount(deviceCounts.get(i)); + groupInfo.setDescription(descriptions.get(i)); + groupInfoList.add(groupInfo); } - return BaseVO.success("Get successfully", groupInfoList); + groupInfoVO.setGroupInfoList(groupInfoList); + groupInfoVO.setGroupCount(size); + return BaseVO.success("Get successfully", groupInfoVO); } @GetMapping("/storageGroups") diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java new file mode 100644 index 00000000..5c5a9684 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.admin.controller; + +import org.apache.iotdb.admin.common.exception.BaseException; +import org.apache.iotdb.admin.common.utils.AuthenticationUtils; +import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.vo.*; +import org.apache.iotdb.admin.service.ConnectionService; +import org.apache.iotdb.admin.service.IotDBService; +import org.apache.iotdb.admin.service.MetricsService; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-22-上午 9:55 + */ +@RestController +@Api(value = "metrics related") +public class MetricsController { + + @Autowired private ConnectionService connectionService; + @Autowired private IotDBService iotDBService; + @Autowired private MetricsService metricsService; + + private static final Logger logger = LoggerFactory.getLogger(MetricsController.class); + + @GetMapping("/servers/metrics/connection") + @ApiOperation("[metrics]Get All Connection") + public BaseVO> getConnectionList(HttpServletRequest request) + throws BaseException { + Integer userId = AuthenticationUtils.getUserId(request); + AuthenticationUtils.userAuthentication(userId, request); + List allConnections = connectionService.getAllConnections(userId); + ArrayList metricsConnectionVOS = new ArrayList<>(); + for (ConnVO connVO : allConnections) { + MetricsConnectionVO temp = new MetricsConnectionVO(); + temp.setId(connVO.getId()); + temp.setName(connVO.getAlias()); + metricsConnectionVOS.add(temp); + } + return BaseVO.success("Get Successfully", metricsConnectionVOS); + } + + @GetMapping("/servers/{serverId}/metrics/datacount") + @ApiOperation("[metrics]Get Datacount") + public BaseVO getMetricsConnectionDataCount( + @PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException { + check(request, serverId); + MetricsDataCountVO metricsDataCountVO = metricsService.getMetricsDataCount(serverId); + return BaseVO.success("Get IoTDB data statistics successfully", metricsDataCountVO); + } + + @GetMapping("/servers/{serverId}/metrics/QueryClassification") + @ApiOperation("[metrics]Get all query classifications") + public BaseVO getAllQueryClassification( + @PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException { + check(request, serverId); + MetircsQueryClassificationVO metircsQueryClassificationVO = + metricsService.getMetircsQueryClassification(serverId); + return BaseVO.success("Get IoTDB data statistics successfully", metircsQueryClassificationVO); + } + + @GetMapping("/servers/{serverId}/metrics/{queryClassificationId}/selectcount") + @ApiOperation("[Metrics]Get detail information of query sql") + public BaseVO getQueryInfo( + @PathVariable("serverId") Integer serverId, + @PathVariable("queryClassificationId") Integer queryClassificationId, + @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, + @RequestParam(value = "filterString", required = false) String filterString, + @RequestParam(value = "startTime", required = false, defaultValue = "-1") String startTimeStr, + @RequestParam(value = "endTime", required = false, defaultValue = "-1") String endTimeStr, + @RequestParam(value = "executionResult", required = false) Integer executionResult, + HttpServletRequest request) + throws BaseException { + check(request, serverId); + QueryInfoVO queryInfoVO = + metricsService.getQueryInfo( + serverId, + queryClassificationId, + pageSize, + pageNum, + filterString, + startTimeStr, + endTimeStr, + executionResult); + return BaseVO.success("Get IoTDB query statement data statistics successfully", queryInfoVO); + } + + @GetMapping("/servers/{serverId}/metrics/diagram") + @ApiOperation("Get metrics data for diagram") + public BaseVO getMetricsDataForDiagram( + @PathVariable("serverId") Integer serverId, + @RequestParam Integer metricId, + HttpServletRequest request) + throws BaseException { + check(request, serverId); + Connection connection = connectionService.getById(serverId); + MetricsDataForDiagramVO metricsDataForDiagramVO = + iotDBService.getMetricDataByMetricId(connection, metricId); + metricsDataForDiagramVO.setServerId(serverId); + return BaseVO.success("Get metrics data for diagram successfully", metricsDataForDiagramVO); + } + + @GetMapping("/servers/{serverId}/metrics/list/{metricsType}") + @ApiOperation("Get metrics data for list") + public BaseVO getMetricsDataForList( + @PathVariable("serverId") Integer serverId, + @PathVariable("metricsType") Integer metricsType, + HttpServletRequest request) + throws BaseException { + check(request, serverId); + MetricsDataForListVO metricsDataForListVO = + metricsService.getMetricsDataForList(serverId, metricsType); + return BaseVO.success("Get metrics data for list successfully", metricsDataForListVO); + } + + @GetMapping("/servers/{serverId}/metrics/list/query/{mode}") + @ApiOperation("Get query metrics data for list") + public BaseVO getQueryMetricsDataForList( + @PathVariable("serverId") Integer serverId, @PathVariable("mode") Integer mode) + throws BaseException { + QueryDataForListVO queryDataForListVO = new QueryDataForListVO(); + queryDataForListVO.setMode(mode); + queryDataForListVO.setServerId(serverId); + + if (mode == 1) { + List queryMetricsVOs = iotDBService.getTopQueryMetricsData(); + queryDataForListVO.setQueryMetricsVOs(queryMetricsVOs); + + } else if (mode == 0) { + List queryMetricsVOs = iotDBService.getSlowQueryMetricsData(); + queryDataForListVO.setQueryMetricsVOs(queryMetricsVOs); + } + return BaseVO.success("Get query metrics data for list successfully", queryDataForListVO); + } + + private void check(HttpServletRequest request, Integer serverId) throws BaseException { + Integer userId = AuthenticationUtils.getUserId(request); + connectionService.check(serverId, userId); + } +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java b/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java new file mode 100644 index 00000000..66f9ea37 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java @@ -0,0 +1,13 @@ +package org.apache.iotdb.admin.mapper; + +import org.apache.iotdb.admin.model.entity.ViewMode; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Component; + +/** + * @author Erickin + * @create 2022-04-22-上午 10:32 + */ +@Component +public interface ViewModeMapper extends BaseMapper {} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java new file mode 100644 index 00000000..b33cce15 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java @@ -0,0 +1,15 @@ +package org.apache.iotdb.admin.model.dto; + +import lombok.Data; +import org.apache.iotdb.admin.model.vo.DataModelVO; + +import java.io.Serializable; +import java.util.List; + +@Data +public class DataModelDetailDTO implements Serializable { + private List dataModelVOList; + private Integer pageNum; + private Integer pageSize; + private Integer total; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java new file mode 100644 index 00000000..7f3210be --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java @@ -0,0 +1,19 @@ +package org.apache.iotdb.admin.model.dto; + +import org.apache.iotdb.admin.model.vo.QueryDataStrVO; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-25-下午 5:12 + */ +@Data +public class QueryInfoDTO { + private Long latestRunningTime; + private Integer totalCount; + private Integer totalPage; + List filteredQueryDataStrVOSList; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java b/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java new file mode 100644 index 00000000..56c9ae6e --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java @@ -0,0 +1,30 @@ +package org.apache.iotdb.admin.model.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Null; +import javax.validation.constraints.Pattern; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-22-上午 10:35 + */ +@Data +@TableName("view_mode") +public class ViewMode implements Serializable { + private static final long serialVersionUID = 1L; + + @Null + @TableId(type = IdType.AUTO) + private Integer id; + + @NotBlank + @Pattern(regexp = "^[^ ]+$", message = "The account name cannot contain spaces") + private String name; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java b/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java new file mode 100644 index 00000000..2be1e095 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java @@ -0,0 +1,18 @@ +package org.apache.iotdb.admin.model.metricsDo; + +import org.apache.iotdb.admin.model.vo.QueryDataVO; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-上午 9:28 + */ +@Data +public class QueryDataDo { + private List QueryDataVOs; + private Long latestTimeStamp; + private Integer count; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java index 2763728d..60f9a600 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java @@ -47,6 +47,16 @@ public class DataModelVO implements Serializable { private List children; + private Integer showNum; + + private Integer pageNum; + + private Integer pageSize; + + private Integer total; + + private Integer totalSonNodeCount; + public DataModelVO(String name) { this.name = name; this.isGroup = false; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java new file mode 100644 index 00000000..62e3cb2a --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java @@ -0,0 +1,16 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GroupInfo implements Serializable { + private String groupName; + private Integer deviceCount; + private String description; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfoVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfoVO.java index 512deb7b..87f48234 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfoVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfoVO.java @@ -24,12 +24,12 @@ import lombok.NoArgsConstructor; import java.io.Serializable; +import java.util.List; @Data @NoArgsConstructor @AllArgsConstructor public class GroupInfoVO implements Serializable { - private String groupName; - private Integer deviceCount; - private String description; + private Integer groupCount; + private List groupInfoList; } diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java new file mode 100644 index 00000000..36615556 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java @@ -0,0 +1,14 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-26-下午 5:26 + */ +@Data +public class JVMMetricsListDataVO extends MetricsListDataVO implements Serializable { + private String metricType; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java new file mode 100644 index 00000000..851c8337 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java @@ -0,0 +1,15 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-25-上午 10:00 + */ +@Data +public class MetircsQueryClassificationVO { + private Integer serverId; + private List classificationList; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java new file mode 100644 index 00000000..9bfa81f5 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java @@ -0,0 +1,23 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-上午 10:15 + */ +@Data +public class MetricsChartDataVO implements Serializable { + private List timeList; + private List metricnameList; + private List unitList; + private HashMap> dataList; +} + +// List timeList; +// List metricnameList; +// HashMap dataList; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java new file mode 100644 index 00000000..8045fdb4 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java @@ -0,0 +1,15 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-25-上午 9:12 + */ +@Data +public class MetricsConnectionVO implements Serializable { + Integer id; + String name; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java new file mode 100644 index 00000000..82f6337f --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java @@ -0,0 +1,20 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +/** + * @author Erickin + * @create 2022-04-25-上午 9:38 + */ +@Data +public class MetricsDataCountVO { + private Integer serverId; + private Boolean status; + private String url; + private Integer port; + private Integer storageGroupCount; + private Integer deviceCount; + private Integer monitorCount; + private Integer dataCount; + private String version; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java new file mode 100644 index 00000000..08135e3d --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java @@ -0,0 +1,16 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-26-上午 10:12 + */ +@Data +public class MetricsDataForDiagramVO implements Serializable { + private Integer serverId; + private Integer metricId; + private MetricsChartDataVO chartData; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java new file mode 100644 index 00000000..269cde1c --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java @@ -0,0 +1,16 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 8:12 + */ +@Data +public class MetricsDataForListVO { + private Integer serverId; + private Integer metricsType; + private List listInfo; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java new file mode 100644 index 00000000..7bde7cad --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java @@ -0,0 +1,17 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-26-下午 5:24 + */ +@Data +public class MetricsListDataVO implements Serializable { + private String name; + private String latestScratchTime; + private String latestResult; + private Integer detailAvailable; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java new file mode 100644 index 00000000..17993c00 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java @@ -0,0 +1,14 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +/** + * @author Erickin + * @create 2022-04-25-上午 10:02 + */ +@Data +public class QueryClassificationVO { + private Integer id; + private String name; + private Integer flag; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java new file mode 100644 index 00000000..b14e3c47 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java @@ -0,0 +1,15 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-25-下午 3:56 + */ +@Data +public class QueryData1VO extends QueryDataVO implements Serializable { + private Integer precompiledTime; + private Integer optimizedTime; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java new file mode 100644 index 00000000..b200a0d2 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java @@ -0,0 +1,16 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 9:22 + */ +@Data +public class QueryDataForListVO { + private Integer serverId; + private Integer mode; + private List queryMetricsVOs; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java new file mode 100644 index 00000000..5aecf441 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java @@ -0,0 +1,21 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-28-下午 10:02 + */ +@Data +public class QueryDataStrVO implements Serializable { + private Integer id; + private String statement; + private String runningTime; + private Boolean isSlowQuery; + private Integer totalTime; + private Integer analysisTime; + private Integer executionTime; + private Integer executionResult; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java new file mode 100644 index 00000000..a14537ab --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java @@ -0,0 +1,15 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-29-下午 2:10 + */ +@Data +public class QueryDataStrVO1 extends QueryDataStrVO implements Serializable { + private Integer precompiledTime; + private Integer optimizedTime; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java new file mode 100644 index 00000000..081be812 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java @@ -0,0 +1,21 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author Erickin + * @create 2022-04-25-下午 8:36 + */ +@Data +public class QueryDataVO implements Serializable { + private Integer id; + private String statement; + private Long runningTime; + private Boolean isSlowQuery; + private Integer totalTime; + private Integer analysisTime; + private Integer executionTime; + private Integer executionResult; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java new file mode 100644 index 00000000..e2b35293 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java @@ -0,0 +1,19 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-25-下午 5:13 + */ +@Data +public class QueryInfoVO { + private Integer queryClassificationId; + private String latestRunningTime; + private Integer totalCount; + private Integer totalPage; + private Integer serverId; + private List filteredQueryDataStrVOSList; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java new file mode 100644 index 00000000..cdf3e12b --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java @@ -0,0 +1,14 @@ +package org.apache.iotdb.admin.model.vo; + +import lombok.Data; + +/** + * @author Erickin + * @create 2022-04-26-下午 9:20 + */ +@Data +public class QueryMetricsVO { + private String SQLStatement; + private String runningTime; + private Integer executionTime; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java index 0b050d73..2a97117a 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java @@ -62,6 +62,9 @@ CountDTO getMeasurementsByDevice( void setIotDBRole(Connection connection, IotDBRole iotDBRole) throws BaseException; + DataModelVO getDataModelDetail( + Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException; + UserRolesVO getRolesOfUser(Connection connection, String userName) throws BaseException; void userGrant(Connection connection, String userName, UserGrantDTO userGrantDTO) diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java new file mode 100644 index 00000000..1180f23f --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java @@ -0,0 +1,23 @@ +package org.apache.iotdb.admin.service; + +import org.apache.iotdb.admin.common.exception.BaseException; +import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.vo.MetricsListDataVO; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 4:07 + */ +public interface MetricsResultService { + List getJVMMetricsDataList(Connection connection) throws BaseException; + + List getCPUMetricsDataList(Connection connection) throws BaseException; + + List getMemMetricsDataList(Connection connection) throws BaseException; + + List getDiskMetricsDataList(Connection connection) throws BaseException; + + List getWriteMetricsDataList(Connection connection) throws BaseException; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java new file mode 100644 index 00000000..50f86632 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java @@ -0,0 +1,41 @@ +package org.apache.iotdb.admin.service; + +import org.apache.iotdb.admin.common.exception.BaseException; +import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.vo.*; + +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 4:07 + */ +public interface MetricsService { + List getJVMMetricsDataList(Connection connection) throws BaseException; + + List getCPUMetricsDataList(Connection connection) throws BaseException; + + List getMemMetricsDataList(Connection connection) throws BaseException; + + List getDiskMetricsDataList(Connection connection) throws BaseException; + + List getWriteMetricsDataList(Connection connection) throws BaseException; + + MetircsQueryClassificationVO getMetircsQueryClassification(Integer serverId); + + QueryInfoVO getQueryInfo( + Integer serverId, + Integer queryClassificationId, + Integer pageSize, + Integer pageNum, + String filterString, + String startTimeStr, + String endTimeStr, + Integer executionResult) + throws BaseException; + + MetricsDataCountVO getMetricsDataCount(Integer serverId) throws BaseException; + + MetricsDataForListVO getMetricsDataForList(Integer serverId, Integer metricsType) + throws BaseException; +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java index e904462f..43188254 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java @@ -765,6 +765,66 @@ public void setIotDBRole(Connection connection, IotDBRole iotDBRole) throws Base } } + @Override + public DataModelVO getDataModelDetail( + Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException { + SessionPool sessionPool = null; + try { + sessionPool = getSessionPool(connection); + DataModelVO root = new DataModelVO(path); + setNodeInfo(root, sessionPool, path); + List childrenDataModel = null; + DataModelDetailDTO childrenDataModelDetail = + getChildrenDataModelDetail(root, path, sessionPool, pageSize, pageNum); + childrenDataModel = + childrenDataModelDetail == null ? null : childrenDataModelDetail.getDataModelVOList(); + if (childrenDataModelDetail != null) { + root.setPageNum(childrenDataModelDetail.getPageNum()); + root.setPageSize(childrenDataModelDetail.getPageSize()); + root.setTotal(childrenDataModelDetail.getTotal()); + } + root.setChildren(childrenDataModel); + root.setTotalSonNodeCount( + getChildrenNode(path, sessionPool) == null + ? 0 + : getChildrenNode(path, sessionPool).size()); + root.setGroupCount(path.equals("root") ? getGroupCount(sessionPool) : null); + root.setPath(path); + return root; + } finally { + closeSessionPool(sessionPool); + } + } + + private DataModelDetailDTO getChildrenDataModelDetail( + DataModelVO root, String path, SessionPool sessionPool, Integer pageSize, Integer pageNum) + throws BaseException { + Set childrenNode = getChildrenNode(path, sessionPool); + if (childrenNode == null) { + return null; + } + List childrenlist = new ArrayList<>(); + List childrenNodeList = new ArrayList<>(childrenNode); + List childrenNodeSubList = new ArrayList<>(); + int size = childrenNode.size(); + int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize; + int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize; + if (size > pageStart) { + childrenNodeSubList = childrenNodeList.subList(pageStart, pageEnd); + } + for (String child : childrenNodeSubList) { + DataModelVO childNode = new DataModelVO(child); + setNodeInfo(childNode, sessionPool, path + "." + child); + childrenlist.add(childNode); + } + DataModelDetailDTO dataModelDetailDTO = new DataModelDetailDTO(); + dataModelDetailDTO.setDataModelVOList(childrenlist); + dataModelDetailDTO.setPageNum(pageNum); + dataModelDetailDTO.setPageSize(pageSize); + dataModelDetailDTO.setTotal(size); + return dataModelDetailDTO; + } + @Override public UserRolesVO getRolesOfUser(Connection connection, String userName) throws BaseException { SessionPool sessionPool = getSessionPool(connection); diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java new file mode 100644 index 00000000..de26ba5d --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java @@ -0,0 +1,283 @@ +package org.apache.iotdb.admin.service.impl; + +import org.apache.iotdb.admin.common.exception.BaseException; +import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.vo.JVMMetricsListDataVO; +import org.apache.iotdb.admin.model.vo.MetricsListDataVO; +import org.apache.iotdb.admin.service.MetricsResultService; + +import org.springframework.stereotype.Service; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 4:41 + */ +@Service +public class MetricsResultServiceImpl implements MetricsResultService { + + public JVMMetricsListDataVO getCurrentThreadsCount(long currentTimeMillis) throws BaseException { + String name = "JVM当前线程数"; + String metricType = "线程"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 1; + String sql = + "select * from " + + "root._metric.\"127.0.0.1:8086\".\"jvm.threads.daemon\"," + + " root._metric.\"127.0.0.1:8086\".\"jvm.threads.live\" " + + "order by time desc limit 1"; + try { + } catch (Exception e) { + e.printStackTrace(); + } + String latestResult = "[Just Test] 前台:20个,后台:39个,线程总数:59个"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getYGCHappendCountAndCostTime(long currentTimeMillis) + throws BaseException { + // TODO 暂时写死 + String name = "YGC发生次数及总耗时"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 2; + String latestResult = "[Just Test] 20次 200s"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getUsedBufferSize(long currentTimeMillis) throws BaseException { + String name = "已经使用的缓冲区大小"; + String metricType = "内存"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 3; + String latestResult = "[Just Test] 20G"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMTotalUnloadClass(long currentTimeMillis) throws BaseException { + String name = "JVM累计卸载的class数量"; + String metricType = "Classes"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 4; + String latestResult = "[Just Test] 30次"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public MetricsListDataVO getCPUUsed(long currentTimeMillis) throws BaseException { + String name = "CPU使用率"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 1; + String latestResult = "[Just Test] 50%"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getCPUCores(long currentTimeMillis) throws BaseException { + String name = "CPU核数"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 0; + String latestResult = "[Just Test] 4核"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getIotDBProcessMemUsed(long currentTimeMillis) throws BaseException { + String name = "IoTDB进程内存占用比例"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 1; + String latestResult = "[Just Test] 70%"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getTotalMem(long currentTimeMillis) throws BaseException { + String name = "物理内存大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 0; + String latestResult = "[Just Test] 4G"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskAvaliable(long currentTimeMillis) throws BaseException { + String name = "磁盘剩余"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 1; + String latestResult = "[Just Test] 2G"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskTotalSize(long currentTimeMillis) throws BaseException { + String name = "磁盘总大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 0; + String latestResult = "[Just Test] 4G"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO writeSucceedProportion(long currentTimeMillis) throws BaseException { + String name = "写入成功率"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 0; + String latestResult = "[Just Test] 80%"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO writeLatency(long currentTimeMillis) throws BaseException { + String name = "写入延迟(最近一分钟)"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String latestScratchTime = simpleDateFormat.format(currentTimeMillis); + Integer detailAvailable = 1; + String latestResult = "[Just Test] 90%"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + @Override + public List getJVMMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + long currentTimeMillis = System.currentTimeMillis(); + JVMMetricsListDataVO currentThreadsCount = getCurrentThreadsCount(currentTimeMillis); + JVMMetricsListDataVO ygcHappendCountAndCostTime = + getYGCHappendCountAndCostTime(currentTimeMillis); + JVMMetricsListDataVO usedBufferSize = getUsedBufferSize(currentTimeMillis); + JVMMetricsListDataVO jvmTotalUnloadClass = getJVMTotalUnloadClass(currentTimeMillis); + // TODO 把所有指标都加进来 + list.add(currentThreadsCount); + list.add(ygcHappendCountAndCostTime); + list.add(usedBufferSize); + list.add(jvmTotalUnloadClass); + return list; + } + + @Override + public List getCPUMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + long currentTimeMillis = System.currentTimeMillis(); + MetricsListDataVO cpuUsed = getCPUUsed(currentTimeMillis); + MetricsListDataVO cpuCores = getCPUCores(currentTimeMillis); + list.add(cpuUsed); + list.add(cpuCores); + return list; + } + + @Override + public List getMemMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + long currentTimeMillis = System.currentTimeMillis(); + MetricsListDataVO iotDBProcessMemUsed = getIotDBProcessMemUsed(currentTimeMillis); + MetricsListDataVO totalMem = getTotalMem(currentTimeMillis); + list.add(iotDBProcessMemUsed); + list.add(totalMem); + return list; + } + + @Override + public List getDiskMetricsDataList(Connection connection) + throws BaseException { + List list = new ArrayList<>(); + long currentTimeMillis = System.currentTimeMillis(); + MetricsListDataVO metricsListDataVO = getDiskAvaliable(currentTimeMillis); + MetricsListDataVO diskTotalSize = getDiskTotalSize(currentTimeMillis); + list.add(metricsListDataVO); + list.add(diskTotalSize); + return list; + } + + @Override + public List getWriteMetricsDataList(Connection connection) + throws BaseException { + List list = new ArrayList<>(); + long currentTimeMillis = System.currentTimeMillis(); + MetricsListDataVO writeSucceedProportion = writeSucceedProportion(currentTimeMillis); + MetricsListDataVO writeLatency = writeLatency(currentTimeMillis); + list.add(writeSucceedProportion); + list.add(writeLatency); + return list; + } +} diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java new file mode 100644 index 00000000..5dd025d9 --- /dev/null +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java @@ -0,0 +1,1746 @@ +package org.apache.iotdb.admin.service.impl; + +import org.apache.iotdb.admin.common.exception.BaseException; +import org.apache.iotdb.admin.common.exception.ErrorCode; +import org.apache.iotdb.admin.model.dto.QueryInfoDTO; +import org.apache.iotdb.admin.model.entity.Connection; +import org.apache.iotdb.admin.model.vo.*; +import org.apache.iotdb.admin.service.ConnectionService; +import org.apache.iotdb.admin.service.IotDBService; +import org.apache.iotdb.admin.service.MetricsService; +import org.apache.iotdb.rpc.IoTDBConnectionException; +import org.apache.iotdb.rpc.StatementExecutionException; +import org.apache.iotdb.session.pool.SessionDataSetWrapper; +import org.apache.iotdb.session.pool.SessionPool; +import org.apache.iotdb.tsfile.read.common.RowRecord; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.*; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Erickin + * @create 2022-04-26-下午 4:41 + */ +@Service +public class MetricsServiceImpl implements MetricsService { + + @Autowired ConnectionService connectionService; + @Autowired IotDBService iotDBService; + + private static final Logger logger = LoggerFactory.getLogger(IotDBServiceImpl.class); + + 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 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; + } + + public JVMMetricsListDataVO getCurrentDaemonThreadsCount(Connection connection) + throws BaseException { + String name = "当前daemon线程数"; + String metricType = "线程"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + 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\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + s1 = s1.substring(0, s1.indexOf('.')); + int daemonThreadCount = Integer.parseInt(s1); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = daemonThreadCount + "个"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getPeakThreadsCount(Connection connection) throws BaseException { + String name = "峰值线程数"; + String metricType = "线程"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.peak\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + s1 = s1.substring(0, s1.indexOf('.')); + int daemonThreadCount = Integer.parseInt(s1); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = daemonThreadCount + "个"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getVariableThreadsCount(Connection connection) throws BaseException { + String name = "处于各种状态的线程数"; + String metricType = "线程"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=new\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=waiting\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=runnable\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=blocked\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=timed-waiting\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.threads.states\".\"state=terminated\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + String s2 = values.get(2); + String s3 = values.get(3); + String s4 = values.get(4); + String s5 = values.get(5); + String s6 = values.get(6); + s1 = s1.substring(0, s1.indexOf('.')); + s2 = s2.substring(0, s2.indexOf('.')); + s3 = s3.substring(0, s3.indexOf('.')); + s4 = s4.substring(0, s4.indexOf('.')); + s5 = s5.substring(0, s5.indexOf('.')); + s6 = s6.substring(0, s6.indexOf('.')); + int newThreadCount = Integer.parseInt(s1); + int waitingThreadCount = Integer.parseInt(s2); + int runnableThreadCount = Integer.parseInt(s3); + int blockedThreadCount = Integer.parseInt(s4); + int timedWaitingThreadCount = Integer.parseInt(s5); + int terminatedThreadCount = Integer.parseInt(s6); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = + "新建(" + + newThreadCount + + ")、" + + "可运行(" + + waitingThreadCount + + ")、" + + "运行(" + + runnableThreadCount + + ")、" + + "阻塞(" + + blockedThreadCount + + ")、" + + "休眠(" + + timedWaitingThreadCount + + ")、" + + "死亡(" + + terminatedThreadCount + + ")"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + 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 countValues = executeQueryOneLine(sessionPool, countSQL); + List 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; + } + + public JVMMetricsListDataVO getYGCMaxCostTimeAndReason(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 timeSQL = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_max\".\"action=end of minor GC\".\"cause=Metadata GC Threshold\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_max\".\"action=end of minor GC\".\"cause=Allocation Failure\" " + + "order by time desc limit 1"; + List timeValues = executeQueryOneLine(sessionPool, timeSQL); + long lastestTimeStamp = Long.parseLong(timeValues.get(0)); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + Integer detailAvailable = 2; + String latestResult = + Double.parseDouble(timeValues.get(1)) / 1000 + + "s(Metadata GC Threshold)、" + + Double.parseDouble(timeValues.get(2)) / 1000 + + "s(Allocation Failure)"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + 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 countValues = executeQueryOneLine(sessionPool, countSQL); + List 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; + } + + public JVMMetricsListDataVO getFGCMaxCostTimeAndReason(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 timeSQL = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.pause_max\".\"action=end of major GC\".\"cause=Metadata GC Threshold\" " + + + // "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_max\".\"action=end of + // major GC\".\"cause=Allocation Failure\", " + + // "root._metric.\"127.0.0.1:8086\".\"jvm.gc.pause_max\".\"action=end of + // major GC\".\"cause=Ergonomics\" " + + "order by time desc limit 1"; + List timeValues = executeQueryOneLine(sessionPool, timeSQL); + long lastestTimeStamp = Long.parseLong(timeValues.get(0)); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + Integer detailAvailable = 2; + // TODO: IOTDB BUG 等待修复 + String s1 = timeValues.get(1).equals("null") ? "0.0" : timeValues.get(1); + // String s2 = timeValues.get(2).equals("null")? "0.0" : timeValues.get(2); + // String s3 = timeValues.get(3).equals("null")? "0.0" : timeValues.get(3); + // String latestResult = timeValues.get(1)+"s(Metadata GC + // Threshold)、"+timeValues.get(2)+"s(Allocation Failure)、"+timeValues.get(3)+"s(Ergonomics)"; + String latestResult = Double.parseDouble(timeValues.get(1)) / 1000 + "s(Metadata GC Threshold)"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getGCCPUoverhead(Connection connection) throws BaseException { + String name = "GC消耗CPU的比例"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.overhead\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + double percent = Double.parseDouble(values.get(1)); + BigDecimal b = new BigDecimal(percent); + double percent1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = percent1 + "%"; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getGCPromoted(Connection connection) throws BaseException { + String name = "从GC之前到GC之后老年代内存池大小正增长的累计"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.memory.promoted\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = getNetFileSizeDescription((long) (Double.parseDouble(values.get(1)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getMajorMemoryMaxValueEver(Connection connection) + throws BaseException { + String name = "老年代内存的历史最大值"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.max.data.size\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = getNetFileSizeDescription((long) (Double.parseDouble(values.get(1)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getMajorMemorySizeAfterGC(Connection connection) + throws BaseException { + String name = "GC之后老年代内存的大小"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.live.data.size\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = getNetFileSizeDescription((long) (Double.parseDouble(values.get(1)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getMinorMemorySizeAddedBetweentwoGC(Connection connection) + throws BaseException { + String name = "在一个GC之后到下一个GC之前年轻代增加的内存"; + String metricType = "垃圾回收"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.gc.memory.allocated\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = getNetFileSizeDescription((long) (Double.parseDouble(values.get(1)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getBufferUsed(Connection connection) throws BaseException { + String name = "已经使用的缓冲区大小"; + String metricType = "内存"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=mapped\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.memory.used\".\"id=direct\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = + getNetFileSizeDescription( + (long) (Double.parseDouble(values.get(1)) + Double.parseDouble(values.get(2)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getMaxBuffer(Connection connection) throws BaseException { + String name = "最大缓冲区大小"; + String metricType = "内存"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.total.capacity\".\"id=mapped\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.total.capacity\".\"id=direct\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = + getNetFileSizeDescription( + (long) (Double.parseDouble(values.get(1)) + Double.parseDouble(values.get(2)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getBufferCount(Connection connection) throws BaseException { + String name = "当前缓冲区数量"; + String metricType = "内存"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.count\".\"id=mapped\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.buffer.count\".\"id=direct\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + String s2 = values.get(2); + s1 = s1.substring(0, s1.indexOf('.')); + s2 = s2.substring(0, s2.indexOf('.')); + String latestResult = (Integer.parseInt(s1) + Integer.parseInt(s2)) + "个"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMCommittedMemorySize(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 = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=nonheap\".\"id=Compressed Class Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=nonheap\".\"id=Code Cache\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=nonheap\".\"id=Metaspace\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=heap\".\"id=PS Old Gen\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=heap\".\"id=PS Eden Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.committed\".\"area=heap\".\"id=PS Survivor Space\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = + getNetFileSizeDescription( + (long) + (Double.parseDouble(values.get(1)) + + Double.parseDouble(values.get(2)) + + Double.parseDouble(values.get(3)) + + Double.parseDouble(values.get(4)) + + Double.parseDouble(values.get(5)) + + Double.parseDouble(values.get(6)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMMemoryMaxSize(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 = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Compressed Class Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Code Cache\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=nonheap\".\"id=Metaspace\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Old Gen\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Eden Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.max\".\"area=heap\".\"id=PS Survivor Space\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = + getNetFileSizeDescription( + (long) + (Double.parseDouble(values.get(1)) + + Double.parseDouble(values.get(2)) + + Double.parseDouble(values.get(3)) + + Double.parseDouble(values.get(4)) + + Double.parseDouble(values.get(5)) + + Double.parseDouble(values.get(6)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMMemoryUsedSize(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 = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Compressed Class Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Code Cache\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=nonheap\".\"id=Metaspace\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Old Gen\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Eden Space\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.memory.used\".\"area=heap\".\"id=PS Survivor Space\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = + getNetFileSizeDescription( + (long) + (Double.parseDouble(values.get(1)) + + Double.parseDouble(values.get(2)) + + Double.parseDouble(values.get(3)) + + Double.parseDouble(values.get(4)) + + Double.parseDouble(values.get(5)) + + Double.parseDouble(values.get(6)))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = count; + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMUnloadedClassesTotal(Connection connection) + throws BaseException { + String name = "JVM累计卸载的Class数量"; + String metricType = "Classes"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.classes.unloaded\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + s1 = s1.substring(0, s1.indexOf('.')); + String latestResult = Integer.parseInt(s1) + "个"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMloadedClassesTotal(Connection connection) throws BaseException { + String name = "JVM累计加载的Class数量"; + String metricType = "Classes"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.classes.loaded\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + s1 = s1.substring(0, s1.indexOf('.')); + String latestResult = Integer.parseInt(s1) + "个"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public JVMMetricsListDataVO getJVMCompilationTime(Connection connection) throws BaseException { + String name = "JVM耗费在编译上的时间"; + String metricType = "Classes"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"jvm.compilation.time\".\"compiler=HotSpot 64-Bit Tiered Compilers\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = values.get(1) + "s"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO(); + jvmMetricsListDataVO.setMetricType(metricType); + jvmMetricsListDataVO.setDetailAvailable(detailAvailable); + jvmMetricsListDataVO.setLatestResult(latestResult); + jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime); + jvmMetricsListDataVO.setName(name); + return jvmMetricsListDataVO; + } + + public MetricsListDataVO getCPUUsed(Connection connection) throws BaseException { + String name = "CPU使用率"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_cpu_load\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = values.get(1) + "%"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getCPUCores(Connection connection) throws BaseException { + String name = "CPU核数"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_cpu_cores\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String s1 = values.get(1); + s1 = s1.substring(0, s1.indexOf('.')); + String latestResult = s1 + "核"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getCPUTime(Connection connection) throws BaseException { + String name = "CPU Time"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"process_cpu_time\".\"name=process\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String timeStr = values.get(1); + long count = Long.parseLong(timeStr.substring(timeStr.indexOf("E") + 1)); + double time = Double.parseDouble(timeStr.substring(0, timeStr.indexOf("E"))); + while (count > 0) { + time *= 10; + count--; + } + String latestResult = (float) (time / 1000000000) + "s"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getTotalMem(Connection connection) throws BaseException { + String name = "物理内存大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + String str = connection.getHost(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_total_physical_memory_size\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = getNetFileSizeDescription((long) Double.parseDouble(values.get(1))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getProcessRatio(Connection connection) throws BaseException { + String name = "IoTDB进程内存占用比例"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"process_mem_ratio\".\"name=process\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + String latestResult = values.get(1) + "%"; + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskTotalSize(Connection connection) throws BaseException { + String name = "磁盘总大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_disk_total_space\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = getNetFileSizeDescription((long) Double.parseDouble(values.get(1))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskLoadSize(Connection connection) throws BaseException { + // TODO: 假数据,等待iotdb增加该指标 + String name = "磁盘挂载"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_disk_total_space\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + // String latestResult = getNetFileSizeDescription((long)Double.parseDouble(values.get(1))); + String latestResult = "【假数据:指标暂缺】2G"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskAvailableSize(Connection connection) throws BaseException { + String name = "磁盘剩余"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_disk_free_space\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String latestResult = getNetFileSizeDescription((long) Double.parseDouble(values.get(1))); + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getDiskIO(Connection connection) throws BaseException { + String name = "磁盘IO吞吐"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"sys_disk_free_space\".\"name=system\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + // String latestResult = getNetFileSizeDescription((long)Double.parseDouble(values.get(1))); + String latestResult = "【假数据:指标暂缺】136K/s"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getWalFileCountAndSize(Connection connection) throws BaseException { + String name = "wal日志文件数量及大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=wal\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=wal\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "数量:" + count + ";" + "大小:" + size; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getSeqTSFileCountAndSize(Connection connection) throws BaseException { + String name = "顺序TsFile文件数量及大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=seq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=seq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "数量:" + count + ";" + "大小:" + size; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getUnSeqTSFileCountAndSize(Connection connection) throws BaseException { + String name = "乱序TsFile文件数量及大小"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "数量:" + count + ";" + "大小:" + size; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getWriteDelay(Connection connection) throws BaseException { + String name = "写入延迟(最近一分钟)"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "【假数据:指标暂缺】" + "90" + "%"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getWriteSucceedCount(Connection connection) throws BaseException { + String name = "查询成功次数(最近1分钟)"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "【假数据:指标暂缺】" + "100" + "次"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getWriteFailedCount(Connection connection) throws BaseException { + String name = "查询失败次数(最近1分钟)"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "【假数据:指标暂缺】" + "20" + "次"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + public MetricsListDataVO getWriteSucceedRatio(Connection connection) throws BaseException { + String name = "查询成功率"; + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Integer detailAvailable = 0; + int port = connection.getPort(); + // TODO bug 修复后删除 + if (port == 6668) { + port = 8086; + } + String sql = + "select * from " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_count\".\"name=unseq\", " + + "root._metric.\"127.0.0.1:" + + port + + "\".\"file_size\".\"name=unseq\" " + + "order by time desc limit 1"; + SessionPool sessionPool = getSessionPool(connection); + List values = executeQueryOneLine(sessionPool, sql); + long lastestTimeStamp = Long.parseLong(values.get(0)); + String count = values.get(1); + count = count.substring(0, count.indexOf('.')); + String size = getNetFileSizeDescription((long) Double.parseDouble(values.get(2))); + String latestResult = "【假数据:指标暂缺】" + "80" + "%"; + String latestScratchTime = simpleDateFormat.format(lastestTimeStamp); + MetricsListDataVO metricsListDataVO = new MetricsListDataVO(); + metricsListDataVO.setDetailAvailable(detailAvailable); + metricsListDataVO.setLatestResult(latestResult); + metricsListDataVO.setLatestScratchTime(latestScratchTime); + metricsListDataVO.setName(name); + return metricsListDataVO; + } + + @Override + public List getJVMMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + list.add(getCurrentThreadsCount(connection)); + list.add(getCurrentDaemonThreadsCount(connection)); + list.add(getPeakThreadsCount(connection)); + list.add(getVariableThreadsCount(connection)); + list.add(getYGCHappendCountAndCostTime(connection)); + list.add(getYGCMaxCostTimeAndReason(connection)); + list.add(getFGCHappendCountAndCostTime(connection)); + list.add(getFGCMaxCostTimeAndReason(connection)); + list.add(getGCCPUoverhead(connection)); + list.add(getGCPromoted(connection)); + list.add(getMajorMemoryMaxValueEver(connection)); + list.add(getMajorMemorySizeAfterGC(connection)); + list.add(getMinorMemorySizeAddedBetweentwoGC(connection)); + list.add(getBufferUsed(connection)); + list.add(getMaxBuffer(connection)); + list.add(getBufferCount(connection)); + list.add(getJVMCommittedMemorySize(connection)); + list.add(getJVMMemoryMaxSize(connection)); + list.add(getJVMMemoryUsedSize(connection)); + list.add(getJVMUnloadedClassesTotal(connection)); + list.add(getJVMloadedClassesTotal(connection)); + list.add(getJVMCompilationTime(connection)); + return list; + } + + @Override + public List getCPUMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + list.add(getCPUCores(connection)); + list.add(getCPUUsed(connection)); + list.add(getCPUTime(connection)); + return list; + } + + @Override + public List getMemMetricsDataList(Connection connection) throws BaseException { + List list = new ArrayList<>(); + list.add(getTotalMem(connection)); + list.add(getProcessRatio(connection)); + return list; + } + + @Override + public List getDiskMetricsDataList(Connection connection) + throws BaseException { + List list = new ArrayList<>(); + list.add(getDiskTotalSize(connection)); + list.add(getDiskLoadSize(connection)); + list.add(getDiskAvailableSize(connection)); + list.add(getDiskIO(connection)); + list.add(getWalFileCountAndSize(connection)); + list.add(getSeqTSFileCountAndSize(connection)); + list.add(getUnSeqTSFileCountAndSize(connection)); + return list; + } + + @Override + public List getWriteMetricsDataList(Connection connection) + throws BaseException { + List list = new ArrayList<>(); + list.add(getWriteDelay(connection)); + list.add(getWriteSucceedCount(connection)); + list.add(getWriteFailedCount(connection)); + list.add(getWriteFailedCount(connection)); + list.add(getWriteSucceedRatio(connection)); + return list; + } + + @Override + public MetircsQueryClassificationVO getMetircsQueryClassification(Integer serverId) { + // TODO:等待清华提供查询分类的接口 + List fakeData = new ArrayList<>(); + for (int i = 0; i < 6; i++) { + QueryClassificationVO queryClassificationVO = new QueryClassificationVO(); + queryClassificationVO.setId(i + 1); + queryClassificationVO.setName("查询分类" + (i + 1)); + queryClassificationVO.setFlag(i % 2 == 0 ? 1 : 0); + fakeData.add(queryClassificationVO); + } + MetircsQueryClassificationVO metircsQueryClassificationVO = new MetircsQueryClassificationVO(); + metircsQueryClassificationVO.setServerId(serverId); + metircsQueryClassificationVO.setClassificationList(fakeData); + return metircsQueryClassificationVO; + } + + @Override + public QueryInfoVO getQueryInfo( + Integer serverId, + Integer queryClassificationId, + Integer pageSize, + Integer pageNum, + String filterString, + String startTimeStr, + String endTimeStr, + Integer executionResult) + throws BaseException { + long startTime = Long.parseLong(startTimeStr); + long endTime = Long.parseLong(endTimeStr); + Connection connection = connectionService.getById(serverId); + QueryInfoDTO queryInfoDTO = + iotDBService.getQueryInfoListByQueryClassificationId( + connection, + queryClassificationId, + pageSize, + pageNum, + filterString, + startTime, + endTime, + executionResult); + QueryInfoVO queryInfoVO = new QueryInfoVO(); + queryInfoVO.setQueryClassificationId(queryClassificationId); + String pattern = "yyyy-MM-dd' 'HH:mm:ss.SSS"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + Long latestRunningTime = queryInfoDTO.getLatestRunningTime(); + queryInfoVO.setLatestRunningTime( + latestRunningTime == 0 ? null : simpleDateFormat.format(latestRunningTime)); + BeanUtils.copyProperties(queryInfoDTO, queryInfoVO); + queryInfoVO.setServerId(serverId); + return queryInfoVO; + } + + @Override + public MetricsDataCountVO getMetricsDataCount(Integer serverId) throws BaseException { + Connection connection = connectionService.getById(serverId); + DataCountVO dataCountVO = new DataCountVO(); + MetricsDataCountVO metricsDataCountVO = new MetricsDataCountVO(); + DataCountVO dataCount = new DataCountVO(); + try { + dataCount = iotDBService.getDataCount(connection); + metricsDataCountVO.setStatus(true); + } catch (BaseException e) { + metricsDataCountVO.setStatus(false); + } + metricsDataCountVO.setServerId(serverId); + metricsDataCountVO.setUrl(connection.getHost()); + metricsDataCountVO.setPort(connection.getPort()); + BeanUtils.copyProperties(dataCount, metricsDataCountVO); + metricsDataCountVO.setDataCount(dataCount.getDataCount()); + return metricsDataCountVO; + } + + @Override + public MetricsDataForListVO getMetricsDataForList(Integer serverId, Integer metricsType) + throws BaseException { + Connection connection = connectionService.getById(serverId); + List metricsDataList = null; + // TODO:具体区分和判断等待清华提供方案和策略 + switch (metricsType) { + case 0: + metricsDataList = getJVMMetricsDataList(connection); + break; + case 1: + metricsDataList = getCPUMetricsDataList(connection); + break; + case 2: + metricsDataList = getMemMetricsDataList(connection); + break; + case 3: + metricsDataList = getDiskMetricsDataList(connection); + break; + case 4: + metricsDataList = getWriteMetricsDataList(connection); + break; + } + MetricsDataForListVO metricsDataForListVO = new MetricsDataForListVO(); + metricsDataForListVO.setServerId(serverId); + metricsDataForListVO.setMetricsType(metricsType); + metricsDataForListVO.setListInfo(metricsDataList); + return metricsDataForListVO; + } + + public static SessionPool getSessionPool(Connection connection) throws BaseException { + String host = connection.getHost(); + Integer port = connection.getPort(); + String username = connection.getUsername(); + String password = connection.getPassword(); + SessionPool sessionPool = null; + try { + sessionPool = new SessionPool(host, port, username, password, 3); + } catch (Exception e) { + throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG); + } + return sessionPool; + } + + private List executeQueryOneLine(SessionPool sessionPool, String sql) + throws BaseException { + SessionDataSetWrapper sessionDataSetWrapper = null; + try { + List valueList = new ArrayList<>(); + sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); + if (sessionDataSetWrapper.hasNext()) { + RowRecord rowRecord = sessionDataSetWrapper.next(); + valueList.add(rowRecord.getTimestamp() + ""); + List fields = rowRecord.getFields(); + for (org.apache.iotdb.tsfile.read.common.Field field : fields) { + valueList.add(field.toString()); + } + } + return valueList; + } catch (IoTDBConnectionException e) { + logger.error(e.getMessage()); + throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG); + } catch (StatementExecutionException e) { + logger.error(e.getMessage()); + throw new BaseException(ErrorCode.SQL_EP, ErrorCode.SQL_EP_MSG); + } finally { + closeResultSet(sessionDataSetWrapper); + } + } + + private void closeSessionPool(SessionPool sessionPool) { + if (sessionPool != null) { + sessionPool.close(); + } + } + + private void closeResultSet(SessionDataSetWrapper sessionDataSetWrapper) { + if (sessionDataSetWrapper != null) { + sessionDataSetWrapper.close(); + } + } + + private static String getNetFileSizeDescription(long size) { + StringBuffer bytes = new StringBuffer(); + DecimalFormat format = new DecimalFormat("###.0"); + if (size >= 1024 * 1024 * 1024) { + double i = (size / (1024.0 * 1024.0 * 1024.0)); + bytes.append(format.format(i)).append("GB"); + } else if (size >= 1024 * 1024) { + double i = (size / (1024.0 * 1024.0)); + bytes.append(format.format(i)).append("MB"); + } else if (size >= 1024) { + double i = (size / (1024.0)); + bytes.append(format.format(i)).append("KB"); + } else if (size < 1024) { + if (size <= 0) { + bytes.append("0B"); + } else { + bytes.append((int) size).append("B"); + } + } + return bytes.toString(); + } +} From 893c93408bce2de4663dc4560ba212473fbd681d Mon Sep 17 00:00:00 2001 From: loveher147 Date: Mon, 30 May 2022 15:19:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E5=B1=95=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 解决大数据量场景的卡顿问题。 --- .../admin/controller/IotDBController.java | 62 ++++--- .../admin/model/dto/DataModelDetailDTO.java | 3 +- .../iotdb/admin/model/vo/NodeTreeVO.java | 9 + .../iotdb/admin/service/IotDBService.java | 28 +-- .../admin/service/impl/IotDBServiceImpl.java | 162 +++++++++++++----- 5 files changed, 188 insertions(+), 76 deletions(-) diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java index 89309134..67e42891 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java @@ -98,12 +98,12 @@ public BaseVO getDataModel( @GetMapping("/dataModel/detail") @ApiOperation("Get IoTDB data model in detail") public BaseVO getDataModelDetail( - @PathVariable("serverId") Integer serverId, - @RequestParam(value = "path", required = false, defaultValue = "root") String path, - @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, - @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, - HttpServletRequest request) - throws BaseException { + @PathVariable("serverId") Integer serverId, + @RequestParam(value = "path", required = false, defaultValue = "root") String path, + @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, + HttpServletRequest request) + throws BaseException { check(request, serverId); Connection connection = connectionService.getById(serverId); DataModelVO dataModelVO = iotDBService.getDataModelDetail(connection, path, pageSize, pageNum); @@ -113,11 +113,11 @@ public BaseVO getDataModelDetail( @GetMapping("/storageGroups/info") @ApiOperation("Get information of the storage group list") public BaseVO getAllStorageGroupsInfo( - @PathVariable("serverId") Integer serverId, - @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize, - @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, - HttpServletRequest request) - throws BaseException { + @PathVariable("serverId") Integer serverId, + @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, + HttpServletRequest request) + throws BaseException { check(request, serverId); Connection connection = connectionService.getById(serverId); List groupNames = iotDBService.getAllStorageGroups(connection); @@ -162,8 +162,6 @@ public BaseVO> getAllStorageGroups( String host = connection.getHost(); for (String groupName : groupNames) { StorageGroupVO storageGroupVO = new StorageGroupVO(); - Integer id = groupService.getGroupId(host, groupName); - storageGroupVO.setGroupId(id); storageGroupVO.setGroupName(groupName); storageGroupVOList.add(storageGroupVO); } @@ -193,9 +191,9 @@ public BaseVO saveStorageGroup( Connection connection = connectionService.getById(serverId); Long ttl = groupDTO.getTtl(); String ttlUnit = groupDTO.getTtlUnit(); - checkTtl(ttl, ttlUnit); Integer groupId = groupDTO.getGroupId(); groupDTO.setGroupName(groupName); + List groupNames = iotDBService.getAllStorageGroups(connection); if (groupId == null) { if (!groupNames.contains(groupDTO.getGroupName())) { @@ -206,6 +204,7 @@ public BaseVO saveStorageGroup( groupService.updateStorageGroupInfo(connection, groupDTO); } if (ttl != null && ttlUnit != null) { + checkTtl(ttl, ttlUnit); if (ttl >= 0) { Long times = switchTime(ttlUnit); iotDBService.saveGroupTtl(connection, groupName, ttl * times); @@ -354,12 +353,19 @@ public BaseVO> getDevicesNodeTreeByGroup( public BaseVO getDevicesTreeByGroup( @PathVariable("serverId") Integer serverId, @PathVariable("groupName") String groupName, + @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, HttpServletRequest request) throws BaseException { checkParameter(groupName); check(request, serverId); Connection connection = connectionService.getById(serverId); - NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName); + NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName, pageSize, pageNum); + if (deviceList == null) { + deviceList = new NodeTreeVO(groupName); + } + deviceList.setPageNum(pageNum); + deviceList.setPageSize(pageSize); return BaseVO.success("Get successfully", deviceList); } @@ -461,8 +467,8 @@ public BaseVO getMeasurementsByDeviceName( @PathVariable("serverId") Integer serverId, @PathVariable("groupName") String groupName, @PathVariable("deviceName") String deviceName, - @RequestParam("pageSize") Integer pageSize, - @RequestParam("pageNum") Integer pageNum, + @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, + @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum, @RequestParam(value = "keyword", required = false) String keyword, HttpServletRequest request) throws BaseException { @@ -475,17 +481,26 @@ public BaseVO getMeasurementsByDeviceName( List measurementVOList = new ArrayList<>(); String host = connection.getHost(); if (measurementDTOList != null) { + List timeseriesList = new ArrayList<>(); + for (MeasurementDTO measurementDTO : measurementDTOList) { + timeseriesList.add(measurementDTO.getTimeseries()); + } + List batchNewValue = + iotDBService.getBatchLastMeasurementValue(connection, timeseriesList); + List batchDataCount = + iotDBService.getBatchDataCount(connection, deviceName, timeseriesList); + int index = 0; for (MeasurementDTO measurementDTO : measurementDTOList) { MeasurementVO measurementVO = new MeasurementVO(); BeanUtils.copyProperties(measurementDTO, measurementVO); String description = measurementService.getDescription(host, measurementDTO.getTimeseries()); - String newValue = - iotDBService.getLastMeasurementValue(connection, measurementDTO.getTimeseries()); - Integer dataCount = - iotDBService.getOneDataCount(connection, deviceName, measurementDTO.getTimeseries()); - measurementVO.setDataCount(dataCount); - measurementVO.setNewValue(newValue); + if (batchNewValue.size() != 0) { + measurementVO.setNewValue(batchNewValue.get(index)); + } + if (batchDataCount.size() != 0) { + measurementVO.setDataCount(Integer.parseInt(batchDataCount.get(index))); + } measurementVO.setDescription(description); ObjectMapper mapper = new ObjectMapper(); List> tags = new ArrayList<>(); @@ -519,6 +534,7 @@ public BaseVO getMeasurementsByDeviceName( throw new BaseException(ErrorCode.GET_MSM_FAIL, ErrorCode.GET_MSM_FAIL_MSG); } measurementVOList.add(measurementVO); + index++; } } MeasuremtnInfoVO measuremtnInfoVO = new MeasuremtnInfoVO(); diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java index b33cce15..58463b06 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java @@ -1,8 +1,9 @@ package org.apache.iotdb.admin.model.dto; -import lombok.Data; import org.apache.iotdb.admin.model.vo.DataModelVO; +import lombok.Data; + import java.io.Serializable; import java.util.List; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/NodeTreeVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/NodeTreeVO.java index cfa4accc..46a476b3 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/NodeTreeVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/NodeTreeVO.java @@ -31,10 +31,19 @@ public class NodeTreeVO implements Serializable { private List children; + private Integer pageSize; + + private Integer pageNum; + + private Integer total; + // private List childrenName; + public NodeTreeVO(String name) { this.name = name; } + public NodeTreeVO() {} + public List initChildren() { if (children == null) { children = new ArrayList<>(); diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java index 2a97117a..4c5eff41 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/IotDBService.java @@ -62,9 +62,6 @@ CountDTO getMeasurementsByDevice( void setIotDBRole(Connection connection, IotDBRole iotDBRole) throws BaseException; - DataModelVO getDataModelDetail( - Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException; - UserRolesVO getRolesOfUser(Connection connection, String userName) throws BaseException; void userGrant(Connection connection, String userName, UserGrantDTO userGrantDTO) @@ -122,7 +119,9 @@ Integer getOneDataCount(Connection connection, String deviceName, String measure List getDeviceNodeTree(Connection connection, String groupName) throws BaseException; - NodeTreeVO getDeviceList(Connection connection, String groupName) throws BaseException; + NodeTreeVO getDeviceList( + Connection connection, String groupName, Integer pageSize, Integer pageNum) + throws BaseException; List getDeviceParents(Connection connection, String groupName, String deviceName) throws BaseException; @@ -155,6 +154,8 @@ void upsertDataPrivileges( Connection connection, String userOrRole, String name, PrivilegeInfoDTO privilegeInfoDTO) throws BaseException; + public List getSlowQueryMetricsData(); + RecordVO getRecords( Connection connection, String deviceName, String timeseriesName, String dataType) throws BaseException; @@ -164,9 +165,7 @@ List queryAll(Connection connection, List sqls, Long timest void updatePwd(Connection connection, IotDBUser iotDBUser) throws BaseException; - void stopQuery(Integer serverId, Long timestamp) throws BaseException; - - QueryInfoDTO getQueryInfoListByQueryClassificationId( + public QueryInfoDTO getQueryInfoListByQueryClassificationId( Connection connection, Integer queryClassificationId, Integer pageSize, @@ -177,10 +176,19 @@ QueryInfoDTO getQueryInfoListByQueryClassificationId( Integer executionResult) throws BaseException; - MetricsDataForDiagramVO getMetricDataByMetricId(Connection connection, Integer metricId) + public List getTopQueryMetricsData(); + + public MetricsDataForDiagramVO getMetricDataByMetricId(Connection connection, Integer metricId) throws BaseException; - List getTopQueryMetricsData(); + void stopQuery(Integer serverId, Long timestamp) throws BaseException; + + DataModelVO getDataModelDetail( + Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException; + + List getBatchLastMeasurementValue(Connection connection, List timeseriesList) + throws BaseException; - List getSlowQueryMetricsData(); + List getBatchDataCount( + Connection connection, String deviceName, List timeseriesList) throws BaseException; } diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java index 43188254..c174d0e2 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java @@ -151,10 +151,11 @@ public DataModelVO getDataModel(Connection connection, String path) throws BaseE sessionPool = getSessionPool(connection); DataModelVO root = new DataModelVO(path); setNodeInfo(root, sessionPool, path); - List childrenDataModel = getChildrenDataModel(root, path, sessionPool); + List childrenDataModel = getChildrenDataModel(root, path, sessionPool, 20); root.setChildren(childrenDataModel); root.setGroupCount(path.equals("root") ? getGroupCount(sessionPool) : null); root.setPath(path); + root.setShowNum(20); return root; } finally { closeSessionPool(sessionPool); @@ -162,15 +163,21 @@ public DataModelVO getDataModel(Connection connection, String path) throws BaseE } private List getChildrenDataModel( - DataModelVO root, String path, SessionPool sessionPool) throws BaseException { + DataModelVO root, String path, SessionPool sessionPool, Integer showNum) + throws BaseException { Set childrenNode = getChildrenNode(path, sessionPool); if (childrenNode == null) { return null; } + List childrenNodeList = new ArrayList<>(childrenNode); + List childrenNodeSubList = new ArrayList<>(); + if (childrenNodeList.size() > showNum) { + childrenNodeSubList = childrenNodeList.subList(0, showNum); + } else { + childrenNodeSubList = childrenNodeList; + } List childrenlist = new ArrayList<>(); - - // TODO: 大量IO - for (String child : childrenNode) { + for (String child : childrenNodeSubList) { DataModelVO childNode = new DataModelVO(child); setNodeInfo(childNode, sessionPool, path + "." + child); childrenlist.add(childNode); @@ -561,7 +568,15 @@ public CountDTO getMeasurementsByDevice( Connection connection, String deviceName, Integer pageSize, Integer pageNum, String keyword) throws BaseException { SessionPool sessionPool = getSessionPool(connection); + String queryCountSql = "count timeseries " + deviceName; + String s = executeQueryOneValue(sessionPool, queryCountSql); + int size = Integer.parseInt(s); String sql = "show timeseries " + deviceName; + int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize; + int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize; + if (size > pageStart) { + sql = "show timeseries " + deviceName + " limit " + pageSize + " offset " + pageStart; + } SessionDataSetWrapper sessionDataSetWrapper = null; try { sessionDataSetWrapper = sessionPool.executeQueryStatement(sql); @@ -582,37 +597,39 @@ public CountDTO getMeasurementsByDevice( } else { continue; } - if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) { - MeasurementDTO t = new MeasurementDTO(); - List columnNames = sessionDataSetWrapper.getColumnNames(); - for (int i = 0; i < fields.size(); i++) { - Field field = - MeasurementDTO.class.getDeclaredField(columnNames.get(i).replaceAll(" ", "")); - field.setAccessible(true); - field.set(t, fields.get(i).toString()); - } - results.add(t); + // if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) + // { + MeasurementDTO t = new MeasurementDTO(); + List columnNames = sessionDataSetWrapper.getColumnNames(); + for (int i = 0; i < fields.size(); i++) { + Field field = + MeasurementDTO.class.getDeclaredField(columnNames.get(i).replaceAll(" ", "")); + field.setAccessible(true); + field.set(t, fields.get(i).toString()); } + results.add(t); + // } } else { count++; - if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) { - MeasurementDTO t = new MeasurementDTO(); - List columnNames = sessionDataSetWrapper.getColumnNames(); - for (int i = 0; i < fields.size(); i++) { - Field field = - MeasurementDTO.class.getDeclaredField(columnNames.get(i).replaceAll(" ", "")); - field.setAccessible(true); - field.set(t, fields.get(i).toString()); - } - results.add(t); + // if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) + // { + MeasurementDTO t = new MeasurementDTO(); + List columnNames = sessionDataSetWrapper.getColumnNames(); + for (int i = 0; i < fields.size(); i++) { + Field field = + MeasurementDTO.class.getDeclaredField(columnNames.get(i).replaceAll(" ", "")); + field.setAccessible(true); + field.set(t, fields.get(i).toString()); } + results.add(t); + // } } } } CountDTO countDTO = new CountDTO(); countDTO.setObjects(results); - countDTO.setTotalCount(count); - Integer totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; + countDTO.setTotalCount(size); + Integer totalPage = size % pageSize == 0 ? size / pageSize : size / pageSize + 1; countDTO.setTotalPage(totalPage); return countDTO; } catch (IoTDBConnectionException e) { @@ -767,7 +784,7 @@ public void setIotDBRole(Connection connection, IotDBRole iotDBRole) throws Base @Override public DataModelVO getDataModelDetail( - Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException { + Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException { SessionPool sessionPool = null; try { sessionPool = getSessionPool(connection); @@ -775,9 +792,9 @@ public DataModelVO getDataModelDetail( setNodeInfo(root, sessionPool, path); List childrenDataModel = null; DataModelDetailDTO childrenDataModelDetail = - getChildrenDataModelDetail(root, path, sessionPool, pageSize, pageNum); + getChildrenDataModelDetail(root, path, sessionPool, pageSize, pageNum); childrenDataModel = - childrenDataModelDetail == null ? null : childrenDataModelDetail.getDataModelVOList(); + childrenDataModelDetail == null ? null : childrenDataModelDetail.getDataModelVOList(); if (childrenDataModelDetail != null) { root.setPageNum(childrenDataModelDetail.getPageNum()); root.setPageSize(childrenDataModelDetail.getPageSize()); @@ -785,9 +802,9 @@ public DataModelVO getDataModelDetail( } root.setChildren(childrenDataModel); root.setTotalSonNodeCount( - getChildrenNode(path, sessionPool) == null - ? 0 - : getChildrenNode(path, sessionPool).size()); + getChildrenNode(path, sessionPool) == null + ? 0 + : getChildrenNode(path, sessionPool).size()); root.setGroupCount(path.equals("root") ? getGroupCount(sessionPool) : null); root.setPath(path); return root; @@ -796,9 +813,57 @@ public DataModelVO getDataModelDetail( } } + @Override + public List getBatchLastMeasurementValue( + Connection connection, List timeseriesList) throws BaseException { + SessionPool sessionPool = getSessionPool(connection); + List indexList = new ArrayList<>(); + for (String timeseries : timeseriesList) { + indexList.add(timeseries.lastIndexOf(".")); + } + String sql = "select "; + for (int i = 0; i < timeseriesList.size(); i++) { + sql += "last_value(" + timeseriesList.get(i).substring(indexList.get(i) + 1) + ")" + ", "; + } + sql = sql.substring(0, sql.length() - 2); + sql += " from "; + sql += timeseriesList.get(0).substring(0, indexList.get(0)); + List values; + try { + values = executeQueryOneLine(sessionPool, sql); + } finally { + closeSessionPool(sessionPool); + } + return values; + } + + @Override + public List getBatchDataCount( + Connection connection, String deviceName, List timeseriesList) throws BaseException { + SessionPool sessionPool = getSessionPool(connection); + List indexList = new ArrayList<>(); + for (String timeseries : timeseriesList) { + indexList.add(timeseries.lastIndexOf(".")); + } + String sql = "select "; + for (int i = 0; i < timeseriesList.size(); i++) { + sql += "count(" + timeseriesList.get(i).substring(indexList.get(i) + 1) + ")" + ", "; + } + sql = sql.substring(0, sql.length() - 2); + sql += " from "; + sql += timeseriesList.get(0).substring(0, indexList.get(0)); + List values; + try { + values = executeQueryOneLine(sessionPool, sql); + } finally { + closeSessionPool(sessionPool); + } + return values; + } + private DataModelDetailDTO getChildrenDataModelDetail( - DataModelVO root, String path, SessionPool sessionPool, Integer pageSize, Integer pageNum) - throws BaseException { + DataModelVO root, String path, SessionPool sessionPool, Integer pageSize, Integer pageNum) + throws BaseException { Set childrenNode = getChildrenNode(path, sessionPool); if (childrenNode == null) { return null; @@ -1633,9 +1698,7 @@ private void checkValue(String value) throws BaseException { private void upsertMeasurementAlias(SessionPool sessionPool, String timeseries, String alias) throws BaseException { - // 需要改为" "值。 - if (alias == null || "null".equals(alias)) { - // if (alias == null || "null".equals(alias) || StringUtils.isBlank(alias)) { + if (alias == null || "null".equals(alias) || StringUtils.isBlank(alias)) { return; } if (alias.matches("^as$") || alias.matches("^\\d+$") || alias.matches("^like$")) { @@ -1850,7 +1913,9 @@ private List getDeviceNodeTree(SessionPool sessionPool, String group } @Override - public NodeTreeVO getDeviceList(Connection connection, String groupName) throws BaseException { + public NodeTreeVO getDeviceList( + Connection connection, String groupName, Integer pageSize, Integer pageNum) + throws BaseException { SessionPool sessionPool = null; try { sessionPool = getSessionPool(connection); @@ -1863,7 +1928,9 @@ public NodeTreeVO getDeviceList(Connection connection, String groupName) throws ancestryName = groupName; } NodeTreeVO ancestry = new NodeTreeVO(ancestryName); - assembleDeviceList(ancestry, groupName, sessionPool); + assembleDeviceList(ancestry, groupName, sessionPool, pageSize, pageNum); + ancestry.setName(groupName); + ancestry.setTotal(devices.size()); return ancestry; } finally { closeSessionPool(sessionPool); @@ -1891,17 +1958,28 @@ public List getDeviceParents(Connection connection, String groupName, St } } - private void assembleDeviceList(NodeTreeVO node, String deviceName, SessionPool sessionPool) + private void assembleDeviceList( + NodeTreeVO node, + String deviceName, + SessionPool sessionPool, + Integer pageSize, + Integer pageNum) throws BaseException { List descendants = findDescendants(deviceName, sessionPool); if (descendants.size() == 0) { return; } List children = findChildren(descendants); + int size = children.size(); + int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize; + int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize; + if (size > pageStart) { + children = children.subList(pageStart, pageEnd); + } for (String child : children) { NodeTreeVO childNode = new NodeTreeVO(child); node.initChildren().add(childNode); - assembleDeviceList(childNode, child, sessionPool); + // assembleDeviceList(childNode, child, sessionPool); } } From 29a70910a87b2adfa4c4f992904b8e5340baf381 Mon Sep 17 00:00:00 2001 From: ljn <> Date: Wed, 1 Jun 2022 11:07:47 +0800 Subject: [PATCH 4/4] hotfix:add the licenses --- .../admin/controller/MetricsController.java | 4 ---- .../iotdb/admin/mapper/ViewModeMapper.java | 23 +++++++++++++++---- .../admin/model/dto/DataModelDetailDTO.java | 18 +++++++++++++++ .../iotdb/admin/model/dto/QueryInfoDTO.java | 23 +++++++++++++++---- .../iotdb/admin/model/entity/ViewMode.java | 22 ++++++++++++++---- .../admin/model/metricsDo/QueryDataDo.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/GroupInfo.java | 18 +++++++++++++++ .../admin/model/vo/JVMMetricsListDataVO.java | 22 ++++++++++++++---- .../vo/MetircsQueryClassificationVO.java | 22 ++++++++++++++---- .../admin/model/vo/MetricsChartDataVO.java | 22 ++++++++++++++---- .../admin/model/vo/MetricsConnectionVO.java | 23 +++++++++++++++---- .../admin/model/vo/MetricsDataCountVO.java | 22 ++++++++++++++---- .../model/vo/MetricsDataForDiagramVO.java | 22 ++++++++++++++---- .../admin/model/vo/MetricsDataForListVO.java | 22 ++++++++++++++---- .../admin/model/vo/MetricsListDataVO.java | 23 +++++++++++++++---- .../admin/model/vo/QueryClassificationVO.java | 23 +++++++++++++++---- .../iotdb/admin/model/vo/QueryData1VO.java | 22 ++++++++++++++---- .../admin/model/vo/QueryDataForListVO.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/QueryDataStrVO.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/QueryDataStrVO1.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/QueryDataVO.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/QueryInfoVO.java | 22 ++++++++++++++---- .../iotdb/admin/model/vo/QueryMetricsVO.java | 22 ++++++++++++++---- .../admin/service/MetricsResultService.java | 22 ++++++++++++++---- .../iotdb/admin/service/MetricsService.java | 22 ++++++++++++++---- .../impl/MetricsResultServiceImpl.java | 22 ++++++++++++++---- .../service/impl/MetricsServiceImpl.java | 22 ++++++++++++++---- 27 files changed, 473 insertions(+), 100 deletions(-) diff --git a/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java index 5c5a9684..30fda570 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java +++ b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java @@ -38,10 +38,6 @@ import java.util.ArrayList; import java.util.List; -/** - * @author Erickin - * @create 2022-04-22-上午 9:55 - */ @RestController @Api(value = "metrics related") public class MetricsController { diff --git a/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java b/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java index 66f9ea37..dd3bc582 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java +++ b/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.mapper; import org.apache.iotdb.admin.model.entity.ViewMode; @@ -5,9 +23,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.springframework.stereotype.Component; -/** - * @author Erickin - * @create 2022-04-22-上午 10:32 - */ + @Component public interface ViewModeMapper extends BaseMapper {} diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java index 58463b06..e60abea2 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.dto; import org.apache.iotdb.admin.model.vo.DataModelVO; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java b/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java index 7f3210be..e69ad388 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.dto; import org.apache.iotdb.admin.model.vo.QueryDataStrVO; @@ -6,10 +24,7 @@ import java.util.List; -/** - * @author Erickin - * @create 2022-04-25-下午 5:12 - */ + @Data public class QueryInfoDTO { private Long latestRunningTime; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java b/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java index 56c9ae6e..bc0b450d 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.entity; import com.baomidou.mybatisplus.annotation.IdType; @@ -11,10 +29,6 @@ import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-22-上午 10:35 - */ @Data @TableName("view_mode") public class ViewMode implements Serializable { diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java b/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java index 2be1e095..81e8bdee 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.metricsDo; import org.apache.iotdb.admin.model.vo.QueryDataVO; @@ -6,10 +24,6 @@ import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-上午 9:28 - */ @Data public class QueryDataDo { private List QueryDataVOs; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java index 62e3cb2a..f95fd50e 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.AllArgsConstructor; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java index 36615556..146635dd 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-26-下午 5:26 - */ @Data public class JVMMetricsListDataVO extends MetricsListDataVO implements Serializable { private String metricType; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java index 851c8337..26a2bedc 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.util.List; -/** - * @author Erickin - * @create 2022-04-25-上午 10:00 - */ @Data public class MetircsQueryClassificationVO { private Integer serverId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java index 9bfa81f5..f211b547 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; @@ -6,10 +24,6 @@ import java.util.HashMap; import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-上午 10:15 - */ @Data public class MetricsChartDataVO implements Serializable { private List timeList; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java index 8045fdb4..e433ff96 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java @@ -1,13 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-25-上午 9:12 - */ + @Data public class MetricsConnectionVO implements Serializable { Integer id; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java index 82f6337f..9849648c 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java @@ -1,11 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; -/** - * @author Erickin - * @create 2022-04-25-上午 9:38 - */ @Data public class MetricsDataCountVO { private Integer serverId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java index 08135e3d..0a27d001 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-26-上午 10:12 - */ @Data public class MetricsDataForDiagramVO implements Serializable { private Integer serverId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java index 269cde1c..7a763fb9 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 8:12 - */ @Data public class MetricsDataForListVO { private Integer serverId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java index 7bde7cad..bb62171d 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java @@ -1,13 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-26-下午 5:24 - */ + @Data public class MetricsListDataVO implements Serializable { private String name; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java index 17993c00..1864a0a7 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java @@ -1,11 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; -/** - * @author Erickin - * @create 2022-04-25-上午 10:02 - */ + @Data public class QueryClassificationVO { private Integer id; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java index b14e3c47..1e5102cc 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-25-下午 3:56 - */ @Data public class QueryData1VO extends QueryDataVO implements Serializable { private Integer precompiledTime; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java index b200a0d2..1f86fc37 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 9:22 - */ @Data public class QueryDataForListVO { private Integer serverId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java index 5aecf441..f9511b46 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-28-下午 10:02 - */ @Data public class QueryDataStrVO implements Serializable { private Integer id; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java index a14537ab..b74408e7 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-29-下午 2:10 - */ @Data public class QueryDataStrVO1 extends QueryDataStrVO implements Serializable { private Integer precompiledTime; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java index 081be812..ca62db31 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.io.Serializable; -/** - * @author Erickin - * @create 2022-04-25-下午 8:36 - */ @Data public class QueryDataVO implements Serializable { private Integer id; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java index e2b35293..007f9aa9 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java @@ -1,13 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; import java.util.List; -/** - * @author Erickin - * @create 2022-04-25-下午 5:13 - */ @Data public class QueryInfoVO { private Integer queryClassificationId; diff --git a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java index cdf3e12b..fba6a4fe 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java +++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java @@ -1,11 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.model.vo; import lombok.Data; -/** - * @author Erickin - * @create 2022-04-26-下午 9:20 - */ @Data public class QueryMetricsVO { private String SQLStatement; diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java index 1180f23f..811c8ec1 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.service; import org.apache.iotdb.admin.common.exception.BaseException; @@ -6,10 +24,6 @@ import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 4:07 - */ public interface MetricsResultService { List getJVMMetricsDataList(Connection connection) throws BaseException; diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java index 50f86632..0acd5b73 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.service; import org.apache.iotdb.admin.common.exception.BaseException; @@ -6,10 +24,6 @@ import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 4:07 - */ public interface MetricsService { List getJVMMetricsDataList(Connection connection) throws BaseException; diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java index de26ba5d..4137090c 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.service.impl; import org.apache.iotdb.admin.common.exception.BaseException; @@ -12,10 +30,6 @@ import java.util.ArrayList; import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 4:41 - */ @Service public class MetricsResultServiceImpl implements MetricsResultService { diff --git a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java index 5dd025d9..47ef9cb1 100644 --- a/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java +++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.iotdb.admin.service.impl; import org.apache.iotdb.admin.common.exception.BaseException; @@ -27,10 +45,6 @@ import java.util.ArrayList; import java.util.List; -/** - * @author Erickin - * @create 2022-04-26-下午 4:41 - */ @Service public class MetricsServiceImpl implements MetricsService {