Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] fix clickhouse monitor #2874

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -196,6 +198,24 @@ public void collect(CollectRep.MetricsData.Builder builder,
}
}

private void parseResponseByHeader(CollectRep.MetricsData.Builder builder, List<String> 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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions hertzbeat-manager/src/main/resources/define/app-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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^_^
parseType: header
keyword: ^_^keyword^_^
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading