Go教程

【MongoDB】Prometheus监控MongoDB

本文主要是介绍【MongoDB】Prometheus监控MongoDB,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

这里只是写了如何安装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

  

 

这篇关于【MongoDB】Prometheus监控MongoDB的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!