Prometheus监控MongoDB

1 下载mongodb exporter

https://github.com/percona/mongodb_exporter

2 systemd 管理mongodb exporter

service文件: /usr/lib/systemd/system/mongodb_exporter.service

[Unit]
Description=mongodb_exporter
Documentation=https://github.com/percona/mongodb_exporter
After=network.target

[Service]
ExecStart=/usr/local/src/mongodb_exporter/mongodb_exporter --mongodb.uri "mongodb://monitoruser:9iHjhLj4dC@172.16.53.123:29017" --collect-all --compatible-mode
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure


[Install]
WantedBy=multi-user.target

[Unit]
Description=mongodb_exporter
After=network.target

mongodb_exporter的监控指标和旧版本有变化,添加--compatible-mode参数,兼容旧指标。

[root@iZderaqgnji3m0Z mongodb_exporter]# ./mongodb_exporter --help
Usage: mongodb_exporter

MongoDB Prometheus exporter

Flags:
  -h, --help                                          Show context-sensitive help.
      --mongodb.collstats-colls=db1,db2.col2          List of comma separared databases.collections to get $collStats
      --mongodb.indexstats-colls=db1.col1,db2.col2    List of comma separared databases.collections to get $indexStats
      --mongodb.uri=mongodb://user:pass@127.0.0.1:27017/admin?ssl=true
                                                      MongoDB connection URI ($MONGODB_URI)
      --[no-]mongodb.global-conn-pool                 Use global connection pool instead of creating new pool for each http request.
      --[no-]mongodb.direct-connect                   Whether or not a direct connect should be made. Direct connections are not valid if multiple hosts are specified
                                                      or an SRV URI is used.
      --web.listen-address=":9216"                    Address to listen on for web interface and telemetry
      --web.telemetry-path="/metrics"                 Metrics expose path
      --web.config=STRING                             Path to the file having Prometheus TLS config for basic auth
      --log.level="error"                             Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]
      --collector.diagnosticdata                      Enable collecting metrics from getDiagnosticData
      --collector.replicasetstatus                    Enable collecting metrics from replSetGetStatus
      --collector.dbstats                             Enable collecting metrics from dbStats
      --collector.topmetrics                          Enable collecting metrics from top admin command
      --collector.indexstats                          Enable collecting metrics from $indexStats
      --collector.collstats                           Enable collecting metrics from $collStats
      --metrics.overridedescendingindex               Enable descending index name override to replace -1 with _DESC
      --collect-all                                   Enable all collectors. Same as specifying all --collector.<name>
      --collector.collstats-limit=0                   Disable collstats, dbstats, topmetrics and indexstats collector if there are more than <n> collections. 0=No limit
      --[no-]discovering-mode                         Enable autodiscover collections
      --[no-]compatible-mode                          Enable old mongodb-exporter compatible metrics
      --version                                       Show version and exit

3 启动exporter

systemctl start mongodb_exporter.service

systemctl stop mongodb_exporter.service

systemctl enable mongodb_exporter.service

4 prometheus动态发现

prometheus.yml

  - job_name: 'mongodb_monitor'
    scrape_interval: 1m
    file_sd_configs:
     - files:
        - /usr/local/src/prometheus/conf.d/mongodb.json

mongodb.json

[
  {
    "labels": {
      "desc": "mongodb",
      "group": "mongodb",
      "host_ip": "172.16.53.117"
    },
    "targets": [
      "172.16.53.117:9216"
    ]
  }
]

5 Grafana dashboard

ID:7353

dashboard有些指标展示不出来,需要调试一下。

6 参考文章

How To Monitor MongoDB with Grafana and Prometheus on Ubuntu 20.04

https://www.digitalocean.com/community/tutorials/how-to-monitor-mongodb-with-grafana-and-prometheus-on-ubuntu-20-04

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值