文章目录
一、下载linux版本的mongodb_exporter
下载地址:https://github.com/percona/mongodb_exporter
wget https://github.com/percona/mongodb_exporter/releases/download/v0.35.0/mongodb_exporter-0.35.0.linux-amd64.tar.gza
二、解压安装包
tar -zxf mongodb_exporter-0.35.0.linux-amd64.tar.gz -C /usr/local
mv /usr/local/mongodb_exporter-* /usr/local/mongodb_exporter
ll /usr/local/mongodb_exporter
三、创建启动服务文件
vim /usr/lib/systemd/system/mongodb_exporter.service
[Unit]
Description=mongodb_exporter
After=network.target
Documentation= https://github.com/percona/mongodb_exporter
[Service]
Type=simple
ExecStart=/usr/local/mongodb_exporter/mongodb_exporter \
--mongodb.uri=mongodb://用户名:密码@192.158.134.12:27017 \
--web.listen-address=:9105
--collect-all # 默认不收集数据,需要加此参数收集全部数据
Restart=on-failure
[Install]
WantedBy=multi-user.target
四、启动服务
systemctl daemon-reload
systemctl enable --now mongodb_exporter
五、查看端口和服务
ss -nltp|grep 9105
systemctl status mongodb_exporter
六、prometheus-server配置
prometheus.yml配置
scrape_configs:
- job_name: 'mongodb-exporter'
file_sd_configs:
- files:
- targets/mongodb*.yaml
refresh_interval: 2m
relabel_configs:
- source_labels: [ '__address__' ]
target_label: 'instance'
regex: "(.*):.*"
replacement: $1
elasticsearch_exporter.yaml
[root@test targets]# cat mongodb_exporter.yaml
- targets:
- 192.158.134.12:9105
- 192.158.134.13:9105
- 192.158.134.14:9105
labels:
app: "Mongodb数据库集群"
job: "Mongodb数据库集群"
# mongodb进程标签
mongodbstatus: " 恢复正常"
mongodbconn: "连接数小于最大连接数的80%,"
mongodbprogram: "mongodb"
mongodbtype: "服务"
七、动态重启配置文件
kill -HUP `pgrep prometheus`
八、Mongodb_exporter对应的PromSql参数说明
mongodb_ss_connections # 根指标
mongodb_ss_connections{state="current"} # 表示当前连接数
mongodb_ss_connections{state="available"} # 可用的连接数