Merge pull request #17 from ljn55966005/dev-0.13.0-metircs
diff --git a/backend/pom.xml b/backend/pom.xml
index 45d3bea..e3fb378 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -145,7 +145,7 @@
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
- <version>0.12.1</version>
+ <version>0.12.5</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
@@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
- <version>0.12.1</version>
+ <version>0.12.5</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
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 2084338..7e04593 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 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 ea0106b..33aea37 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 @@
return getResponseEntity(resource);
}
+ @ApiOperation("Download the query log file")
+ @GetMapping("/downloadQueryLogFile")
+ public ResponseEntity<Resource> 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<Resource> 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 612816e..67e4289 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,35 +85,67 @@
@GetMapping("/dataModel")
@ApiOperation("Get IoTDB data model")
public BaseVO<DataModelVO> 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);
+ }
+
+ @GetMapping("/dataModel/detail")
+ @ApiOperation("Get IoTDB data model in detail")
+ public BaseVO<DataModelVO> 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<List<GroupInfoVO>> getAllStorageGroupsInfo(
- @PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
+ public BaseVO<GroupInfoVO> 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<String> groupNames = iotDBService.getAllStorageGroups(connection);
- List<GroupInfoVO> groupInfoList = new ArrayList<>();
- if (groupNames == null || groupNames.size() == 0) {
- return BaseVO.success("Get successfully", groupInfoList);
+ List<String> 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<GroupInfo> groupInfoList = new ArrayList<>();
+ GroupInfoVO groupInfoVO = new GroupInfoVO();
+ if (subGroupNames == null || subGroupNames.size() == 0) {
+ return BaseVO.success("Get successfully", groupInfoVO);
}
String host = connection.getHost();
- List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, groupNames);
- List<String> 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<Integer> deviceCounts = iotDBService.getDevicesCount(connection, subGroupNames);
+ List<String> 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")
@@ -130,8 +162,6 @@
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);
}
@@ -161,7 +191,6 @@
Connection connection = connectionService.getById(serverId);
Long ttl = groupDTO.getTtl();
String ttlUnit = groupDTO.getTtlUnit();
- checkTtl(ttl, ttlUnit);
Integer groupId = groupDTO.getGroupId();
groupDTO.setGroupName(groupName);
@@ -175,6 +204,7 @@
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);
@@ -323,12 +353,19 @@
public BaseVO<NodeTreeVO> 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);
}
@@ -430,8 +467,8 @@
@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 {
@@ -444,17 +481,26 @@
List<MeasurementVO> measurementVOList = new ArrayList<>();
String host = connection.getHost();
if (measurementDTOList != null) {
+ List<String> timeseriesList = new ArrayList<>();
+ for (MeasurementDTO measurementDTO : measurementDTOList) {
+ timeseriesList.add(measurementDTO.getTimeseries());
+ }
+ List<String> batchNewValue =
+ iotDBService.getBatchLastMeasurementValue(connection, timeseriesList);
+ List<String> 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<List<String>> tags = new ArrayList<>();
@@ -488,6 +534,7 @@
throw new BaseException(ErrorCode.GET_MSM_FAIL, ErrorCode.GET_MSM_FAIL_MSG);
}
measurementVOList.add(measurementVO);
+ index++;
}
}
MeasuremtnInfoVO measuremtnInfoVO = new MeasuremtnInfoVO();
@@ -1121,9 +1168,7 @@
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 +1274,9 @@
}
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/controller/MetricsController.java b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java
new file mode 100644
index 0000000..30fda57
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/controller/MetricsController.java
@@ -0,0 +1,166 @@
+/*
+ * 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;
+
+@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<List<MetricsConnectionVO>> getConnectionList(HttpServletRequest request)
+ throws BaseException {
+ Integer userId = AuthenticationUtils.getUserId(request);
+ AuthenticationUtils.userAuthentication(userId, request);
+ List<ConnVO> allConnections = connectionService.getAllConnections(userId);
+ ArrayList<MetricsConnectionVO> 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<MetricsDataCountVO> 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<MetircsQueryClassificationVO> 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<QueryInfoVO> 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<MetricsDataForDiagramVO> 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<MetricsDataForListVO> 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<QueryDataForListVO> 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<QueryMetricsVO> queryMetricsVOs = iotDBService.getTopQueryMetricsData();
+ queryDataForListVO.setQueryMetricsVOs(queryMetricsVOs);
+
+ } else if (mode == 0) {
+ List<QueryMetricsVO> 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 0000000..dd3bc58
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/mapper/ViewModeMapper.java
@@ -0,0 +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.mapper;
+
+import org.apache.iotdb.admin.model.entity.ViewMode;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Component;
+
+
+@Component
+public interface ViewModeMapper extends BaseMapper<ViewMode> {}
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 4a7ea78..ed3b8e1 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<String> privileges;
private List<String> cancelPrivileges;
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 0000000..e60abea
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/DataModelDetailDTO.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class DataModelDetailDTO implements Serializable {
+ private List<DataModelVO> 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 0000000..e69ad38
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/dto/QueryInfoDTO.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import lombok.Data;
+
+import java.util.List;
+
+
+@Data
+public class QueryInfoDTO {
+ private Long latestRunningTime;
+ private Integer totalCount;
+ private Integer totalPage;
+ List<QueryDataStrVO> 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 0000000..bc0b450
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/entity/ViewMode.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+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;
+
+@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 0000000..81e8bde
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/metricsDo/QueryDataDo.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class QueryDataDo {
+ private List<QueryDataVO> QueryDataVOs;
+ private Long latestTimeStamp;
+ private Integer count;
+}
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 cdef28c..fc2c2e7 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/model/vo/DataModelVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java
index 2763728..60f9a60 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 @@
private List<DataModelVO> 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 0000000..f95fd50
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfo.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+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 512deb7..87f4823 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<GroupInfo> 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 0000000..146635d
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/JVMMetricsListDataVO.java
@@ -0,0 +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;
+
+@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 0000000..26a2bed
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetircsQueryClassificationVO.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+@Data
+public class MetircsQueryClassificationVO {
+ private Integer serverId;
+ private List<QueryClassificationVO> 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 0000000..f211b54
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsChartDataVO.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+import java.util.HashMap;
+import java.util.List;
+
+@Data
+public class MetricsChartDataVO implements Serializable {
+ private List<String> timeList;
+ private List<String> metricnameList;
+ private List<String> unitList;
+ private HashMap<String, List<String>> dataList;
+}
+
+// List<String> timeList;
+// List<String> metricnameList;
+// HashMap<String, List<Integer> 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 0000000..e433ff9
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsConnectionVO.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+
+@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 0000000..9849648
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataCountVO.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+@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 0000000..0a27d00
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForDiagramVO.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+@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 0000000..7a763fb
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsDataForListVO.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+@Data
+public class MetricsDataForListVO {
+ private Integer serverId;
+ private Integer metricsType;
+ private List<MetricsListDataVO> 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 0000000..bb62171
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/MetricsListDataVO.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+
+@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/NodeTreeVO.java b/backend/src/main/java/org/apache/iotdb/admin/model/vo/NodeTreeVO.java
index cfa4acc..46a476b 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 @@
private List<NodeTreeVO> children;
+ private Integer pageSize;
+
+ private Integer pageNum;
+
+ private Integer total;
+ // private List<String> childrenName;
+
public NodeTreeVO(String name) {
this.name = name;
}
+ public NodeTreeVO() {}
+
public List<NodeTreeVO> initChildren() {
if (children == null) {
children = new ArrayList<>();
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 0000000..1864a0a
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryClassificationVO.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+
+@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 0000000..1e5102c
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryData1VO.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+@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 0000000..1f86fc3
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataForListVO.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+@Data
+public class QueryDataForListVO {
+ private Integer serverId;
+ private Integer mode;
+ private List<QueryMetricsVO> 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 0000000..f9511b4
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+@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 0000000..b74408e
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataStrVO1.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+@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 0000000..ca62db3
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryDataVO.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+@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 0000000..007f9aa
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryInfoVO.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+@Data
+public class QueryInfoVO {
+ private Integer queryClassificationId;
+ private String latestRunningTime;
+ private Integer totalCount;
+ private Integer totalPage;
+ private Integer serverId;
+ private List<QueryDataStrVO> 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 0000000..fba6a4f
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/model/vo/QueryMetricsVO.java
@@ -0,0 +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;
+
+@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 70cd585..4c5eff4 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<String> getAllStorageGroups(Connection connection) throws BaseException;
@@ -119,7 +119,9 @@
List<NodeTreeVO> 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<String> getDeviceParents(Connection connection, String groupName, String deviceName)
throws BaseException;
@@ -152,6 +154,8 @@
Connection connection, String userOrRole, String name, PrivilegeInfoDTO privilegeInfoDTO)
throws BaseException;
+ public List<QueryMetricsVO> getSlowQueryMetricsData();
+
RecordVO getRecords(
Connection connection, String deviceName, String timeseriesName, String dataType)
throws BaseException;
@@ -161,5 +165,30 @@
void updatePwd(Connection connection, IotDBUser iotDBUser) throws BaseException;
+ public QueryInfoDTO getQueryInfoListByQueryClassificationId(
+ Connection connection,
+ Integer queryClassificationId,
+ Integer pageSize,
+ Integer pageNum,
+ String filterString,
+ Long startTime,
+ Long endTime,
+ Integer executionResult)
+ throws BaseException;
+
+ public List<QueryMetricsVO> getTopQueryMetricsData();
+
+ public MetricsDataForDiagramVO getMetricDataByMetricId(Connection connection, Integer metricId)
+ throws BaseException;
+
void stopQuery(Integer serverId, Long timestamp) throws BaseException;
+
+ DataModelVO getDataModelDetail(
+ Connection connection, String path, Integer pageSize, Integer pageNum) throws BaseException;
+
+ List<String> getBatchLastMeasurementValue(Connection connection, List<String> timeseriesList)
+ throws BaseException;
+
+ List<String> getBatchDataCount(
+ Connection connection, String deviceName, List<String> timeseriesList) throws BaseException;
}
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 0000000..811c8ec
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsResultService.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+import org.apache.iotdb.admin.model.entity.Connection;
+import org.apache.iotdb.admin.model.vo.MetricsListDataVO;
+
+import java.util.List;
+
+public interface MetricsResultService {
+ List<MetricsListDataVO> getJVMMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getCPUMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getMemMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getDiskMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> 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 0000000..0acd5b7
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/service/MetricsService.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+import org.apache.iotdb.admin.model.entity.Connection;
+import org.apache.iotdb.admin.model.vo.*;
+
+import java.util.List;
+
+public interface MetricsService {
+ List<MetricsListDataVO> getJVMMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getCPUMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getMemMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> getDiskMetricsDataList(Connection connection) throws BaseException;
+
+ List<MetricsListDataVO> 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 803c4f5..c174d0e 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 @@
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<String> dataCountList = executeQueryOneLine(sessionPool, "select count(*) from root");
+ List<String> 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,46 @@
}
@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<DataModelVO> 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);
}
}
+ private List<DataModelVO> getChildrenDataModel(
+ DataModelVO root, String path, SessionPool sessionPool, Integer showNum)
+ throws BaseException {
+ Set<String> childrenNode = getChildrenNode(path, sessionPool);
+ if (childrenNode == null) {
+ return null;
+ }
+ List<String> childrenNodeList = new ArrayList<>(childrenNode);
+ List<String> childrenNodeSubList = new ArrayList<>();
+ if (childrenNodeList.size() > showNum) {
+ childrenNodeSubList = childrenNodeList.subList(0, showNum);
+ } else {
+ childrenNodeSubList = childrenNodeList;
+ }
+ List<DataModelVO> childrenlist = new ArrayList<>();
+ for (String child : childrenNodeSubList) {
+ 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<String> childrenNode = getChildrenNode(prefixPath, sessionPool);
@@ -152,22 +202,51 @@
private Set<String> getChildrenNode(String prefixPath, SessionPool sessionPool)
throws BaseException {
String sql = "show storage group " + prefixPath;
+ sql = sql.replace(',', '.');
List<String> 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<String> 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 +255,19 @@
}
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 +275,19 @@
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 +334,7 @@
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 +362,24 @@
+ 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 +463,14 @@
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 +483,8 @@
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);
}
@@ -446,7 +568,15 @@
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);
@@ -467,37 +597,39 @@
} else {
continue;
}
- if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) {
- MeasurementDTO t = new MeasurementDTO();
- List<String> 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<String> 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<String> 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<String> 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) {
@@ -651,6 +783,114 @@
}
@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<DataModelVO> 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);
+ }
+ }
+
+ @Override
+ public List<String> getBatchLastMeasurementValue(
+ Connection connection, List<String> timeseriesList) throws BaseException {
+ SessionPool sessionPool = getSessionPool(connection);
+ List<Integer> 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<String> values;
+ try {
+ values = executeQueryOneLine(sessionPool, sql);
+ } finally {
+ closeSessionPool(sessionPool);
+ }
+ return values;
+ }
+
+ @Override
+ public List<String> getBatchDataCount(
+ Connection connection, String deviceName, List<String> timeseriesList) throws BaseException {
+ SessionPool sessionPool = getSessionPool(connection);
+ List<Integer> 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<String> 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 {
+ Set<String> childrenNode = getChildrenNode(path, sessionPool);
+ if (childrenNode == null) {
+ return null;
+ }
+ List<DataModelVO> childrenlist = new ArrayList<>();
+ List<String> childrenNodeList = new ArrayList<>(childrenNode);
+ List<String> 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);
UserRolesVO userRolesVO = new UserRolesVO();
@@ -907,15 +1147,29 @@
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) {
@@ -1659,7 +1913,9 @@
}
@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);
@@ -1672,7 +1928,9 @@
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);
@@ -1700,17 +1958,28 @@
}
}
- 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<String> descendants = findDescendants(deviceName, sessionPool);
if (descendants.size() == 0) {
return;
}
List<String> 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);
}
}
@@ -2305,6 +2574,1610 @@
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<QueryDataVO> 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<QueryDataVO> 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<QueryDataStrVO> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("Interface1");
+ metricnameList.add("Interface2");
+ metricnameList.add("Interface3");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> interface1 = new ArrayList<>();
+ List<String> interface2 = new ArrayList<>();
+ List<String> interface3 = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> 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<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> close_Operation = new ArrayList<>();
+ List<String> execute_Query_Statement = new ArrayList<>();
+ List<String> execute_Statement = new ArrayList<>();
+ List<String> get_Properties = new ArrayList<>();
+ List<String> insert_Record = new ArrayList<>();
+ List<String> close_Session = new ArrayList<>();
+ List<String> open_Session = new ArrayList<>();
+ List<String> request_Statement_Id = new ArrayList<>();
+ List<String> fetch_Results = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("success");
+ metricnameList.add("fail");
+ metricnameList.add("total");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> success = new ArrayList<>();
+ List<String> fail = new ArrayList<>();
+ List<String> total = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("success");
+ metricnameList.add("fail");
+ metricnameList.add("total");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> success = new ArrayList<>();
+ List<String> fail = new ArrayList<>();
+ List<String> total = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("wal");
+ metricnameList.add("tsfile_seq");
+ metricnameList.add("tsfile_unseq");
+ metricnameList.add("total");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("MB");
+ List<String> wal = new ArrayList<>();
+ List<String> tsfile_seq = new ArrayList<>();
+ List<String> tsfile_unseq = new ArrayList<>();
+ List<String> total = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("wal");
+ metricnameList.add("tsfile_seq");
+ metricnameList.add("tsfile_unseq");
+ metricnameList.add("total");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("个");
+ List<String> wal = new ArrayList<>();
+ List<String> tsfile_seq = new ArrayList<>();
+ List<String> tsfile_unseq = new ArrayList<>();
+ List<String> total = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("io");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("次/s");
+ List<String> io = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("buffer");
+ metricnameList.add("max");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("MB");
+ List<String> buffer = new ArrayList<>();
+ List<String> max = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("storage");
+ metricnameList.add("max");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("MB");
+ List<String> storage = new ArrayList<>();
+ List<String> max = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("new");
+ metricnameList.add("canrunning");
+ metricnameList.add("running");
+ metricnameList.add("block");
+ metricnameList.add("die");
+ metricnameList.add("dormancy");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("个");
+ List<String> newState = new ArrayList<>();
+ List<String> canrunning = new ArrayList<>();
+ List<String> running = new ArrayList<>();
+ List<String> block = new ArrayList<>();
+ List<String> die = new ArrayList<>();
+ List<String> dormancy = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("front");
+ metricnameList.add("end");
+ metricnameList.add("total");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("个");
+ List<String> front = new ArrayList<>();
+ List<String> end = new ArrayList<>();
+ List<String> total = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("模块1");
+ metricnameList.add("模块2");
+ metricnameList.add("模块3");
+ metricnameList.add("模块4");
+ metricnameList.add("模块5");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("%");
+ List<String> module1 = new ArrayList<>();
+ List<String> module2 = new ArrayList<>();
+ List<String> module3 = new ArrayList<>();
+ List<String> module4 = new ArrayList<>();
+ List<String> module5 = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("Metadata GC Threshold");
+ metricnameList.add("Allocation Failure");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> metadata_GC_Threshold_Reason = new ArrayList<>();
+ List<String> Allocation_Failure_Reason = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("Metadata GC Threshold");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("ms");
+ List<String> metadata_GC_Threshold_Reason = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("load");
+ metricnameList.add("unload");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("个");
+ List<String> load = new ArrayList<>();
+ List<String> unload = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<QueryMetricsVO> getTopQueryMetricsData() {
+ // TODO [清华]提供获取Top SQL语句信息的接口
+ // FakeData
+ List<QueryMetricsVO> 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<QueryMetricsVO> getSlowQueryMetricsData() {
+ // TODO [清华]提供获取Slow SQL语句信息的接口
+ // FakeData
+ List<QueryMetricsVO> 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<String> timeList = new ArrayList<>();
+ List<String> metricnameList = new ArrayList<>();
+ metricnameList.add("fgc次数");
+ metricnameList.add("ygc次数");
+ metricnameList.add("fgc耗时");
+ metricnameList.add("ygc耗时");
+ List<String> unitList = new ArrayList<>();
+ unitList.add("次");
+ unitList.add("ms");
+ List<String> majorGCCount = new ArrayList<>();
+ List<String> minorGCCount = new ArrayList<>();
+ List<String> majorGCTime = new ArrayList<>();
+ List<String> minorGCTime = new ArrayList<>();
+ HashMap<String, List<String>> 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<org.apache.iotdb.tsfile.read.common.Field> 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<QueryDataVO> queryDataVOS,
+ Integer pageSize,
+ Integer pageNum,
+ String filterString,
+ Long startTime,
+ Long endTime,
+ Integer executionResult) {
+ List<QueryDataVO> filteredQueryDataVOS = new ArrayList<>();
+ filteredQueryDataVOS.addAll(queryDataVOS);
+ if (filterString != null) {
+ List<QueryDataVO> tempList = new ArrayList<>();
+ for (QueryDataVO queryDataVO : filteredQueryDataVOS) {
+ if (queryDataVO.getStatement().contains(filterString)) {
+ tempList.add(queryDataVO);
+ }
+ }
+ filteredQueryDataVOS.clear();
+ filteredQueryDataVOS.addAll(tempList);
+ }
+ if (startTime != -1) {
+ List<QueryDataVO> tempList = new ArrayList<>();
+ for (QueryDataVO queryDataVO : filteredQueryDataVOS) {
+ if (queryDataVO.getRunningTime() >= startTime) {
+ tempList.add(queryDataVO);
+ }
+ }
+ filteredQueryDataVOS.clear();
+ filteredQueryDataVOS.addAll(tempList);
+ }
+ if (endTime != -1) {
+ List<QueryDataVO> tempList = new ArrayList<>();
+ for (QueryDataVO queryDataVO : filteredQueryDataVOS) {
+ if (queryDataVO.getRunningTime() <= endTime) {
+ tempList.add(queryDataVO);
+ }
+ }
+ filteredQueryDataVOS.clear();
+ filteredQueryDataVOS.addAll(tempList);
+ }
+ if (executionResult != null) {
+ List<QueryDataVO> 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<QueryDataVO> 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 +4215,17 @@
List<String> 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 +4374,7 @@
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 +4616,9 @@
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 +4653,9 @@
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 +4836,25 @@
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/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 0000000..4137090
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsResultServiceImpl.java
@@ -0,0 +1,297 @@
+/*
+ * 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;
+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;
+
+@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<MetricsListDataVO> getJVMMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getCPUMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getMemMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getDiskMetricsDataList(Connection connection)
+ throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getWriteMetricsDataList(Connection connection)
+ throws BaseException {
+ List<MetricsListDataVO> 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 0000000..47ef9cb
--- /dev/null
+++ b/backend/src/main/java/org/apache/iotdb/admin/service/impl/MetricsServiceImpl.java
@@ -0,0 +1,1760 @@
+/*
+ * 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;
+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;
+
+@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<String> values = executeQueryOneLine(sessionPool, sql);
+ long lastestTimeStamp = Long.parseLong(values.get(0));
+ String s1 = values.get(2);
+ String s2 = values.get(1);
+ s1 = s1.substring(0, s1.indexOf('.'));
+ s2 = s2.substring(0, s2.indexOf('.'));
+ int totalThreadCount = Integer.parseInt(s1);
+ int demoThreadCount = Integer.parseInt(s2);
+ String latestScratchTime = simpleDateFormat.format(lastestTimeStamp);
+ String latestResult =
+ "前台:"
+ + (totalThreadCount - demoThreadCount)
+ + "个,后台:"
+ + demoThreadCount
+ + "个,线程总数:"
+ + totalThreadCount
+ + "个";
+ JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO();
+ jvmMetricsListDataVO.setMetricType(metricType);
+ jvmMetricsListDataVO.setDetailAvailable(detailAvailable);
+ jvmMetricsListDataVO.setLatestResult(latestResult);
+ jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime);
+ jvmMetricsListDataVO.setName(name);
+ return jvmMetricsListDataVO;
+ }
+
+ 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<String> 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<String> 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<String> 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<String> countValues = executeQueryOneLine(sessionPool, countSQL);
+ List<String> timeValues = executeQueryOneLine(sessionPool, timeSQL);
+ long lastestTimeStamp = Long.parseLong(countValues.get(0));
+ String latestScratchTime = simpleDateFormat.format(lastestTimeStamp);
+ Integer detailAvailable = 2;
+ String s1 = countValues.get(1);
+ String s2 = countValues.get(2);
+ s1 = s1.substring(0, s1.indexOf('.'));
+ s2 = s2.substring(0, s2.indexOf('.'));
+ int count = Integer.parseInt(s1) + Integer.parseInt(s2);
+ double time =
+ (Double.parseDouble(timeValues.get(1)) + Double.parseDouble(timeValues.get(2))) / 1000;
+ String latestResult = count + "次 " + time + "s";
+ JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO();
+ jvmMetricsListDataVO.setMetricType(metricType);
+ jvmMetricsListDataVO.setDetailAvailable(detailAvailable);
+ jvmMetricsListDataVO.setLatestResult(latestResult);
+ jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime);
+ jvmMetricsListDataVO.setName(name);
+ return jvmMetricsListDataVO;
+ }
+
+ 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<String> 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<String> countValues = executeQueryOneLine(sessionPool, countSQL);
+ List<String> timeValues = executeQueryOneLine(sessionPool, timeSQL);
+ long lastestTimeStamp = Long.parseLong(countValues.get(0));
+ String latestScratchTime = simpleDateFormat.format(lastestTimeStamp);
+ Integer detailAvailable = 2;
+ // TODO: IOTDB BUG 等待修复
+ String s1 = countValues.get(1).equals("null") ? "0.0" : countValues.get(1);
+ // String s2 = countValues.get(2).equals("null") ? "0.0" : countValues.get(2);
+ // String s3 = countValues.get(3).equals("null") ? "0.0" : countValues.get(3);
+
+ s1 = s1.substring(0, s1.indexOf('.'));
+ // s2 = s2.substring(0, s2.indexOf('.'));
+ // s3 = s3.substring(0, s3.indexOf('.'));
+ // int count = Integer.parseInt(s1) + Integer.parseInt(s2) + Integer.parseInt(s3);
+ int count = Integer.parseInt(s1);
+ // TODO: IOTDB BUG 等待修复
+ double d1 = timeValues.get(1).equals("null") ? 0.0 : Double.parseDouble(timeValues.get(1));
+ // double d2 = timeValues.get(2).equals("null")? 0.0 : Double.parseDouble(timeValues.get(2));
+ // double d3 = timeValues.get(3).equals("null")? 0.0 : Double.parseDouble(timeValues.get(3));
+ // double time = d1 + d2 + d3;
+ double time = (d1) / 1000;
+ String latestResult = count + "次 " + time + "s";
+ JVMMetricsListDataVO jvmMetricsListDataVO = new JVMMetricsListDataVO();
+ jvmMetricsListDataVO.setMetricType(metricType);
+ jvmMetricsListDataVO.setDetailAvailable(detailAvailable);
+ jvmMetricsListDataVO.setLatestResult(latestResult);
+ jvmMetricsListDataVO.setLatestScratchTime(latestScratchTime);
+ jvmMetricsListDataVO.setName(name);
+ return jvmMetricsListDataVO;
+ }
+
+ 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<MetricsListDataVO> getJVMMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getCPUMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> list = new ArrayList<>();
+ list.add(getCPUCores(connection));
+ list.add(getCPUUsed(connection));
+ list.add(getCPUTime(connection));
+ return list;
+ }
+
+ @Override
+ public List<MetricsListDataVO> getMemMetricsDataList(Connection connection) throws BaseException {
+ List<MetricsListDataVO> list = new ArrayList<>();
+ list.add(getTotalMem(connection));
+ list.add(getProcessRatio(connection));
+ return list;
+ }
+
+ @Override
+ public List<MetricsListDataVO> getDiskMetricsDataList(Connection connection)
+ throws BaseException {
+ List<MetricsListDataVO> 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<MetricsListDataVO> getWriteMetricsDataList(Connection connection)
+ throws BaseException {
+ List<MetricsListDataVO> 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<QueryClassificationVO> 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<MetricsListDataVO> 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<String> executeQueryOneLine(SessionPool sessionPool, String sql)
+ throws BaseException {
+ SessionDataSetWrapper sessionDataSetWrapper = null;
+ try {
+ List<String> valueList = new ArrayList<>();
+ sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
+ if (sessionDataSetWrapper.hasNext()) {
+ RowRecord rowRecord = sessionDataSetWrapper.next();
+ valueList.add(rowRecord.getTimestamp() + "");
+ List<org.apache.iotdb.tsfile.read.common.Field> 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();
+ }
+}
diff --git a/backend/src/main/resources/sqlite/iotdb.db b/backend/src/main/resources/sqlite/iotdb.db
index 9700849..26e0b25 100644
--- a/backend/src/main/resources/sqlite/iotdb.db
+++ b/backend/src/main/resources/sqlite/iotdb.db
Binary files differ