|
| 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 | +} |
0 commit comments