diff --git a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java index 0a43f73166e..dddc4154b8d 100644 --- a/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java +++ b/collector/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java @@ -326,6 +326,35 @@ private void parseResponseBySiteMap(String resp, List aliasFields, private void parseResponseByXmlPath(String resp, List aliasFields, HttpProtocol http, CollectRep.MetricsData.Builder builder) { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builderFactory = factory.newDocumentBuilder(); + + Document document = builderFactory.parse(new ByteArrayInputStream(resp.getBytes(StandardCharsets.UTF_8))); + document.getDocumentElement().normalize(); + + for (String alias : aliasFields) { + NodeList nodeList = document.getElementsByTagName(alias); + if (nodeList.getLength() > 0) { + Node node = nodeList.item(0); + String value = node.getTextContent(); + + CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder(); + valueRowBuilder.addColumns(value); + builder.addValues(valueRowBuilder.build()); + } else { + CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder(); + valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); + builder.addValues(valueRowBuilder.build()); + } + } + + } catch (Exception e) { + String errorMsg = "Error parsing XML response: " + e.getMessage(); + log.error(errorMsg, e); + builder.setCode(CollectRep.Code.FAIL); + builder.setMsg(errorMsg); + } } private void parseResponseByJsonPath(String resp, List aliasFields, HttpProtocol http, diff --git a/manager/src/main/resources/define/app-springboot3.yml b/manager/src/main/resources/define/app-springboot3.yml index 90ffe25f426..6cd1d7df0c5 100644 --- a/manager/src/main/resources/define/app-springboot3.yml +++ b/manager/src/main/resources/define/app-springboot3.yml @@ -172,6 +172,56 @@ metrics: parseType: jsonPath parseScript: '$.availableTags[?(@.tag == "state")].values[*]' + - name: status + i18n: + zh-CN: 状态 + en-US: Status + priority: 6 + fields: + - field: activeThreads + i18n: + zh-CN: 活跃线程数 + en-US: Active Threads + type: 0 + - field: inactiveThreads + i18n: + zh-CN: 非活跃线程数 + en-US: Inactive Threads + type: 0 + - field: usedMemory + i18n: + zh-CN: 已用内存 + en-US: Used Memory + type: 0 + unit: MB + - field: totalMemory + i18n: + zh-CN: 总内存 + en-US: Total Memory + type: 0 + unit: MB + protocol: http + http: + host: ^_^host^_^ + port: ^_^port^_^ + url: ^_^base_path^_^/metrics/status.xml + method: GET + ssl: ^_^ssl^_^ + authorization: + type: Basic Auth + basicAuthUsername: ^_^username^_^ + basicAuthPassword: ^_^password^_^ + parseType: xmlPath + parseScript: + - alias: activeThreads + path: /status/threads/active + - alias: inactiveThreads + path: /status/threads/inactive + - alias: usedMemory + path: /status/memory/used + - alias: totalMemory + path: /status/memory/total + - name: threads i18n: zh-CN: 线程