From 0a3b077172c1d64c0e8d0e7550854503d8f37863 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sat, 5 Mar 2022 21:30:31 +0800 Subject: [PATCH] =?UTF-8?q?[manager,home,collector]feature:=E6=94=AF?= =?UTF-8?q?=E6=8C=81mariadb=E7=9B=91=E6=8E=A7=E7=B1=BB=E5=9E=8B=20(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collect/database/JdbcCommonCollect.java | 1 + home/docs/help/guide.md | 4 +- home/docs/help/mariadb.md | 57 +++++++ home/sidebars.json | 3 +- .../src/main/resources/define/app/mariadb.yml | 141 ++++++++++++++++++ .../main/resources/define/param/mariadb.yml | 30 ++++ 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 home/docs/help/mariadb.md create mode 100644 manager/src/main/resources/define/app/mariadb.yml create mode 100644 manager/src/main/resources/define/param/mariadb.yml diff --git a/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java b/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java index 1f86ffc..12adee5 100644 --- a/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java +++ b/collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java @@ -248,6 +248,7 @@ public class JdbcCommonCollect extends AbstractCollect { String url; switch (jdbcProtocol.getPlatform()) { case "mysql": + case "mariadb": url = "jdbc:mysql://" + jdbcProtocol.getHost() + ":" + jdbcProtocol.getPort() + "/" + (jdbcProtocol.getDatabase() == null ? "" : jdbcProtocol.getDatabase()) + "?useUnicode=true&characterEncoding=utf-8&useSSL=false"; diff --git a/home/docs/help/guide.md b/home/docs/help/guide.md index 1614327..e23f2b1 100644 --- a/home/docs/help/guide.md +++ b/home/docs/help/guide.md @@ -18,7 +18,7 @@ sidebar_label: 帮助入门 ### 数据库监控 -[MYSQL数据库监控](mysql) +[MYSQL数据库监控](mysql)      [MariaDB数据库监控](mariadb) ## 💡 告警服务 @@ -33,6 +33,8 @@ sidebar_label: 帮助入门 > 指标阈值配置,提供表达式形式的指标阈值配置,可设置告警级别,触发次数,告警通知模版和是否启用,关联监控等功能。 +详见 [阈值告警](alert_threshold)      [阈值表达式](alert_threshold_expr) + ### 告警通知 > 触发告警信息后,除了显示在告警中心列表外,还可以用指定方式(邮件钉钉微信飞书等)通知给指定接收人。 diff --git a/home/docs/help/mariadb.md b/home/docs/help/mariadb.md new file mode 100644 index 0000000..83f0d28 --- /dev/null +++ b/home/docs/help/mariadb.md @@ -0,0 +1,57 @@ +--- +id: mariadb +title: 监控:MariaDB数据库监控 +sidebar_label: MariaDB数据库 +--- + +> 对MariaDB数据库的通用性能指标进行采集监控。支持MariaDB5+。 + +### 配置参数 + +| 参数名称 | 参数帮助描述 | +| ----------- | ----------- | +| 监控Host | 被监控的对端IPV4,IPV6或域名。注意⚠️不带协议头(eg: https://, http://)。 | +| 监控名称 | 标识此监控的名称,名称需要保证唯一性。 | +| 端口 | 网站对外提供的端口,http一般默认为80,https一般默认为443。 | +| 数据库名称 | 数据库实例名称,可选。 | +| 用户名 | 数据库连接用户名,可选 | +| 密码 | 数据库连接密码,可选 | +| URL | 数据库连接URL,可选,若配置,则URL里面的数据库名称,用户名密码等参数会覆盖上面配置的参数 | +| 采集间隔 | 监控周期性采集数据间隔时间,单位秒,可设置的最小间隔为10秒 | +| 是否探测 | 新增监控前是否先探测检查监控可用性,探测成功才会继续新增修改操作 | +| 描述备注 | 更多标识和描述此监控的备注信息,用户可以在这里备注信息 | + +### 采集指标 + +#### 指标集合:basic + +| 指标名称 | 指标单位 | 指标帮助描述 | +| ----------- | ----------- | ----------- | +| version | 无 | 数据库版本 | +| port | 无 | 数据库暴露服务端口 | +| datadir | 无 | 数据库存储数据盘地址 | +| max_connections | 无 | 数据库最大连接数 | + +#### 指标集合:status + +| 指标名称 | 指标单位 | 指标帮助描述 | +| ----------- | ----------- | ----------- | +| threads_created | 无 | MariaDB已经创建的总连接数 | +| threads_connected | 无 | MariaDB已经连接的连接数 | +| threads_cached | 无 | MariaDB当前缓存的连接数 | +| threads_running | 无 | MariaDB当前活跃的连接数 | +| qps | 无 | 每秒请求查询次数。`QPS = questions/uptimes` | +| tps | 无 | 每秒事务数据 `TPS= (commit+rollback)/seconds`| + + +#### 指标集合:innodb + +| 指标名称 | 指标单位 | 指标帮助描述 | +| ----------- | ----------- | ----------- | +| innodb_data_reads | 无 | innodb平均每秒从文件中读取的次数 | +| innodb_data_writes | 无 | innodb平均每秒从文件中写入的次数 | +| innodb_data_read | KB | innodb平均每秒钟读取的数据量,单位为KB | +| innodb_data_written | KB | innodb平均每秒钟写入的数据量,单位为KB | + + + diff --git a/home/sidebars.json b/home/sidebars.json index 36945e0..1228a6b 100644 --- a/home/sidebars.json +++ b/home/sidebars.json @@ -55,7 +55,8 @@ "type": "category", "label": "数据库监控", "items": [ - "help/mysql" + "help/mysql", + "help/mariadb" ] }, { diff --git a/manager/src/main/resources/define/app/mariadb.yml b/manager/src/main/resources/define/app/mariadb.yml new file mode 100644 index 0000000..959650d --- /dev/null +++ b/manager/src/main/resources/define/app/mariadb.yml @@ -0,0 +1,141 @@ +category: db +app: mariadb +name: + zh-CN: MariaDB数据库 + en-US: MariaDB +# 参数映射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: url + type: 1 +# 指标组列表 +metrics: + - name: basic + # 指标组调度优先级(0-127)越小优先级越高,优先级低的指标组会等优先级高的指标组采集完成后才会被调度,相同优先级的指标组会并行调度采集 + # 优先级为0的指标组为可用性指标组,即它会被首先调度,采集成功才会继续调度其它指标组,采集失败则中断调度 + priority: 0 + # 指标组中的具体监控指标 + fields: + # 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位 + - field: version + type: 1 + instance: true + - field: port + type: 1 + - field: datadir + type: 1 + - field: max_connections + type: 0 +# (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换 + aliasFields: + - version + - version_compile_os + - version_compile_machine + - port + - datadir + - max_connections +# (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值 +# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime + calculates: + - port=port + - datadir=datadir + - max_connections=max_connections + - version=version+"_"+version_compile_os+"_"+version_compile_machine + protocol: jdbc + jdbc: + # 主机host: ipv4 ipv6 域名 + host: ^_^host^_^ + # 端口 + port: ^_^port^_^ + platform: mariadb + username: ^_^username^_^ + password: ^_^password^_^ + database: ^_^database^_^ + # SQL查询方式: oneRow, multiRow, columns + queryType: columns + # sql + sql: show global variables where Variable_name like 'version%' or Variable_name = 'max_connections' or Variable_name = 'datadir' or Variable_name = 'port'; + url: ^_^url^_^ + + - name: status + priority: 1 + fields: + # 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位 + - field: threads_created + type: 0 + - field: threads_connected + type: 0 + - field: threads_cached + type: 0 + - field: threads_running + type: 0 + # (非必须)监控指标别名,与上面的指标名映射。用于采集接口数据字段不直接是最终指标名称,需要此别名做映射转换 + aliasFields: + - threads_created + - threads_connected + - threads_cached + - threads_running + # (非必须)指标计算表达式,与上面的别名一起作用,计算出最终需要的指标值 + # eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime + calculates: + - threads_created=threads_created + - threads_connected=threads_connected + - threads_cached=threads_cached + - threads_running=threads_running + protocol: jdbc + jdbc: + # 主机host: ipv4 ipv6 域名 + host: ^_^host^_^ + # 端口 + port: ^_^port^_^ + platform: mariadb + username: ^_^username^_^ + password: ^_^password^_^ + database: ^_^database^_^ + # SQL查询方式: oneRow, multiRow, columns + queryType: columns + # sql + sql: show global status where Variable_name like 'thread%' or Variable_name = 'com_commit' or Variable_name = 'com_rollback' or Variable_name = 'questions' or Variable_name = 'uptime'; + url: ^_^url^_^ + + - name: innodb + priority: 2 + fields: + # 指标信息 包括 field名称 type字段类型:0-number数字,1-string字符串 instance是否为实例主键 unit:指标单位 + - field: innodb_data_reads + type: 0 + unit: 次数 + - field: innodb_data_writes + type: 0 + unit: 次数 + - field: innodb_data_read + type: 0 + unit: kb + - field: innodb_data_written + type: 0 + unit: kb + protocol: jdbc + jdbc: + # 主机host: ipv4 ipv6 域名 + host: ^_^host^_^ + # 端口 + port: ^_^port^_^ + platform: mariadb + username: ^_^username^_^ + password: ^_^password^_^ + database: ^_^database^_^ + # SQL查询方式: oneRow, multiRow, columns + queryType: columns + # sql + sql: show global status where Variable_name like 'innodb%'; + url: ^_^url^_^ \ No newline at end of file diff --git a/manager/src/main/resources/define/param/mariadb.yml b/manager/src/main/resources/define/param/mariadb.yml new file mode 100644 index 0000000..3de359b --- /dev/null +++ b/manager/src/main/resources/define/param/mariadb.yml @@ -0,0 +1,30 @@ +app: mariadb +param: + - field: host + name: 主机Host + type: host + required: true + - field: port + name: 端口 + type: number + range: '[0,65535]' + required: true + defaultValue: 80 + placeholder: '请输入端口' + - field: database + name: 数据库名称 + type: text + required: false + - field: username + name: 用户名 + type: text + limit: 20 + required: false + - field: password + name: 密码 + type: password + required: false + - field: url + name: URL + type: text + required: false \ No newline at end of file