Skip to content

Commit

Permalink
[manager,collector] add feature-clickhouse monitoring(#179) (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangeyts authored Jan 9, 2023
1 parent f946f2a commit 6331eec
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 0 deletions.
6 changes: 6 additions & 0 deletions collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<!-- clickhouse -->
<dependency>
<groupId>cc.blynk.clickhouse</groupId>
<artifactId>clickhouse4j</artifactId>
<version>1.4.4</version>
</dependency>
<!-- dm -->
<dependency>
<groupId>com.dameng</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ private String constructDatabaseUrl(JdbcProtocol jdbcProtocol) {
url = "jdbc:postgresql://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort()
+ "/" + (jdbcProtocol.getDatabase() == null ? "" : jdbcProtocol.getDatabase());
break;
case "clickhouse":
url = "jdbc:clickhouse://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort()
+ "/" + (jdbcProtocol.getDatabase() == null ? "" : jdbcProtocol.getDatabase());
break;
case "sqlserver":
url = "jdbc:sqlserver://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort()
+ ";" + (jdbcProtocol.getDatabase() == null ? "" : "DatabaseName=" + jdbcProtocol.getDatabase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void run(String... args) throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Class.forName("oracle.jdbc.driver.OracleDriver");
Class.forName("dm.jdbc.driver.DmDriver");
Class.forName("cc.blynk.clickhouse.ClickHouseDriver");
} catch (Exception e) {
log.error("load jdbc error: {}", e.getMessage(), e);
}
Expand Down
137 changes: 137 additions & 0 deletions manager/src/main/resources/define/app/app-clickhouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

category: db
app: clickhouse
name:
zh-CN: CLICKHOUSE数据库
en-US: CLICKHOUSE DB
# 参数映射map. type是参数类型: 0-number数字, 1-string明文字符串, 2-secret加密字符串
# 强制固定必须参数 - host
configmap:
- key: host
type: 1
- key: port
type: 0
- key: username
type: 1
- key: password
type: 2
- key: database
type: 1
- key: timeout
type: 0
- key: url
type: 1
- key: keyword
type: 1
# 指标组列表
metrics:
- name: system.metrics
priority: 1
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: metric
type: 1
- field: value
type: 0
# - field: description
# type: 1
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- metric
- value
# - description
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: clickhouse
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: multiRow
# sql
sql: SELECT * FROM system.metrics LIMIT 10;
- name: system.events
priority: 2
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: event
type: 1
- field: value
type: 0
# - field: description
# type: 1
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- event
- value
# - description
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: clickhouse
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: multiRow
# sql
sql: SELECT * FROM system.events LIMIT 5;
- name: asynchronous.metrics
priority: 3
fields:
# 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位
- field: metric
type: 1
- field: value
type: 0
# - field: description
# type: 1
# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换
aliasFields:
- metric
- value
# - description
# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
protocol: jdbc
jdbc:
# 主机host: ipv4 ipv6 域名
host: ^_^host^_^
# 端口
port: ^_^port^_^
platform: clickhouse
username: ^_^username^_^
password: ^_^password^_^
database: ^_^database^_^
timeout: ^_^timeout^_^
# SQL查询方式: oneRow, multiRow, columns
queryType: multiRow
# sql
sql: SELECT * FROM system.asynchronous_metrics LIMIT 10;
73 changes: 73 additions & 0 deletions manager/src/main/resources/define/param/param-clickhouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

app: clickhouse
param:
- field: host
name:
zh-CN: 主机Host
en-US: Host
type: host
required: true
- field: port
name:
zh-CN: 端口
en-US: Port
type: number
range: '[0,65535]'
required: true
defaultValue: 3306
- field: timeout
name:
zh-CN: 查询超时时间(ms)
en-US: Query Timeout(ms)
type: number
required: false
hide: true
defaultValue: 6000
- field: database
name:
zh-CN: 数据库名称
en-US: Database Name
type: text
required: false
- field: username
name:
zh-CN: 用户名
en-US: Username
type: text
limit: 20
required: false
- field: password
name:
zh-CN: 密码
en-US: Password
type: password
required: false
- field: url
name:
zh-CN: URL
en-US: URL
type: text
required: false
hide: true
- field: keyword
name:
zh-CN: 关键字计数
en-US: Keyword Num
type: text
placeholder: 'Input Keyword'
required: false
hide: true
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
import static org.mockito.Mockito.*;

/**
* newBranch feature-clickhouse#179
* 配置带密码的clickhouse
* https://www.cnblogs.com/it1042290135/p/16202478.html
9363是promethus的http端口(在config.xml里面打开), http://clickhouse:9363/metrics
docker run -d --name some-clickhouse-server -p 8123:8123 -p 9009:9009 -p 9090:9000 -p 9363:9363 --ulimit nofile=262144:262144 --volume=/opt/clickhouse/data:/var/lib/clickhouse --volume=/opt/clickhouse/log:/var/log/clickhouse-server --volume=/opt/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml --volume=/opt/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml clickhouse/clickhouse-server
*
* https://hub.docker.com/r/clickhouse/clickhouse-server/
* docker run -d -p 18123:8123 -p19000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
* curl 'http://localhost:18123/'
* web UI
* http://localhost:18123/play
*
* 明文密码linux可以登录了,但是navicat还是无法登录
* clickhouse client -h 127.0.0.1 -d default -m -u default --password 123456
* Test case for {@link MonitorService}
* @see TagServiceTest
*/
Expand Down

0 comments on commit 6331eec

Please sign in to comment.