• Prometheus监控MongoDB数据库


    监控环境:Prometheus

    数据库:MongoDB 3.4.6 集群,3个节点

    监控工具:mongodb_exporter

    我这个模板是自己二次开发的。使用mongodb_exporter 监控 阿里云的MongoDB数据库

    各位根据自己的需求进行使用

    1、创建Mongodb监控可读账号

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

    2、下载MongoDB监控软件

    地址:  https://github.com/percona/mongodb_exporter
    

    我使用的:mongodb_exporter-0.11.2.linux-amd64.tar.gz 版本

    3、配置文件

    nohup  ./mongodb_exporter --mongodb.uri mongodb://root:heian@192.168.82.105:27017/admin --collect.database --collect.collection --collect.topmetrics  --collect.indexusage  --collect.connpoolstats --suppress.collectshardingstatus  &

    mongodb_exporter暴露的endpoint端口默认为9216

    1. [root@prometheus-server exporter]# ./mongodb_exporter --help
    2. usage: mongodb_exporter []
    3. exports various MongoDB metrics in Prometheus format.
    4. Flags:
    5. -h, --help Show context-sensitive help (also try --help-long and --help-man).
    6. --web.auth-file=WEB.AUTH-FILE
    7. Path to YAML file with server_user, server_password keys for HTTP Basic authentication (overrides HTTP_AUTH environment variable).
    8. --web.ssl-cert-file=WEB.SSL-CERT-FILE
    9. Path to SSL certificate file.
    10. --web.ssl-key-file=WEB.SSL-KEY-FILE
    11. Path to SSL key file.
    12. --web.listen-address=":9216"
    13. Address to listen on for web interface and telemetry.
    14. --web.telemetry-path="/metrics"
    15. Path under which to expose metrics.
    16. --collect.database Enable collection of Database metrics
    17. --collect.collection Enable collection of Collection metrics
    18. --collect.topmetrics Enable collection of table top metrics
    19. --collect.indexusage Enable collection of per index usage stats
    20. --collect.connpoolstats Collect MongoDB connpoolstats
    21. --suppress.collectshardingstatus
    22. Suppress the collection of Sharding Status
    23. --mongodb.uri=[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]
    24. MongoDB URI, format
    25. --test Check MongoDB connection, print buildInfo() information and exit.
    26. --version Show application version.
    27. --log.level="info" Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]
    28. --log.format="logger:stderr"
    29. Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"

    1. 配置启动服务
    2. vim /usr/lib/systemd/system/mongodb_exporter.service
    3. [Unit]
    4. Description=mongodb_exporter
    5. Documentation=https://github.com/percona/mongodb_exporter
    6. After=network.target
    7. [Service]
    8. Type=simple
    9. User=prometheus
    10. Environment="MONGODB_URI=mongodb://mongodb_exporter:123456@localhost:27017"
    11. ExecStart=/usr/local/bin/mongodb_exporter --log.level=error \
    12. --collect.database \
    13. --collect.collection \
    14. --collect.topmetrics \
    15. --collect.indexusage \
    16. --collect.connpoolstats
    17. Restart=on-failure
    18. [Install]
    19. WantedBy=multi-user.target

    4、prometheus配置基于文件的自动发现

    1. - job_name: 'mongo_cluster'
    2. file_sd_configs:
    3. - files: ['/usr/local/prometheus/sd_config/mongo_cluster.yaml']
    4. refresh_interval: 5s
    5. root:/usr/local/prometheus# cat /usr/local/prometheus/sd_config/mongo_cluster.yaml
    6. - targets:
    7. - "192.168.88.140:9216"
    8. - "192.168.88.141:9216"
    9. - "192.168.88.142:9216"
    10. labels:
    11. project: mongo
    12. unitname: "Mongodb_exporter"
    13. service: mongo

    5、grafana配置mongo展示图

    导入图:16974

    MongoDB信息 | Grafana Labs  (这个模板是自己绘制的,有基础的可以二次开发)

  • 相关阅读:
    Java Matcher.find()方法具有什么功能呢?
    STM32的命名含义
    几分钟实现对恶意IP地址进行拦截,腾讯云Web防火墙实在太香了!
    bp神经网络数据预测实例,bp网络神经预测模型
    《算法通关村—轻松搞定合并二叉树》
    Reids实战——优惠券秒杀(全局唯一ID生成策略)
    从服务智能化中寻找新增量
    Kubernetes 深入理解kubernetes(一)
    【具身智能】RT-2:视觉-语言-动作模型(VLA)
    iOS 17 Simulator Failed with HTTP status 400:bad request
  • 原文地址:https://blog.csdn.net/heian_99/article/details/126884386