Prometheus监控MongoDB
创始人
2024-05-24 09:25:27
0

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_exporterMongoDB Prometheus exporterFlags:-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=trueMongoDB 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 specifiedor 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.--collector.collstats-limit=0                   Disable collstats, dbstats, topmetrics and indexstats collector if there are more than  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: 1mfile_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

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...