From 7dc0d74a3215856d05ad83e0fb336d11fb15f5b9 Mon Sep 17 00:00:00 2001 From: liuhy Date: Fri, 16 Aug 2024 10:31:31 +0800 Subject: [PATCH 1/5] [type:feature] optimize okhttp3 connection factory --- common/pom.xml | 4 ++ .../manager/config/RestTemplateConfig.java | 39 ++++++++++++++----- pom.xml | 6 +++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/common/pom.xml b/common/pom.xml index 0aaa3497ab0..e8e638722b4 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -96,6 +96,10 @@ org.apache.httpcomponents httpclient + + org.apache.httpcomponents.client5 + httpclient5 + com.github.ben-manes.caffeine diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java index d07735c2aee..ad226820bf6 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java @@ -19,11 +19,17 @@ import java.util.Collections; import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.core5.util.Timeout; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.OkHttp3ClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; /** @@ -39,15 +45,30 @@ public RestTemplate restTemplate(ClientHttpRequestFactory factory) { restTemplate.setInterceptors(Collections.singletonList(new HeaderRequestInterceptor())); return restTemplate; } - + @Bean - public ClientHttpRequestFactory simpleClientHttpRequestFactory() { - OkHttpClient client = new OkHttpClient.Builder() - .connectTimeout(15, TimeUnit.SECONDS) - .readTimeout(20, TimeUnit.SECONDS) - .writeTimeout(20, TimeUnit.SECONDS) + public ClientHttpRequestFactory httpComponentsClientHttpRequestFactory() { + ConnectionConfig connectionConfig = ConnectionConfig + .custom() + .setConnectTimeout(Timeout.of(15, TimeUnit.SECONDS)) + .setSocketTimeout(Timeout.of(20, TimeUnit.SECONDS)) + .setValidateAfterInactivity(Timeout.of(20, TimeUnit.SECONDS)) + .build(); + RequestConfig requestConfig = RequestConfig.custom() + .setConnectionRequestTimeout(15, TimeUnit.SECONDS) + .setResponseTimeout(20, TimeUnit.SECONDS) + .build(); + HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder + .create() + .setDefaultConnectionConfig(connectionConfig) + .setMaxConnTotal(200) + .setMaxConnPerRoute(20) + .build(); + CloseableHttpClient httpClient = HttpClients.custom() + .setConnectionManager(connectionManager) + .setDefaultRequestConfig(requestConfig) .build(); - return new OkHttp3ClientHttpRequestFactory(client); + return new HttpComponentsClientHttpRequestFactory(httpClient); } } diff --git a/pom.xml b/pom.xml index 31f9f010b8f..8b33e36d821 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ 2.0.24 2.9.3 4.5.14 + 5.3.1 1.18.28 2.0.9 @@ -240,6 +241,11 @@ httpclient ${httpclient.version} + + org.apache.httpcomponents.client5 + httpclient5 + ${httpclient5.version} + org.apache.commons commons-jexl3 From ab72dc0951d2288fe8c2a8449f0d949535eee80c Mon Sep 17 00:00:00 2001 From: liuhy Date: Sat, 17 Aug 2024 09:48:06 +0800 Subject: [PATCH 2/5] [type:feature] optimize okhttp3 connection factory --- .../common/constants/NetworkConstants.java | 5 ++++- .../manager/config/RestTemplateConfig.java | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/org/apache/hertzbeat/common/constants/NetworkConstants.java b/common/src/main/java/org/apache/hertzbeat/common/constants/NetworkConstants.java index de58a2e1fe7..7322286c472 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/constants/NetworkConstants.java +++ b/common/src/main/java/org/apache/hertzbeat/common/constants/NetworkConstants.java @@ -54,7 +54,8 @@ interface HttpClientConstants { int READ_TIME_OUT = 6 * 1000; int WRITE_TIME_OUT = 6 * 1000; - int CONNECT_TIME_OUT = 6 * 1000; + int CONNECT_TIME_OUT = 15; + int SOCKET_TIME_OUT = 20; int CHUNK_SIZE = 8196; int MAX_IDLE_CONNECTIONS = 20; int KEEP_ALIVE_TIMEOUT = 30 * 1000; @@ -63,6 +64,8 @@ interface HttpClientConstants { int HTTPCLIENT_KEEP_ALIVE_DURATION = 30 * 1000; int HTTP_CLIENT_CONNECTION_MANAGER_CLOSE_WAIT_TIME_MS = 1000; int HTTP_CLIENT_CONNECTION_MANAGER_CLOSE_IDLE_TIME_S = 30; + int HTTP_CLIENT_MAX_CONNECT_TOTAL = 200; + int HTTP_CLIENT_MAX_CONNECT_PRE_ROUTE = 200; } } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java index ad226820bf6..3d8e6dec88b 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java @@ -17,8 +17,6 @@ package org.apache.hertzbeat.manager.config; -import java.util.Collections; -import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; @@ -26,12 +24,16 @@ import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; import org.apache.hc.client5.http.io.HttpClientConnectionManager; import org.apache.hc.core5.util.Timeout; +import org.apache.hertzbeat.common.constants.NetworkConstants.HttpClientConstants; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +import java.util.Collections; +import java.util.concurrent.TimeUnit; + /** * restTemplate config * todo thread pool @@ -50,19 +52,19 @@ public RestTemplate restTemplate(ClientHttpRequestFactory factory) { public ClientHttpRequestFactory httpComponentsClientHttpRequestFactory() { ConnectionConfig connectionConfig = ConnectionConfig .custom() - .setConnectTimeout(Timeout.of(15, TimeUnit.SECONDS)) - .setSocketTimeout(Timeout.of(20, TimeUnit.SECONDS)) - .setValidateAfterInactivity(Timeout.of(20, TimeUnit.SECONDS)) + .setConnectTimeout(Timeout.of(HttpClientConstants.CONNECT_TIME_OUT, TimeUnit.SECONDS)) + .setSocketTimeout(Timeout.of(HttpClientConstants.SOCKET_TIME_OUT, TimeUnit.SECONDS)) + .setValidateAfterInactivity(Timeout.of(HttpClientConstants.MAX_IDLE_CONNECTIONS, TimeUnit.SECONDS)) .build(); RequestConfig requestConfig = RequestConfig.custom() - .setConnectionRequestTimeout(15, TimeUnit.SECONDS) - .setResponseTimeout(20, TimeUnit.SECONDS) + .setConnectionRequestTimeout(HttpClientConstants.CONNECT_TIME_OUT, TimeUnit.SECONDS) + .setResponseTimeout(HttpClientConstants.SOCKET_TIME_OUT, TimeUnit.SECONDS) .build(); HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder .create() .setDefaultConnectionConfig(connectionConfig) - .setMaxConnTotal(200) - .setMaxConnPerRoute(20) + .setMaxConnTotal(HttpClientConstants.HTTP_CLIENT_MAX_CONNECT_TOTAL) + .setMaxConnPerRoute(HttpClientConstants.HTTP_CLIENT_MAX_CONNECT_PRE_ROUTE) .build(); CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) From b98de51c69f4c26ded0bdf3cda48a1196e1b08db Mon Sep 17 00:00:00 2001 From: liuhy Date: Sat, 17 Aug 2024 09:55:26 +0800 Subject: [PATCH 3/5] [type:feature] optimize okhttp3 connection factory --- .../apache/hertzbeat/manager/config/RestTemplateConfig.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java index 3d8e6dec88b..e5e5cca74bb 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/config/RestTemplateConfig.java @@ -17,6 +17,8 @@ package org.apache.hertzbeat.manager.config; +import java.util.Collections; +import java.util.concurrent.TimeUnit; import org.apache.hc.client5.http.config.ConnectionConfig; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; @@ -31,9 +33,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -import java.util.Collections; -import java.util.concurrent.TimeUnit; - /** * restTemplate config * todo thread pool From 02b4a9d496daa8ba80c0859d97383e78f838ff59 Mon Sep 17 00:00:00 2001 From: liuhy Date: Wed, 21 Aug 2024 06:59:29 +0800 Subject: [PATCH 4/5] [type:feature] remove httpclient4 dependency import --- collector/pom.xml | 10 ++++++++-- common/pom.xml | 4 ---- .../org/apache/hertzbeat/common/util/IpDomainUtil.java | 2 +- pom.xml | 5 ----- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/collector/pom.xml b/collector/pom.xml index 241c999c4ca..f76563de99d 100644 --- a/collector/pom.xml +++ b/collector/pom.xml @@ -71,8 +71,8 @@ - org.apache.httpcomponents - httpclient + org.apache.httpcomponents.client5 + httpclient5 @@ -185,6 +185,12 @@ com.ecwid.consul consul-api 1.4.5 + + + httpclient + org.apache.httpcomponents + + diff --git a/common/pom.xml b/common/pom.xml index e8e638722b4..a35f2acb9b2 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -92,10 +92,6 @@ protobuf-java-util - - org.apache.httpcomponents - httpclient - org.apache.httpcomponents.client5 httpclient5 diff --git a/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java b/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java index 8845fcfaf86..9f23bae5cd8 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java +++ b/common/src/main/java/org/apache/hertzbeat/common/util/IpDomainUtil.java @@ -24,8 +24,8 @@ import java.util.Enumeration; import java.util.regex.Pattern; import lombok.extern.slf4j.Slf4j; +import org.apache.hc.core5.net.InetAddressUtils; import org.apache.hertzbeat.common.constants.NetworkConstants; -import org.apache.http.conn.util.InetAddressUtils; import org.springframework.util.StringUtils; /** diff --git a/pom.xml b/pom.xml index 36fc7438d54..cd1b89b0fb9 100644 --- a/pom.xml +++ b/pom.xml @@ -236,11 +236,6 @@ commons-net ${commons-net} - - org.apache.httpcomponents - httpclient - ${httpclient.version} - org.apache.httpcomponents.client5 httpclient5 From 93d7ff530900f248078b6e3c91cbcb0c8750a430 Mon Sep 17 00:00:00 2001 From: liuhy Date: Wed, 21 Aug 2024 07:03:23 +0800 Subject: [PATCH 5/5] [type:feature] kingbase spotless apply --- home/docs/help/kingbase.md | 2 +- .../current/help/kingbase.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/home/docs/help/kingbase.md b/home/docs/help/kingbase.md index 92d3b440496..ccdb5cc0391 100644 --- a/home/docs/help/kingbase.md +++ b/home/docs/help/kingbase.md @@ -37,7 +37,7 @@ keywords: [open source monitoring tool, open source database monitoring tool, mo #### Metric set:state -| Metric name | Metric unit | Metric help description | +| Metric name | Metric unit | Metric help description | |----------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | name | none | Database name, or share-object is a shared object | | conflicts | times | The number of queries canceled in the database due to a conflict with recovery | diff --git a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/kingbase.md b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/kingbase.md index 2f22804c38b..b09187ff456 100644 --- a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/kingbase.md +++ b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/kingbase.md @@ -37,16 +37,16 @@ keywords: [开源监控系统, 开源数据库监控, Kingbase数据库监控] #### 指标集合:state -| 指标名称 | 指标单位 | 指标帮助描述 | -|----------------|------|--------------------------------------------------------------------------| -| name | 无 | 数据库名称,或share-object为共享对象。 | -| conflicts | 次数 | 由于与恢复冲突而在这个数据库中被取消的查询的数目 | -| deadlocks | 个数 | 在这个数据库中被检测到的死锁数 | -| blks_read | 次数 | 在这个数据库中被读取的磁盘块的数量 | +| 指标名称 | 指标单位 | 指标帮助描述 | +|----------------|------|------------------------------------------------------------------------| +| name | 无 | 数据库名称,或share-object为共享对象。 | +| conflicts | 次数 | 由于与恢复冲突而在这个数据库中被取消的查询的数目 | +| deadlocks | 个数 | 在这个数据库中被检测到的死锁数 | +| blks_read | 次数 | 在这个数据库中被读取的磁盘块的数量 | | blks_hit | 次数 | 磁盘块被发现已经在缓冲区中的次数,这样不需要一次读取(这只包括 Kingbase 缓冲区中的命中,而不包括在操作系统文件系统缓冲区中的命中) | -| blk_read_time | ms | 在这个数据库中后端花费在读取数据文件块的时间 | -| blk_write_time | ms | 在这个数据库中后端花费在写数据文件块的时间 | -| stats_reset | 无 | 这些统计信息上次被重置的时间 | +| blk_read_time | ms | 在这个数据库中后端花费在读取数据文件块的时间 | +| blk_write_time | ms | 在这个数据库中后端花费在写数据文件块的时间 | +| stats_reset | 无 | 这些统计信息上次被重置的时间 | #### 指标集合:activity