这里只是写了如何安装mongodb_exporter。
其他部分参看:https://www.cnblogs.com/abclife/p/16659151.html
下载和安装
sudo wget https://github.com/percona/mongodb_exporter/releases/download/v0.34.0/mongodb_exporter-0.34.0.linux-amd64.tar.gz sudo tar -zxvf mongodb_exporter-0.34.0.linux-amd64.tar.gz -C /usr/local/ sudo ln -s /usr/local/mongodb_exporter-0.34.0.linux-amd64/ /usr/local/mongodb_exporter sudo chown -R prometheus:prometheus /usr/local/mongodb_exporter*
创建mongodb用户
use admin db.dropUser("mongodb_exporter"); db.getSiblingDB("admin").createRole({ role: "explainRole", privileges: [{ resource: { db: "", collection: "" }, actions: [ "listIndexes", "listCollections", "dbStats", "dbHash", "collStats", "find" ] }], roles:[] }) db.getSiblingDB("admin").createUser({ user: "mongodb_exporter", pwd: "pwd123", roles: [ { role: "explainRole", db: "admin" }, { role: "clusterMonitor", db: "admin" }, { role: "read", db: "local" } ] })
配置成服务
cd /lib/systemd/system/ sudo touch mongodb_exporter.service sudo vi mongodb_exporter.service
添加以下内容:
[Unit] Description=MongoDB Exporter User=prometheus [Service] Type=simple Restart=always Environment="MONGODB_URI=mongodb://mongodb_exporter:pwd123@localhost:27017/admin?ssl=false" ExecStart=/usr/local/mongodb_exporter/mongodb_exporter --collect-all --log.level=error [Install] WantedBy=multi-user.target
sudo systemctl daemon-reload sudo systemctl restart mongodb_exporter.service sudo systemctl enable mongodb_exporter.service
查看
http://localhost:9216/metrics