diff --git a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java index 0a43f73166e..c398791fd3a 100644 --- a/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java +++ b/hertzbeat-collector/hertzbeat-collector-basic/src/main/java/org/apache/hertzbeat/collector/collect/http/HttpCollectImpl.java @@ -156,6 +156,8 @@ public void collect(CollectRep.MetricsData.Builder builder, parseResponseByWebsite(resp, metrics, metrics.getHttp(), builder, responseTime, response); case DispatchConstants.PARSE_SITE_MAP -> parseResponseBySiteMap(resp, metrics.getAliasFields(), builder); + case DispatchConstants.PARSE_HEADER -> + parseResponseByHeader(builder, metrics.getAliasFields(), response); default -> parseResponseByDefault(resp, metrics.getAliasFields(), metrics.getHttp(), builder, responseTime); } @@ -196,6 +198,24 @@ public void collect(CollectRep.MetricsData.Builder builder, } } + private void parseResponseByHeader(CollectRep.MetricsData.Builder builder, List aliases, CloseableHttpResponse response) { + CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder(); + for (String alias : aliases) { + if (!StringUtils.hasText(alias)) { + valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); + continue; + } + final Header firstHeader = response.getFirstHeader(alias); + if (Objects.isNull(firstHeader)) { + valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); + continue; + } + + valueRowBuilder.addColumns(firstHeader.getValue()); + } + builder.addValues(valueRowBuilder.build()); + } + @Override public String supportProtocol() { return DispatchConstants.PROTOCOL_HTTP; @@ -207,30 +227,11 @@ private void parseResponseByWebsite(String resp, Metrics metrics, HttpProtocol h CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder(); int keywordNum = CollectUtil.countMatchKeyword(resp, http.getKeyword()); for (String alias : metrics.getAliasFields()) { - if ("summary".equalsIgnoreCase(metrics.getName())) { - addColumnForSummary(responseTime, valueRowBuilder, keywordNum, alias); - } else if ("header".equalsIgnoreCase(metrics.getName())) { - addColumnFromHeader(valueRowBuilder, alias, response); - } + addColumnForSummary(responseTime, valueRowBuilder, keywordNum, alias); } builder.addValues(valueRowBuilder.build()); } - private void addColumnFromHeader(CollectRep.ValueRow.Builder valueRowBuilder, String alias, CloseableHttpResponse response) { - if (!StringUtils.hasText(alias)) { - valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); - return; - } - - final Header firstHeader = response.getFirstHeader(alias); - if (Objects.isNull(firstHeader)) { - valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); - return; - } - - valueRowBuilder.addColumns(firstHeader.getValue()); - } - private void addColumnForSummary(Long responseTime, CollectRep.ValueRow.Builder valueRowBuilder, int keywordNum, String alias) { if (NetworkConstants.RESPONSE_TIME.equalsIgnoreCase(alias)) { valueRowBuilder.addColumns(responseTime.toString()); diff --git a/hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/DispatchConstants.java b/hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/DispatchConstants.java index 5f61cf6762e..e6d00dfa179 100644 --- a/hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/DispatchConstants.java +++ b/hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/dispatch/DispatchConstants.java @@ -194,6 +194,10 @@ public interface DispatchConstants { * Analysis method Sitemap site-wide availability monitoring rules */ String PARSE_SITE_MAP = "sitemap"; + /** + * Analysis method resolution: response header + */ + String PARSE_HEADER = "header"; /** * Parsing method prometheus exporter data */ diff --git a/hertzbeat-manager/src/main/resources/define/app-api.yml b/hertzbeat-manager/src/main/resources/define/app-api.yml index e3eaa9b631f..13ad461a825 100644 --- a/hertzbeat-manager/src/main/resources/define/app-api.yml +++ b/hertzbeat-manager/src/main/resources/define/app-api.yml @@ -352,5 +352,5 @@ metrics: digestAuthUsername: ^_^username^_^ digestAuthPassword: ^_^password^_^ # http response data parse type: default-hertzbeat rule, jsonpath-jsonpath script, website-for website monitoring, prometheus-prometheus exporter rule - parseType: website - keyword: ^_^keyword^_^ \ No newline at end of file + parseType: header + keyword: ^_^keyword^_^ diff --git a/hertzbeat-manager/src/main/resources/define/app-clickhouse.yml b/hertzbeat-manager/src/main/resources/define/app-clickhouse.yml index 2cabe2300f3..ba9d75e71f5 100644 --- a/hertzbeat-manager/src/main/resources/define/app-clickhouse.yml +++ b/hertzbeat-manager/src/main/resources/define/app-clickhouse.yml @@ -104,7 +104,7 @@ params: # collect metrics config list metrics: # metrics - ping_available - - name: ping_available + - name: summary i18n: zh-CN: ping的可用性 en-US: ping_available