Prometheus监控MongoDB

这里只是对prometheus监控MongoDB的配置过程做个记录,方便以后查阅。

1.下载mongodb_exporter

1
https://github.com/percona/mongodb_exporter

2.配置mongodb_exporter

1
2
3
tar xf mongodb_exporter-0.11.2.linux-amd64.tar.gz
mkdir mongodb_exporter
mv downloads/mongodb_exporter mongodb_exporter/

3.配置用于监控mongodb的账户权限

mongodb admin库中执行

1
2
3
4
5
6
7
8
9
10
use admin
db.createUser({
user: "prometheus",
pwd: "1111111111111111",
roles: [
{ role: "read", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
{ role: "clusterMonitor", db: "admin" }
]
});

4.启动mongodb_exporter

1
/work/admin/mongodb_exporter/mongodb_exporter --web.listen-address=:9002 --mongodb.uri mongodb://prometheus:1111111111111111@dds-2zeb67fd071be3541.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-13285847

5.prometheus配置

1
2
3
4
5
6
- job_name: 'ops'
static_configs:
- targets: ['192.168.6.216:9100']
labels: {cluster: 'product',type: 'basic',env: 'ops',job: 'ops',export: 'ops'}
- targets: ['192.168.6.216:9002']
labels: {cluster: 'product',type: 'middle',env: 'bj-server-mongodb',job: 'bj-server-mongodb',export: 'bj-server-mongodb-exporter'}

重启prometheus

如果开启了api管理功能,可以如下方式热加载配置

1
curl -X POST http://127.0.0.1:9090/-/reload

6.grafana出图

推荐使用2583

效果如下

-------------本文结束感谢您的阅读-------------