采集组件列表
- mysql
- mongodb
- redis
- pgsql
一、采集mysql指标
mysql 监控采集插件,核心原理就是连到 mysql 实例,执行一些 sql,解析输出内容,整理为监控数据上报,使用categraf进行采集(如果没有安装那就去看看部署篇)
首先修改Configuration
categraf的conf/input.mysql/mysql.toml
[[instances]] //主
address = "x.x.x.x:3306" //mysql主地址
username = "root" //登陆用户
password = "xxxxxxxxxxxxx" //登陆密码
labels = { instance="n9e-x.x.x.x:3306" } //标签用于指标识别
[[instances]] //从
address = "x.x.x.x:3306"
username = "root"
password = "xxxxxxxxxxxxx"
labels = { instance="n9e-x.x.x.x:3306" }
# 通过 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 = false
# 监控所有的table的磁盘占用大小
gather_table_size = false
# 是否采集系统表的大小,通过不用,所以默认设置为false
gather_system_table_size = false
# 通过 show slave status监控slave的情况,比较关键,所以默认采集
gather_slave_status = true
重启categraf
[root@ceph01 ~]# systemctl restart categraf
查看采集到的指标
[root@ceph01 categraf]# ls
categraf conf
[root@ceph01 categraf]# ./categraf --test --inputs mysql
夜莺平台查看指标
二、采集mongodb指标
mongodb 监控采集插件,由 mongodb-exporter封装而来
configuration
categraf的conf/input.mongodb/mongodb.toml
[[instances]] //主
log_level = "error"
labels = { instance="x.x.x.x:27017" }
mongodb_uri = "mongodb://用户:登陆密码@x.x.x.x:27017/用户"
collect_all = true
compatible_mode = true
[[instances]] //从1
log_level = "error"
labels = { instance="x.x.x.x:27017" }
mongodb_uri = "mongodb://用户:登陆密码@x.x.x.x:27017/用户"
collect_all = true
compatible_mode = true
[[instances]] //从2
log_level = "error"
labels = { instance="x.x.x.x:27017" }
mongodb_uri = "mongodb://用户:登陆密码@x.x.x.x:27017/用户"
collect_all = true
compatible_mode = true
重启categraf
[root@ceph01 ~]# systemctl restart categraf
查看采集到的指标
[root@ceph01 ~]# cd /data/categraf
[root@ceph01 categraf]# ls
categraf conf
[root@ceph01 categraf]# ./categraf --test --inputs mongodb
夜莺平台查看指标
三、采集redis指标
redis 的监控原理,就是连上 redis,执行 info 命令,解析结果,整理成监控数据上报。
configuration
redis 插件的配置在 conf/input.redis/redis.toml
最简单的配置如下:
监控多个 redis 实例,就增加 instances 即可
[[instances]] //主1
address = "x.x.x.x:26379"
password = "登陆密码"
labels = { instance="x.x.x.x:26379" }
[[instances]] //从1
address = "x.x.x.x:26380"
password = "登陆密码"
labels = { instance="x.x.x.x:26380" }
[[instances]] //主2
address = "x.x.x.x:26379"
password = "登陆密码"
labels = { instance="x.x.x.x:26379" }
[[instances]] //从2
address = "x.x.x.x:26380"
password = "登陆密码"
labels = { instance="x.x.x.x:26380" }
[[instances]] //主3
address = "x.x.x.x:26379"
password = "登陆密码"
labels = { instance="x.x.x.x:26379" }
[[instances]] //从3
address = "x.x.x.x:26380"
password = "登陆密码"
labels = { instance="x.x.x.x:26380" }
重启categraf
[root@ceph01 ~]# systemctl restart categraf
查看采集到的指标
[root@ceph01 ~]# cd /data/categraf
[root@ceph01 categraf]# ls
categraf conf
[root@ceph01 categraf]# ./categraf --test --inputs redis
夜莺平台查看指标
四、采集pgsql指标
categraf的conf/input.postgresql/postgresql.toml
[[instances]]
address = "host=192.168.11.181 port=5432 user=postgres password=123456789 sslmode=disable"
重启categraf
[root@ceph03 ~]# systemctl restart categraf
查看采集到的指标
[root@ceph03 ~]# cd /data/categraf
[root@ceph03 categraf]# ./categraf --test input postgresql
夜莺平台查看指标