Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 21d9ebe

Browse files
committed
新增监控指标展示功能
- 该版本适配低于0.13版本的iotdb并提供数据库管理功能,但不提供监控管理(低于0.13版本iotdb不支持监控); - 仍然存在部分接口返回后端假数据,等待清华提供接口后替换为真实数据。
1 parent ff960d2 commit 21d9ebe

32 files changed

Lines changed: 2764 additions & 17 deletions

backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,57 @@ public BaseVO<DataModelVO> getDataModel(
9595
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
9696
}
9797

98+
@GetMapping("/dataModel/detail")
99+
@ApiOperation("Get IoTDB data model in detail")
100+
public BaseVO<DataModelVO> getDataModelDetail(
101+
@PathVariable("serverId") Integer serverId,
102+
@RequestParam(value = "path", required = false, defaultValue = "root") String path,
103+
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
104+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
105+
HttpServletRequest request)
106+
throws BaseException {
107+
check(request, serverId);
108+
Connection connection = connectionService.getById(serverId);
109+
DataModelVO dataModelVO = iotDBService.getDataModelDetail(connection, path, pageSize, pageNum);
110+
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
111+
}
112+
98113
@GetMapping("/storageGroups/info")
99114
@ApiOperation("Get information of the storage group list")
100-
public BaseVO<List<GroupInfoVO>> getAllStorageGroupsInfo(
101-
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
115+
public BaseVO<GroupInfoVO> getAllStorageGroupsInfo(
116+
@PathVariable("serverId") Integer serverId,
117+
@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
118+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
119+
HttpServletRequest request)
120+
throws BaseException {
102121
check(request, serverId);
103122
Connection connection = connectionService.getById(serverId);
104123
List<String> groupNames = iotDBService.getAllStorageGroups(connection);
105-
List<GroupInfoVO> groupInfoList = new ArrayList<>();
106-
if (groupNames == null || groupNames.size() == 0) {
107-
return BaseVO.success("Get successfully", groupInfoList);
124+
List<String> subGroupNames = new ArrayList<>();
125+
int size = groupNames.size();
126+
int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize;
127+
int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize;
128+
if (size > pageStart) {
129+
subGroupNames = groupNames.subList(pageStart, pageEnd);
130+
}
131+
List<GroupInfo> groupInfoList = new ArrayList<>();
132+
GroupInfoVO groupInfoVO = new GroupInfoVO();
133+
if (subGroupNames == null || subGroupNames.size() == 0) {
134+
return BaseVO.success("Get successfully", groupInfoVO);
108135
}
109136
String host = connection.getHost();
110-
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, groupNames);
111-
List<String> descriptions = groupService.getGroupDescription(host, groupNames);
112-
for (int i = 0; i < groupNames.size(); i++) {
113-
GroupInfoVO groupInfoVO = new GroupInfoVO();
114-
groupInfoVO.setGroupName(groupNames.get(i));
115-
groupInfoVO.setDeviceCount(deviceCounts.get(i));
116-
groupInfoVO.setDescription(descriptions.get(i));
117-
groupInfoList.add(groupInfoVO);
137+
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, subGroupNames);
138+
List<String> descriptions = groupService.getGroupDescription(host, subGroupNames);
139+
for (int i = 0; i < subGroupNames.size(); i++) {
140+
GroupInfo groupInfo = new GroupInfo();
141+
groupInfo.setGroupName(subGroupNames.get(i));
142+
groupInfo.setDeviceCount(deviceCounts.get(i));
143+
groupInfo.setDescription(descriptions.get(i));
144+
groupInfoList.add(groupInfo);
118145
}
119-
return BaseVO.success("Get successfully", groupInfoList);
146+
groupInfoVO.setGroupInfoList(groupInfoList);
147+
groupInfoVO.setGroupCount(size);
148+
return BaseVO.success("Get successfully", groupInfoVO);
120149
}
121150

122151
@GetMapping("/storageGroups")
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.iotdb.admin.controller;
20+
21+
import org.apache.iotdb.admin.common.exception.BaseException;
22+
import org.apache.iotdb.admin.common.utils.AuthenticationUtils;
23+
import org.apache.iotdb.admin.model.entity.Connection;
24+
import org.apache.iotdb.admin.model.vo.*;
25+
import org.apache.iotdb.admin.service.ConnectionService;
26+
import org.apache.iotdb.admin.service.IotDBService;
27+
import org.apache.iotdb.admin.service.MetricsService;
28+
29+
import io.swagger.annotations.Api;
30+
import io.swagger.annotations.ApiOperation;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.web.bind.annotation.*;
35+
36+
import javax.servlet.http.HttpServletRequest;
37+
38+
import java.util.ArrayList;
39+
import java.util.List;
40+
41+
/**
42+
* @author Erickin
43+
* @create 2022-04-22-上午 9:55
44+
*/
45+
@RestController
46+
@Api(value = "metrics related")
47+
public class MetricsController {
48+
49+
@Autowired private ConnectionService connectionService;
50+
@Autowired private IotDBService iotDBService;
51+
@Autowired private MetricsService metricsService;
52+
53+
private static final Logger logger = LoggerFactory.getLogger(MetricsController.class);
54+
55+
@GetMapping("/servers/metrics/connection")
56+
@ApiOperation("[metrics]Get All Connection")
57+
public BaseVO<List<MetricsConnectionVO>> getConnectionList(HttpServletRequest request)
58+
throws BaseException {
59+
Integer userId = AuthenticationUtils.getUserId(request);
60+
AuthenticationUtils.userAuthentication(userId, request);
61+
List<ConnVO> allConnections = connectionService.getAllConnections(userId);
62+
ArrayList<MetricsConnectionVO> metricsConnectionVOS = new ArrayList<>();
63+
for (ConnVO connVO : allConnections) {
64+
MetricsConnectionVO temp = new MetricsConnectionVO();
65+
temp.setId(connVO.getId());
66+
temp.setName(connVO.getAlias());
67+
metricsConnectionVOS.add(temp);
68+
}
69+
return BaseVO.success("Get Successfully", metricsConnectionVOS);
70+
}
71+
72+
@GetMapping("/servers/{serverId}/metrics/datacount")
73+
@ApiOperation("[metrics]Get Datacount")
74+
public BaseVO<MetricsDataCountVO> getMetricsConnectionDataCount(
75+
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
76+
check(request, serverId);
77+
MetricsDataCountVO metricsDataCountVO = metricsService.getMetricsDataCount(serverId);
78+
return BaseVO.success("Get IoTDB data statistics successfully", metricsDataCountVO);
79+
}
80+
81+
@GetMapping("/servers/{serverId}/metrics/QueryClassification")
82+
@ApiOperation("[metrics]Get all query classifications")
83+
public BaseVO<MetircsQueryClassificationVO> getAllQueryClassification(
84+
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
85+
check(request, serverId);
86+
MetircsQueryClassificationVO metircsQueryClassificationVO =
87+
metricsService.getMetircsQueryClassification(serverId);
88+
return BaseVO.success("Get IoTDB data statistics successfully", metircsQueryClassificationVO);
89+
}
90+
91+
@GetMapping("/servers/{serverId}/metrics/{queryClassificationId}/selectcount")
92+
@ApiOperation("[Metrics]Get detail information of query sql")
93+
public BaseVO<QueryInfoVO> getQueryInfo(
94+
@PathVariable("serverId") Integer serverId,
95+
@PathVariable("queryClassificationId") Integer queryClassificationId,
96+
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
97+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
98+
@RequestParam(value = "filterString", required = false) String filterString,
99+
@RequestParam(value = "startTime", required = false, defaultValue = "-1") String startTimeStr,
100+
@RequestParam(value = "endTime", required = false, defaultValue = "-1") String endTimeStr,
101+
@RequestParam(value = "executionResult", required = false) Integer executionResult,
102+
HttpServletRequest request)
103+
throws BaseException {
104+
check(request, serverId);
105+
QueryInfoVO queryInfoVO =
106+
metricsService.getQueryInfo(
107+
serverId,
108+
queryClassificationId,
109+
pageSize,
110+
pageNum,
111+
filterString,
112+
startTimeStr,
113+
endTimeStr,
114+
executionResult);
115+
return BaseVO.success("Get IoTDB query statement data statistics successfully", queryInfoVO);
116+
}
117+
118+
@GetMapping("/servers/{serverId}/metrics/diagram")
119+
@ApiOperation("Get metrics data for diagram")
120+
public BaseVO<MetricsDataForDiagramVO> getMetricsDataForDiagram(
121+
@PathVariable("serverId") Integer serverId,
122+
@RequestParam Integer metricId,
123+
HttpServletRequest request)
124+
throws BaseException {
125+
check(request, serverId);
126+
Connection connection = connectionService.getById(serverId);
127+
MetricsDataForDiagramVO metricsDataForDiagramVO =
128+
iotDBService.getMetricDataByMetricId(connection, metricId);
129+
metricsDataForDiagramVO.setServerId(serverId);
130+
return BaseVO.success("Get metrics data for diagram successfully", metricsDataForDiagramVO);
131+
}
132+
133+
@GetMapping("/servers/{serverId}/metrics/list/{metricsType}")
134+
@ApiOperation("Get metrics data for list")
135+
public BaseVO<MetricsDataForListVO> getMetricsDataForList(
136+
@PathVariable("serverId") Integer serverId,
137+
@PathVariable("metricsType") Integer metricsType,
138+
HttpServletRequest request)
139+
throws BaseException {
140+
check(request, serverId);
141+
MetricsDataForListVO metricsDataForListVO =
142+
metricsService.getMetricsDataForList(serverId, metricsType);
143+
return BaseVO.success("Get metrics data for list successfully", metricsDataForListVO);
144+
}
145+
146+
@GetMapping("/servers/{serverId}/metrics/list/query/{mode}")
147+
@ApiOperation("Get query metrics data for list")
148+
public BaseVO<QueryDataForListVO> getQueryMetricsDataForList(
149+
@PathVariable("serverId") Integer serverId, @PathVariable("mode") Integer mode)
150+
throws BaseException {
151+
QueryDataForListVO queryDataForListVO = new QueryDataForListVO();
152+
queryDataForListVO.setMode(mode);
153+
queryDataForListVO.setServerId(serverId);
154+
155+
if (mode == 1) {
156+
List<QueryMetricsVO> queryMetricsVOs = iotDBService.getTopQueryMetricsData();
157+
queryDataForListVO.setQueryMetricsVOs(queryMetricsVOs);
158+
159+
} else if (mode == 0) {
160+
List<QueryMetricsVO> queryMetricsVOs = iotDBService.getSlowQueryMetricsData();
161+
queryDataForListVO.setQueryMetricsVOs(queryMetricsVOs);
162+
}
163+
return BaseVO.success("Get query metrics data for list successfully", queryDataForListVO);
164+
}
165+
166+
private void check(HttpServletRequest request, Integer serverId) throws BaseException {
167+
Integer userId = AuthenticationUtils.getUserId(request);
168+
connectionService.check(serverId, userId);
169+
}
170+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.apache.iotdb.admin.mapper;
2+
3+
import org.apache.iotdb.admin.model.entity.ViewMode;
4+
5+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6+
import org.springframework.stereotype.Component;
7+
8+
/**
9+
* @author Erickin
10+
* @create 2022-04-22-上午 10:32
11+
*/
12+
@Component
13+
public interface ViewModeMapper extends BaseMapper<ViewMode> {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.apache.iotdb.admin.model.dto;
2+
3+
import lombok.Data;
4+
import org.apache.iotdb.admin.model.vo.DataModelVO;
5+
6+
import java.io.Serializable;
7+
import java.util.List;
8+
9+
@Data
10+
public class DataModelDetailDTO implements Serializable {
11+
private List<DataModelVO> dataModelVOList;
12+
private Integer pageNum;
13+
private Integer pageSize;
14+
private Integer total;
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.apache.iotdb.admin.model.dto;
2+
3+
import org.apache.iotdb.admin.model.vo.QueryDataStrVO;
4+
5+
import lombok.Data;
6+
7+
import java.util.List;
8+
9+
/**
10+
* @author Erickin
11+
* @create 2022-04-25-下午 5:12
12+
*/
13+
@Data
14+
public class QueryInfoDTO {
15+
private Long latestRunningTime;
16+
private Integer totalCount;
17+
private Integer totalPage;
18+
List<QueryDataStrVO> filteredQueryDataStrVOSList;
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.apache.iotdb.admin.model.entity;
2+
3+
import com.baomidou.mybatisplus.annotation.IdType;
4+
import com.baomidou.mybatisplus.annotation.TableId;
5+
import com.baomidou.mybatisplus.annotation.TableName;
6+
import lombok.Data;
7+
8+
import javax.validation.constraints.NotBlank;
9+
import javax.validation.constraints.Null;
10+
import javax.validation.constraints.Pattern;
11+
12+
import java.io.Serializable;
13+
14+
/**
15+
* @author Erickin
16+
* @create 2022-04-22-上午 10:35
17+
*/
18+
@Data
19+
@TableName("view_mode")
20+
public class ViewMode implements Serializable {
21+
private static final long serialVersionUID = 1L;
22+
23+
@Null
24+
@TableId(type = IdType.AUTO)
25+
private Integer id;
26+
27+
@NotBlank
28+
@Pattern(regexp = "^[^ ]+$", message = "The account name cannot contain spaces")
29+
private String name;
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.apache.iotdb.admin.model.metricsDo;
2+
3+
import org.apache.iotdb.admin.model.vo.QueryDataVO;
4+
5+
import lombok.Data;
6+
7+
import java.util.List;
8+
9+
/**
10+
* @author Erickin
11+
* @create 2022-04-26-上午 9:28
12+
*/
13+
@Data
14+
public class QueryDataDo {
15+
private List<QueryDataVO> QueryDataVOs;
16+
private Long latestTimeStamp;
17+
private Integer count;
18+
}

backend/src/main/java/org/apache/iotdb/admin/model/vo/DataModelVO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public class DataModelVO implements Serializable {
4747

4848
private List<DataModelVO> children;
4949

50+
private Integer showNum;
51+
52+
private Integer pageNum;
53+
54+
private Integer pageSize;
55+
56+
private Integer total;
57+
58+
private Integer totalSonNodeCount;
59+
5060
public DataModelVO(String name) {
5161
this.name = name;
5262
this.isGroup = false;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.apache.iotdb.admin.model.vo;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
@Data
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class GroupInfo implements Serializable {
13+
private String groupName;
14+
private Integer deviceCount;
15+
private String description;
16+
}

backend/src/main/java/org/apache/iotdb/admin/model/vo/GroupInfoVO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import lombok.NoArgsConstructor;
2525

2626
import java.io.Serializable;
27+
import java.util.List;
2728

2829
@Data
2930
@NoArgsConstructor
3031
@AllArgsConstructor
3132
public class GroupInfoVO implements Serializable {
32-
private String groupName;
33-
private Integer deviceCount;
34-
private String description;
33+
private Integer groupCount;
34+
private List<GroupInfo> groupInfoList;
3535
}

0 commit comments

Comments
 (0)