categraf/inputs/mysql/README.md

96 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# mysql
mysql 监控采集插件,核心原理就是连到 mysql 实例,执行一些 sql解析输出内容整理为监控数据上报。
## Configuration
```toml
# # collect interval
# interval = 15
# 要监控 MySQL首先要给出要监控的MySQL的连接地址、用户名、密码
[[instances]]
address = "127.0.0.1:3306"
username = "root"
password = "1234"
# # set tls=custom to enable tls
# parameters = "tls=false"
# 通过 show global status监控mysql默认抓取一些基础指标
# 如果想抓取更多global status的指标把下面的配置设置为true
extra_status_metrics = true
# 通过show global variables监控mysql的全局变量默认抓取一些常规的
# 常规的基本够用了扩展的部分默认不采集下面的配置设置为false
extra_innodb_metrics = false
# 监控processlist关注较少默认不采集
gather_processlist_processes_by_state = false
gather_processlist_processes_by_user = false
# 监控各个数据库的磁盘占用大小
gather_schema_size = true
# 监控所有的table的磁盘占用大小
gather_table_size = false
# 是否采集系统表的大小通过不用所以默认设置为false
gather_system_table_size = false
# 通过 show slave status监控slave的情况比较关键所以默认采集
gather_slave_status = true
# # timeout
# timeout_seconds = 3
# # interval = global.interval * interval_times
# interval_times = 1
# 如果要复用Grafana的大盘Grafana的大盘一般使用instance标识的
# 建议为mysql实例附一个instance的标签
# important! use global unique string to specify instance
# labels = { instance="n9e-10.2.3.4:3306" }
## Optional TLS Config
# use_tls = false
# tls_min_version = "1.2"
# tls_ca = "/etc/categraf/ca.pem"
# tls_cert = "/etc/categraf/cert.pem"
# tls_key = "/etc/categraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = true
# 自定义SQL指定SQL、返回的各个列那些是作为metric哪些是作为label
# [[instances.queries]]
# mesurement = "users"
# metric_fields = [ "total" ]
# label_fields = [ "service" ]
# # field_to_append = ""
# timeout = "3s"
# request = '''
# select 'n9e' as service, count(*) as total from n9e_v5.users
# '''
```
## 监控多个实例
大家最常问的问题是如何监控多个mysql实例实际大家对toml配置学习一下就了解了`[[instances]]` 部分表示数组,是可以出现多个的,所以,举例:
```toml
[[instances]]
address = "10.2.3.6:3306"
username = "root"
password = "1234"
labels = { instance="n9e-10.2.3.6:3306" }
[[instances]]
address = "10.2.6.9:3306"
username = "root"
password = "1234"
labels = { instance="zbx-10.2.6.9:3306" }
```
## 监控大盘和告警规则
本 README 的同级目录,大家可以看到 dashboard.json 就是监控大盘导入夜莺就可以使用alerts.json 是告警规则,也是导入夜莺就可以使用。