已关闭
回滚实例监控代码,此代码导致打包不成功 #318
Louisyzh创建于 2023年7月5日关闭于 2023年7月6日
回滚实例监控代码,此代码导致打包不成功 #318
已关闭
从refs/pull/318/head合入到master
共 9 个文件变更+2605-163
| @@ -9,6 +9,7 @@ | |||
| 9 | <plugin-id>observability-instance</plugin-id> | 9 | <plugin-id>observability-instance</plugin-id> |
| 10 | <npm.run.script>buildNoTest</npm.run.script> | 10 | <npm.run.script>buildNoTest</npm.run.script> |
| 11 | <web.build.skip>false</web.build.skip> | 11 | <web.build.skip>false</web.build.skip> |
| 12 | + <web.clean.skip>false</web.clean.skip> | ||
| 12 | <!--project--> | 13 | <!--project--> |
| 13 | <java.version>11</java.version> | 14 | <java.version>11</java.version> |
| 14 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 15 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| @@ -170,7 +171,7 @@ | |||
| 170 | <followSymlinks>false</followSymlinks> | 171 | <followSymlinks>false</followSymlinks> |
| 171 | </fileset> | 172 | </fileset> |
| 172 | </filesets> | 173 | </filesets> |
| 173 | - <skip>${web.build.skip}</skip> | 174 | + <skip>${web.clean.skip}</skip> |
| 174 | <failOnError>true</failOnError> | 175 | <failOnError>true</failOnError> |
| 175 | </configuration> | 176 | </configuration> |
| 176 | </plugin> | 177 | </plugin> |
Mplugins/observability-instance/src/main/java/com/nctigba/observability/instance/constants/MetricsLine.java+3-2
| @@ -79,8 +79,9 @@ public enum MetricsLine { | |||
| 79 | NETWORK_TCP_INSEGS(Type.OS, "rate(agent_netstat_Tcp_InSegs{host='ogbrench'}[5m])"), | 79 | NETWORK_TCP_INSEGS(Type.OS, "rate(agent_netstat_Tcp_InSegs{host='ogbrench'}[5m])"), |
| 80 | NETWORK_TCP_OUTSEGS(Type.OS, "rate(agent_netstat_Tcp_OutSegs{host='ogbrench'}[5m])"), | 80 | NETWORK_TCP_OUTSEGS(Type.OS, "rate(agent_netstat_Tcp_OutSegs{host='ogbrench'}[5m])"), |
| 81 | 81 | ||
| 82 | - NETWORK_TCP_SOCKET(Type.OS, "agent_network_socket{proto=~'tcp|tcp6',host='ogbrench'} by (state)", "{state}"), | 82 | + NETWORK_TCP_SOCKET(Type.OS, "sum(rate(agent_network_socket{proto=~'tcp|tcp6',host='ogbrench'}[1m])) by (state)", |
| 83 | - NETWORK_UDP_SOCKET(Type.OS, "agent_network_socket{proto=~'udp|udp6',host='ogbrench'}"), | 83 | + "{state}"), |
| 84 | + NETWORK_UDP_SOCKET(Type.OS, "sum(rate(agent_network_socket{proto=~'udp|udp6',host='ogbrench'}[1m]))"), | ||
| 84 | 85 | ||
| 85 | // opengauss instance | 86 | // opengauss instance |
| 86 | INSTANCE_TPS_COMMIT(Type.DB, "sum(irate(pg_stat_database_xact_rollback_total{instanceId='ogbrench'}[5m]))"), | 87 | INSTANCE_TPS_COMMIT(Type.DB, "sum(irate(pg_stat_database_xact_rollback_total{instanceId='ogbrench'}[5m]))"), |
Mplugins/observability-instance/src/main/java/com/nctigba/observability/instance/controller/PageController.java+86-97
| @@ -1,7 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) GBA-NCTI-ISDC. 2022-2023. All rights reserved. | 2 | * Copyright (c) GBA-NCTI-ISDC. 2022-2023. All rights reserved. |
| 3 | */ | 3 | */ |
| 4 | - | ||
| 5 | package com.nctigba.observability.instance.controller; | 4 | package com.nctigba.observability.instance.controller; |
| 6 | 5 | ||
| 7 | import java.util.HashMap; | 6 | import java.util.HashMap; |
| @@ -28,7 +27,12 @@ import lombok.RequiredArgsConstructor; | |||
| 28 | 27 | ||
| 29 | 28 | ||
| 30 | public class PageController extends ControllerConfig { | 29 | public class PageController extends ControllerConfig { |
| 31 | - private static final Enum<?>[] MEMORY = { | 30 | + private final MetricsService metricsService; |
| 31 | + private final DbConfigMapper dbConfigMapper; | ||
| 32 | + private final ClusterManager clusterManager; | ||
| 33 | + private final MessageSource messageSource; | ||
| 34 | + | ||
| 35 | + private static final Object[] MEMORY = { | ||
| 32 | MetricsLine.MEMORY_USED, | 36 | MetricsLine.MEMORY_USED, |
| 33 | MetricsLine.MEMORY_DB_USED, | 37 | MetricsLine.MEMORY_DB_USED, |
| 34 | MetricsValue.MEM_TOTAL, | 38 | MetricsValue.MEM_TOTAL, |
| @@ -38,8 +42,30 @@ public class PageController extends ControllerConfig { | |||
| 38 | MetricsValue.SWAP_TOTAL, | 42 | MetricsValue.SWAP_TOTAL, |
| 39 | MetricsValue.SWAP_USED, | 43 | MetricsValue.SWAP_USED, |
| 40 | MetricsValue.SWAP_FREE, | 44 | MetricsValue.SWAP_FREE, |
| 41 | - MetricsLine.MEMORY_SWAP | 45 | + MetricsLine.MEMORY_SWAP, }; |
| 42 | - }; | 46 | + |
| 47 | + | ||
| 48 | + public Map<String, Object> memory(String id, Long start, Long end, Integer step) { | ||
| 49 | + HashMap<String, Object> batch = metricsService.listBatch(MEMORY, id, start, end, step); | ||
| 50 | + clusterManager.setCurrentDatasource(id, null); | ||
| 51 | + // memory node detail | ||
| 52 | + List<Map<String, Object>> memoryNodeDetail = dbConfigMapper.memoryNodeDetail(); | ||
| 53 | + memoryNodeDetail.forEach(map -> { | ||
| 54 | + var str = map.get("memorytype").toString(); | ||
| 55 | + map.put("desc", messageSource.getMessage("memory.node." + str, null, str, Language.getLocale())); | ||
| 56 | + }); | ||
| 57 | + batch.put("memoryNodeDetail", memoryNodeDetail); | ||
| 58 | + // memory config detail | ||
| 59 | + List<Map<String, Object>> memoryConfig = dbConfigMapper.memoryConfig(); | ||
| 60 | + memoryConfig.forEach(map -> { | ||
| 61 | + var str = map.get("name").toString(); | ||
| 62 | + map.put("desc", messageSource.getMessage("memory.config." + str, null, str, Language.getLocale())); | ||
| 63 | + }); | ||
| 64 | + batch.put("memoryConfig", memoryConfig); | ||
| 65 | + clusterManager.pool(); | ||
| 66 | + return AjaxResult.success(batch); | ||
| 67 | + } | ||
| 68 | + | ||
| 43 | private static final MetricsLine[] IO = { | 69 | private static final MetricsLine[] IO = { |
| 44 | MetricsLine.IOPS_R, | 70 | MetricsLine.IOPS_R, |
| 45 | MetricsLine.IOPS_W, | 71 | MetricsLine.IOPS_W, |
| @@ -49,8 +75,7 @@ public class PageController extends ControllerConfig { | |||
| 49 | MetricsLine.IO_UTIL, | 75 | MetricsLine.IO_UTIL, |
| 50 | MetricsLine.IO_AVG_REPONSE_TIME_READ, | 76 | MetricsLine.IO_AVG_REPONSE_TIME_READ, |
| 51 | MetricsLine.IO_AVG_REPONSE_TIME_WRITE, | 77 | MetricsLine.IO_AVG_REPONSE_TIME_WRITE, |
| 52 | - MetricsLine.IO_AVG_REPONSE_TIME_RW | 78 | + MetricsLine.IO_AVG_REPONSE_TIME_RW, }; |
| 53 | - }; | ||
| 54 | 79 | ||
| 55 | private static final MetricsValue[] IO_TABLE = { | 80 | private static final MetricsValue[] IO_TABLE = { |
| 56 | MetricsValue.IO_TPS, | 81 | MetricsValue.IO_TPS, |
| @@ -59,8 +84,31 @@ public class PageController extends ControllerConfig { | |||
| 59 | MetricsValue.IO_AVGRQ_SZ, | 84 | MetricsValue.IO_AVGRQ_SZ, |
| 60 | MetricsValue.IO_AVGQU_SZ, | 85 | MetricsValue.IO_AVGQU_SZ, |
| 61 | MetricsValue.IO_AWAIT, | 86 | MetricsValue.IO_AWAIT, |
| 62 | - MetricsValue.IO_UTIL | 87 | + MetricsValue.IO_UTIL }; |
| 63 | - }; | 88 | + |
| 89 | + | ||
| 90 | + | ||
| 91 | + public Map<String, Object> io(String id, Long start, Long end, Integer step) { | ||
| 92 | + HashMap<String, Object> io = metricsService.listBatch(IO, id, start, end, step); | ||
| 93 | + HashMap<String, Object> table = metricsService.listBatch(IO_TABLE, id, start, end, step); | ||
| 94 | + HashMap<String, Object> lines = new HashMap<>(); | ||
| 95 | + for (MetricsValue m : IO_TABLE) { | ||
| 96 | + var map = (HashMap<String, Object>) table.get(m.name()); | ||
| 97 | + if (map == null) | ||
| 98 | + continue; | ||
| 99 | + map.forEach((k, v) -> { | ||
| 100 | + if (!lines.containsKey(k)) { | ||
| 101 | + HashMap<String, Object> line = new HashMap<String, Object>(); | ||
| 102 | + line.put("device", k); | ||
| 103 | + lines.put(k, line); | ||
| 104 | + } | ||
| 105 | + ((HashMap<String, Object>) lines.get(k)).put(m.name(), v); | ||
| 106 | + }); | ||
| 107 | + } | ||
| 108 | + io.put("table", lines.values().stream().collect(Collectors.toList())); | ||
| 109 | + return AjaxResult.success(io); | ||
| 110 | + } | ||
| 111 | + | ||
| 64 | private static final MetricsLine[] NETWORK = { | 112 | private static final MetricsLine[] NETWORK = { |
| 65 | MetricsLine.NETWORK_IN, | 113 | MetricsLine.NETWORK_IN, |
| 66 | MetricsLine.NETWORK_OUT, | 114 | MetricsLine.NETWORK_OUT, |
| @@ -70,8 +118,7 @@ public class PageController extends ControllerConfig { | |||
| 70 | MetricsLine.NETWORK_TCP_INSEGS, | 118 | MetricsLine.NETWORK_TCP_INSEGS, |
| 71 | MetricsLine.NETWORK_TCP_OUTSEGS, | 119 | MetricsLine.NETWORK_TCP_OUTSEGS, |
| 72 | MetricsLine.NETWORK_TCP_SOCKET, | 120 | MetricsLine.NETWORK_TCP_SOCKET, |
| 73 | - MetricsLine.NETWORK_UDP_SOCKET | 121 | + MetricsLine.NETWORK_UDP_SOCKET, }; |
| 74 | - }; | ||
| 75 | 122 | ||
| 76 | private static final MetricsValue[] NETWORK_TABLE = { | 123 | private static final MetricsValue[] NETWORK_TABLE = { |
| 77 | MetricsValue.NETWORK_RXPCK, | 124 | MetricsValue.NETWORK_RXPCK, |
| @@ -83,8 +130,31 @@ public class PageController extends ControllerConfig { | |||
| 83 | MetricsValue.NETWORK_RXDROP, | 130 | MetricsValue.NETWORK_RXDROP, |
| 84 | MetricsValue.NETWORK_TXDROP, | 131 | MetricsValue.NETWORK_TXDROP, |
| 85 | MetricsValue.NETWORK_RXFIFO, | 132 | MetricsValue.NETWORK_RXFIFO, |
| 86 | - MetricsValue.NETWORK_TXFIFO | 133 | + MetricsValue.NETWORK_TXFIFO, }; |
| 87 | - }; | 134 | + |
| 135 | + | ||
| 136 | + | ||
| 137 | + public Map<String, Object> network(String id, Long start, Long end, Integer step) { | ||
| 138 | + HashMap<String, Object> network = metricsService.listBatch(NETWORK, id, start, end, step); | ||
| 139 | + HashMap<String, Object> table = metricsService.listBatch(NETWORK_TABLE, id, start, end, step); | ||
| 140 | + HashMap<String, Object> lines = new HashMap<>(); | ||
| 141 | + for (MetricsValue m : NETWORK_TABLE) { | ||
| 142 | + var map = (HashMap<String, Object>) table.get(m.name()); | ||
| 143 | + if (map == null) | ||
| 144 | + continue; | ||
| 145 | + map.forEach((k, v) -> { | ||
| 146 | + if (!lines.containsKey(k)) { | ||
| 147 | + HashMap<String, Object> line = new HashMap<String, Object>(); | ||
| 148 | + line.put("device", k); | ||
| 149 | + lines.put(k, line); | ||
| 150 | + } | ||
| 151 | + ((HashMap<String, Object>) lines.get(k)).put(m.name(), v); | ||
| 152 | + }); | ||
| 153 | + } | ||
| 154 | + network.put("table", lines.values().stream().collect(Collectors.toList())); | ||
| 155 | + return AjaxResult.success(network); | ||
| 156 | + } | ||
| 157 | + | ||
| 88 | private static final MetricsLine[] INSTANCE = { | 158 | private static final MetricsLine[] INSTANCE = { |
| 89 | MetricsLine.INSTANCE_TPS_COMMIT, | 159 | MetricsLine.INSTANCE_TPS_COMMIT, |
| 90 | MetricsLine.INSTANCE_TPS_ROLLBACK, | 160 | MetricsLine.INSTANCE_TPS_ROLLBACK, |
| @@ -94,98 +164,17 @@ public class PageController extends ControllerConfig { | |||
| 94 | MetricsLine.INSTANCE_DB_CONNECTION_IDLE, | 164 | MetricsLine.INSTANCE_DB_CONNECTION_IDLE, |
| 95 | MetricsLine.INSTANCE_DB_CONNECTION_CURR, | 165 | MetricsLine.INSTANCE_DB_CONNECTION_CURR, |
| 96 | MetricsLine.INSTANCE_DB_CONNECTION_TOTAL, | 166 | MetricsLine.INSTANCE_DB_CONNECTION_TOTAL, |
| 97 | - MetricsLine.INSTANCE_DB_SLOWSQL | 167 | + MetricsLine.INSTANCE_DB_SLOWSQL, }; |
| 98 | - }; | ||
| 99 | - private static final MetricsLine[] WAIT_EVENT = { | ||
| 100 | - MetricsLine.WAIT_EVENT_COUNT | ||
| 101 | - }; | ||
| 102 | - | ||
| 103 | - private final MetricsService metricsService; | ||
| 104 | - private final DbConfigMapper dbConfigMapper; | ||
| 105 | - private final ClusterManager clusterManager; | ||
| 106 | - private final MessageSource messageSource; | ||
| 107 | - private final Language language; | ||
| 108 | - | ||
| 109 | - | ||
| 110 | - public Map<String, Object> memory(String id, Long start, Long end, Integer step) { | ||
| 111 | - HashMap<String, Object> batch = metricsService.listBatch(MEMORY, id, start, end, step); | ||
| 112 | - try { | ||
| 113 | - clusterManager.setCurrentDatasource(id, null); | ||
| 114 | - // memory node detail | ||
| 115 | - List<Map<String, Object>> memoryNodeDetail = dbConfigMapper.memoryNodeDetail(); | ||
| 116 | - memoryNodeDetail.forEach(map -> { | ||
| 117 | - var str = map.get("memorytype").toString(); | ||
| 118 | - map.put("desc", messageSource.getMessage("memory.node." + str, null, str, language.getLocale())); | ||
| 119 | - }); | ||
| 120 | - batch.put("memoryNodeDetail", memoryNodeDetail); | ||
| 121 | - // memory config detail | ||
| 122 | - List<Map<String, Object>> memoryConfig = dbConfigMapper.memoryConfig(); | ||
| 123 | - memoryConfig.forEach(map -> { | ||
| 124 | - var str = map.get("name").toString(); | ||
| 125 | - map.put("desc", messageSource.getMessage("memory.config." + str, null, str, language.getLocale())); | ||
| 126 | - }); | ||
| 127 | - batch.put("memoryConfig", memoryConfig); | ||
| 128 | - } finally { | ||
| 129 | - clusterManager.pool(); | ||
| 130 | - } | ||
| 131 | - return AjaxResult.success(batch); | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - | ||
| 135 | - | ||
| 136 | - public Map<String, Object> io(String id, Long start, Long end, Integer step) { | ||
| 137 | - HashMap<String, Object> io = metricsService.listBatch(IO, id, start, end, step); | ||
| 138 | - HashMap<String, Object> table = metricsService.listBatch(IO_TABLE, id, start, end, step); | ||
| 139 | - HashMap<String, Object> lines = new HashMap<>(); | ||
| 140 | - for (MetricsValue metric : IO_TABLE) { | ||
| 141 | - var map = (HashMap<String, Object>) table.get(metric.name()); | ||
| 142 | - if (map == null) { | ||
| 143 | - continue; | ||
| 144 | - } | ||
| 145 | - map.forEach((k, v) -> { | ||
| 146 | - if (!lines.containsKey(k)) { | ||
| 147 | - HashMap<String, Object> line = new HashMap<>(); | ||
| 148 | - line.put("device", k); | ||
| 149 | - lines.put(k, line); | ||
| 150 | - } | ||
| 151 | - ((HashMap<String, Object>) lines.get(k)).put(metric.name(), v); | ||
| 152 | - }); | ||
| 153 | - } | ||
| 154 | - io.put("table", lines.values().stream().collect(Collectors.toList())); | ||
| 155 | - return AjaxResult.success(io); | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - | ||
| 160 | - public Map<String, Object> network(String id, Long start, Long end, Integer step) { | ||
| 161 | - HashMap<String, Object> network = metricsService.listBatch(NETWORK, id, start, end, step); | ||
| 162 | - HashMap<String, Object> table = metricsService.listBatch(NETWORK_TABLE, id, start, end, step); | ||
| 163 | - HashMap<String, Object> lines = new HashMap<>(); | ||
| 164 | - for (MetricsValue metric : NETWORK_TABLE) { | ||
| 165 | - var map = (HashMap<String, Object>) table.get(metric.name()); | ||
| 166 | - if (map == null) { | ||
| 167 | - continue; | ||
| 168 | - } | ||
| 169 | - map.forEach((k, v) -> { | ||
| 170 | - if (!lines.containsKey(k)) { | ||
| 171 | - HashMap<String, Object> line = new HashMap<>(); | ||
| 172 | - line.put("device", k); | ||
| 173 | - lines.put(k, line); | ||
| 174 | - } | ||
| 175 | - ((HashMap<String, Object>) lines.get(k)).put(metric.name(), v); | ||
| 176 | - }); | ||
| 177 | - } | ||
| 178 | - network.put("table", lines.values().stream().collect(Collectors.toList())); | ||
| 179 | - return AjaxResult.success(network); | ||
| 180 | - } | ||
| 181 | 168 | ||
| 182 | 169 | ||
| 183 | public Map<String, Object> instance(String id, Long start, Long end, Integer step) { | 170 | public Map<String, Object> instance(String id, Long start, Long end, Integer step) { |
| 184 | return AjaxResult.success(metricsService.listBatch(INSTANCE, id, start, end, step)); | 171 | return AjaxResult.success(metricsService.listBatch(INSTANCE, id, start, end, step)); |
| 185 | } | 172 | } |
| 186 | 173 | ||
| 174 | + private static final MetricsLine[] WAIT_EVENT = { MetricsLine.WAIT_EVENT_COUNT, }; | ||
| 175 | + | ||
| 187 | 176 | ||
| 188 | - public Map<String, Object> waitEvent(String id, Long start, Long end, Integer step) { | 177 | + public Map<String, Object> wait_event(String id, Long start, Long end, Integer step) { |
| 189 | return AjaxResult.success(metricsService.listBatch(WAIT_EVENT, id, start, end, step)); | 178 | return AjaxResult.success(metricsService.listBatch(WAIT_EVENT, id, start, end, step)); |
| 190 | } | 179 | } |
| 191 | 180 | ||
Mplugins/observability-instance/src/main/java/com/nctigba/observability/instance/service/ExporterInstallService.java+0-16
| @@ -91,22 +91,6 @@ public class ExporterInstallService extends AbstractInstaller { | |||
| 91 | }).findFirst().orElse(null); | 91 | }).findFirst().orElse(null); |
| 92 | try (var session = SshSession.connect(hostEntity.getPublicIp(), hostEntity.getPort(), user.getUsername(), | 92 | try (var session = SshSession.connect(hostEntity.getPublicIp(), hostEntity.getPort(), user.getUsername(), |
| 93 | encryptionUtils.decrypt(user.getPassword()));) { | 93 | encryptionUtils.decrypt(user.getPassword()));) { |
| 94 | - // check port | ||
| 95 | - try { | ||
| 96 | - if (StrUtil.isNotBlank(session.execute("ss -tuln | grep " + httpPort))) { | ||
| 97 | - throw new CustomException("port in use:" + httpPort); | ||
| 98 | - } | ||
| 99 | - } catch (CustomException e) { | ||
| 100 | - throw new CustomException("port in use:" + httpPort); | ||
| 101 | - } | ||
| 102 | - try { | ||
| 103 | - if (StrUtil.isNotBlank(session.execute("ss -tuln | grep " + exporterPort))) { | ||
| 104 | - throw new CustomException("port in use:" + httpPort); | ||
| 105 | - } | ||
| 106 | - } catch (CustomException e) { | ||
| 107 | - throw new CustomException("port in use:" + httpPort); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | expEnv = envMapper.selectOne(Wrappers.<NctigbaEnv>lambdaQuery().eq(NctigbaEnv::getHostid, hostId) | 94 | expEnv = envMapper.selectOne(Wrappers.<NctigbaEnv>lambdaQuery().eq(NctigbaEnv::getHostid, hostId) |
| 111 | .eq(NctigbaEnv::getType, envType.EXPORTER).eq(NctigbaEnv::getNodeid, nodeId)); | 95 | .eq(NctigbaEnv::getType, envType.EXPORTER).eq(NctigbaEnv::getNodeid, nodeId)); |
| 112 | session.execute("mkdir -p " + path); | 96 | session.execute("mkdir -p " + path); |
Mplugins/observability-instance/src/main/java/com/nctigba/observability/instance/service/MetricsService.java+35-41
| @@ -1,7 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) GBA-NCTI-ISDC. 2022-2023. All rights reserved. | 2 | * Copyright (c) GBA-NCTI-ISDC. 2022-2023. All rights reserved. |
| 3 | */ | 3 | */ |
| 4 | - | ||
| 5 | package com.nctigba.observability.instance.service; | 4 | package com.nctigba.observability.instance.service; |
| 6 | 5 | ||
| 7 | import java.util.ArrayList; | 6 | import java.util.ArrayList; |
| @@ -13,19 +12,20 @@ import java.util.Map; | |||
| 13 | import java.util.concurrent.TimeUnit; | 12 | import java.util.concurrent.TimeUnit; |
| 14 | import java.util.stream.Collectors; | 13 | import java.util.stream.Collectors; |
| 15 | 14 | ||
| 16 | -import org.opengauss.admin.common.exception.CustomException; | ||
| 17 | import org.opengauss.admin.system.plugin.facade.HostFacade; | 15 | import org.opengauss.admin.system.plugin.facade.HostFacade; |
| 18 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 19 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 20 | 18 | ||
| 21 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 19 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| 22 | import com.gitee.starblues.bootstrap.annotation.AutowiredType; | 20 | import com.gitee.starblues.bootstrap.annotation.AutowiredType; |
| 21 | +import com.nctigba.common.web.exception.CustomException; | ||
| 23 | import com.nctigba.observability.instance.constants.MetricsLine; | 22 | import com.nctigba.observability.instance.constants.MetricsLine; |
| 24 | import com.nctigba.observability.instance.constants.MetricsValue; | 23 | import com.nctigba.observability.instance.constants.MetricsValue; |
| 25 | import com.nctigba.observability.instance.constants.MonitoringConstants; | 24 | import com.nctigba.observability.instance.constants.MonitoringConstants; |
| 26 | import com.nctigba.observability.instance.entity.NctigbaEnv; | 25 | import com.nctigba.observability.instance.entity.NctigbaEnv; |
| 26 | +import com.nctigba.observability.instance.entity.NctigbaEnv.envType; | ||
| 27 | import com.nctigba.observability.instance.mapper.NctigbaEnvMapper; | 27 | import com.nctigba.observability.instance.mapper.NctigbaEnvMapper; |
| 28 | -import com.nctigba.observability.instance.service.MetricsService.PrometheusResult.PromData.MonitoringMetric; | 28 | +import com.nctigba.observability.instance.service.MetricsService.prometheusResult.data.monitoringMetric; |
| 29 | import com.nctigba.observability.instance.util.ListUtil; | 29 | import com.nctigba.observability.instance.util.ListUtil; |
| 30 | 30 | ||
| 31 | import cn.hutool.core.thread.ThreadUtil; | 31 | import cn.hutool.core.thread.ThreadUtil; |
| @@ -53,46 +53,42 @@ public class MetricsService { | |||
| 53 | if (PROM.containsKey(DEFAULT)) { | 53 | if (PROM.containsKey(DEFAULT)) { |
| 54 | return PROM.get(DEFAULT); | 54 | return PROM.get(DEFAULT); |
| 55 | } | 55 | } |
| 56 | - var env = envMapper | 56 | + var env = envMapper.selectOne(Wrappers.<NctigbaEnv>lambdaQuery().eq(NctigbaEnv::getType, envType.PROMETHEUS)); |
| 57 | - .selectOne(Wrappers.<NctigbaEnv>lambdaQuery().eq(NctigbaEnv::getType, NctigbaEnv.envType.PROMETHEUS)); | 57 | + if (env == null) |
| 58 | - if (env == null) { | 58 | + throw new RuntimeException("Prometheus not found"); |
| 59 | - throw new CustomException("Prometheus not found"); | ||
| 60 | - } | ||
| 61 | var host = hostFacade.getById(env.getHostid()); | 59 | var host = hostFacade.getById(env.getHostid()); |
| 62 | String url = "http://" + host.getPublicIp() + ":" + env.getPort(); | 60 | String url = "http://" + host.getPublicIp() + ":" + env.getPort(); |
| 63 | PROM.put(DEFAULT, url); | 61 | PROM.put(DEFAULT, url); |
| 64 | return url; | 62 | return url; |
| 65 | } | 63 | } |
| 66 | 64 | ||
| 67 | - private PrometheusResult query(String type, String query, Map<String, Object> param) { | 65 | + private prometheusResult query(String type, String query, Map<String, Object> param) { |
| 68 | String baseUrl = getPrometheusUrl() + type; | 66 | String baseUrl = getPrometheusUrl() + type; |
| 69 | var result = HttpUtil.get(baseUrl, param); | 67 | var result = HttpUtil.get(baseUrl, param); |
| 70 | - var prometheusResult = JSONUtil.toBean(result, PrometheusResult.class); | 68 | + var prometheusResult = JSONUtil.toBean(result, prometheusResult.class); |
| 71 | prometheusResult.isSuccess(); | 69 | prometheusResult.isSuccess(); |
| 72 | return prometheusResult; | 70 | return prometheusResult; |
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | - private List<MonitoringMetric> value(String query, Long time) { | 73 | + public List<monitoringMetric> value(String query, Long time) { |
| 76 | - if (StrUtil.isBlank(query)) { | 74 | + if (StrUtil.isBlank(query)) |
| 77 | throw new NullPointerException("query null"); | 75 | throw new NullPointerException("query null"); |
| 78 | - } | 76 | + log.info("promQL:{},time:{}", query, time); |
| 79 | - log.info("promQL:{}, time:{}", query, time); | ||
| 80 | var prometheusResult = query(MonitoringConstants.PROMETHEUS_QUERY_POINT, query, | 77 | var prometheusResult = query(MonitoringConstants.PROMETHEUS_QUERY_POINT, query, |
| 81 | Map.of("query", query, "time", time)); | 78 | Map.of("query", query, "time", time)); |
| 82 | return prometheusResult.getData().getResult(); | 79 | return prometheusResult.getData().getResult(); |
| 83 | } | 80 | } |
| 84 | 81 | ||
| 85 | - private List<MonitoringMetric> list(String query, Number start, Number end, Integer step) { | 82 | + public List<monitoringMetric> list(String query, Number start, Number end, Integer step) { |
| 86 | - if (StrUtil.isBlank(query)) { | 83 | + if (StrUtil.isBlank(query)) |
| 87 | return Collections.emptyList(); | 84 | return Collections.emptyList(); |
| 88 | - } | 85 | + log.info("promQL:{},start:{},end:{},step:{}", query, start, end, step); |
| 89 | - log.info("promQL:{}, start:{}, end:{}, step:{}", query, start, end, step); | ||
| 90 | var prometheusResult = query(MonitoringConstants.PROMETHEUS_QUERY_RANGE, query, | 86 | var prometheusResult = query(MonitoringConstants.PROMETHEUS_QUERY_RANGE, query, |
| 91 | Map.of("query", query, "start", start, "end", end, "step", step)); | 87 | Map.of("query", query, "start", start, "end", end, "step", step)); |
| 92 | return prometheusResult.getData().getResult(); | 88 | return prometheusResult.getData().getResult(); |
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | - public HashMap<String, Object> listBatch(Enum<?>[] metricsArr, String nodeId, Long start, Long end, Integer step) { | 91 | + public HashMap<String, Object> listBatch(Object[] metricsArr, String nodeId, Long start, Long end, Integer step) { |
| 96 | var result = new HashMap<String, Object>(); | 92 | var result = new HashMap<String, Object>(); |
| 97 | var node = clusterManager.getOpsNodeById(nodeId); | 93 | var node = clusterManager.getOpsNodeById(nodeId); |
| 98 | var hostId = node.getHostId(); | 94 | var hostId = node.getHostId(); |
| @@ -106,10 +102,10 @@ public class MetricsService { | |||
| 106 | ThreadUtil.execute(() -> { | 102 | ThreadUtil.execute(() -> { |
| 107 | try { | 103 | try { |
| 108 | if (metric instanceof MetricsLine) { | 104 | if (metric instanceof MetricsLine) { |
| 109 | - MetricsLine metricLine = (MetricsLine) metric; | 105 | + MetricsLine m = (MetricsLine) metric; |
| 110 | - String promQl = metricLine.promQl(hostId, nodeId); | 106 | + String promQl = m.promQl(hostId, nodeId); |
| 111 | - var metrics = list(metricLine.promQl(hostId, nodeId), start, end, step); | 107 | + var metrics = list(promQl, start, end, step); |
| 112 | - result.put(metricLine.name(), parseLine(promQl, metrics, timeline, metricLine.getTemplate())); | 108 | + result.put(m.name(), parseLine(promQl, metrics, timeline, m.getTemplate())); |
| 113 | return; | 109 | return; |
| 114 | } | 110 | } |
| 115 | if (metric instanceof MetricsValue) { | 111 | if (metric instanceof MetricsValue) { |
| @@ -131,14 +127,14 @@ public class MetricsService { | |||
| 131 | return result; | 127 | return result; |
| 132 | } | 128 | } |
| 133 | 129 | ||
| 134 | - private Object parseValue(String promQl, List<MonitoringMetric> metric, String template) { | 130 | + private Object parseValue(String promQl, List<monitoringMetric> metric, String template) { |
| 135 | if (metric.size() == 0) { | 131 | if (metric.size() == 0) { |
| 136 | return null; | 132 | return null; |
| 137 | } else if (metric.size() == 1) { | 133 | } else if (metric.size() == 1) { |
| 138 | return metric.get(0).getValue().get(1); | 134 | return metric.get(0).getValue().get(1); |
| 139 | } else { | 135 | } else { |
| 140 | var map = new HashMap<String, Object>(); | 136 | var map = new HashMap<String, Object>(); |
| 141 | - for (var monitoringMetric : metric) { | 137 | + for (monitoringMetric monitoringMetric : metric) { |
| 142 | if (template == null) | 138 | if (template == null) |
| 143 | throw new NullPointerException(promQl); | 139 | throw new NullPointerException(promQl); |
| 144 | String key = StrUtil.format(template, monitoringMetric.getMetric()); | 140 | String key = StrUtil.format(template, monitoringMetric.getMetric()); |
| @@ -148,17 +144,16 @@ public class MetricsService { | |||
| 148 | } | 144 | } |
| 149 | } | 145 | } |
| 150 | 146 | ||
| 151 | - private Object parseLine(String promQl, List<MonitoringMetric> metric, List<Long> timeline, String template) { | 147 | + private Object parseLine(String promQl, List<monitoringMetric> metric, List<Long> timeline, String template) { |
| 152 | if (metric.size() == 0) { | 148 | if (metric.size() == 0) { |
| 153 | return null; | 149 | return null; |
| 154 | } else if (metric.size() == 1) { | 150 | } else if (metric.size() == 1) { |
| 155 | return ListUtil.collect(metric.get(0).getValues(), timeline); | 151 | return ListUtil.collect(metric.get(0).getValues(), timeline); |
| 156 | } else { | 152 | } else { |
| 157 | var map = new HashMap<String, Object>(); | 153 | var map = new HashMap<String, Object>(); |
| 158 | - for (var monitoringMetric : metric) { | 154 | + for (monitoringMetric monitoringMetric : metric) { |
| 159 | - if (template == null) { | 155 | + if (template == null) |
| 160 | throw new NullPointerException(promQl); | 156 | throw new NullPointerException(promQl); |
| 161 | - } | ||
| 162 | String key = StrUtil.format(template, monitoringMetric.getMetric()); | 157 | String key = StrUtil.format(template, monitoringMetric.getMetric()); |
| 163 | var lineNumber = ListUtil.collect(monitoringMetric.getValues(), timeline); | 158 | var lineNumber = ListUtil.collect(monitoringMetric.getValues(), timeline); |
| 164 | map.put(key, lineNumber); | 159 | map.put(key, lineNumber); |
| @@ -168,29 +163,28 @@ public class MetricsService { | |||
| 168 | } | 163 | } |
| 169 | 164 | ||
| 170 | 165 | ||
| 171 | - public static class PrometheusResult { | 166 | + public static class prometheusResult { |
| 172 | - Stat status; | 167 | + stat status; |
| 173 | - PromData data; | 168 | + data data; |
| 174 | 169 | ||
| 175 | public void isSuccess() { | 170 | public void isSuccess() { |
| 176 | - if (status == Stat.error) { | 171 | + if (status == stat.error) |
| 177 | - throw new CustomException(error); | 172 | + throw new RuntimeException(error); |
| 178 | - } | ||
| 179 | } | 173 | } |
| 180 | 174 | ||
| 181 | 175 | ||
| 182 | - public static class PromData { | 176 | + public static class data { |
| 183 | - ResultType resultType; | 177 | + resultType resultType; |
| 184 | - List<MonitoringMetric> result; | 178 | + List<monitoringMetric> result; |
| 185 | 179 | ||
| 186 | 180 | ||
| 187 | - public static class MonitoringMetric { | 181 | + public static class monitoringMetric { |
| 188 | Map<String, String> metric; | 182 | Map<String, String> metric; |
| 189 | List<Number> value; | 183 | List<Number> value; |
| 190 | List<List<Number>> values; | 184 | List<List<Number>> values; |
| 191 | } | 185 | } |
| 192 | 186 | ||
| 193 | - public enum ResultType { | 187 | + public enum resultType { |
| 194 | matrix, | 188 | matrix, |
| 195 | vector, | 189 | vector, |
| 196 | scalar, | 190 | scalar, |
| @@ -201,7 +195,7 @@ public class MetricsService { | |||
| 201 | String errorType; | 195 | String errorType; |
| 202 | String error; | 196 | String error; |
| 203 | 197 | ||
| 204 | - public enum Stat { | 198 | + public enum stat { |
| 205 | success, | 199 | success, |
| 206 | error | 200 | error |
| 207 | } | 201 | } |
Mplugins/observability-instance/src/main/java/com/nctigba/observability/instance/service/TopSQLService.java+1-6
| @@ -8,7 +8,6 @@ import java.time.LocalDateTime; | |||
| 8 | import java.time.format.DateTimeFormatter; | 8 | import java.time.format.DateTimeFormatter; |
| 9 | import java.time.format.DateTimeParseException; | 9 | import java.time.format.DateTimeParseException; |
| 10 | import java.util.ArrayList; | 10 | import java.util.ArrayList; |
| 11 | -import java.util.Collections; | ||
| 12 | import java.util.List; | 11 | import java.util.List; |
| 13 | import java.util.Map; | 12 | import java.util.Map; |
| 14 | 13 | ||
| @@ -26,7 +25,6 @@ import com.nctigba.observability.instance.mapper.TopSqlMapper; | |||
| 26 | import com.nctigba.observability.instance.model.InstanceNodeInfo; | 25 | import com.nctigba.observability.instance.model.InstanceNodeInfo; |
| 27 | import com.nctigba.observability.instance.service.TopSQLService.waitEvent.event; | 26 | import com.nctigba.observability.instance.service.TopSQLService.waitEvent.event; |
| 28 | 27 | ||
| 29 | -import cn.hutool.core.util.StrUtil; | ||
| 30 | import lombok.Data; | 28 | import lombok.Data; |
| 31 | import lombok.RequiredArgsConstructor; | 29 | import lombok.RequiredArgsConstructor; |
| 32 | import lombok.extern.slf4j.Slf4j; | 30 | import lombok.extern.slf4j.Slf4j; |
| @@ -123,7 +121,7 @@ public class TopSQLService { | |||
| 123 | 121 | ||
| 124 | /** | 122 | /** |
| 125 | * Query instance node information | 123 | * Query instance node information |
| 126 | - * | 124 | + * |
| 127 | * nodeId instance node id | 125 | * nodeId instance node id |
| 128 | * Instance node information | 126 | * Instance node information |
| 129 | */ | 127 | */ |
| @@ -144,9 +142,6 @@ public class TopSQLService { | |||
| 144 | try { | 142 | try { |
| 145 | clusterManager.setCurrentDatasource(nodeId, null); | 143 | clusterManager.setCurrentDatasource(nodeId, null); |
| 146 | String table = topSqlMapper.waitEvent(sqlId); | 144 | String table = topSqlMapper.waitEvent(sqlId); |
| 147 | - if (StrUtil.isBlank(table)) { | ||
| 148 | - return Collections.emptyList(); | ||
| 149 | - } | ||
| 150 | String[] lines = table.split(","); | 145 | String[] lines = table.split(","); |
| 151 | waitEvent pre = null; | 146 | waitEvent pre = null; |
| 152 | for (String string : lines) { | 147 | for (String string : lines) { |
| @@ -0,0 +1,4 @@ | |||
| 1 | +# | ||
| 2 | +# Copyright (c) 2023 Huawei Technologies Co.,Ltd. | ||
| 3 | +# | ||
| 4 | + | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +# sso异常测试 | ||
| 2 | +EC00001=SSO的WEB层错误 | ||