首页 > 数据库 >Prometheus监控MongoDB数据库

Prometheus监控MongoDB数据库

时间:2024-04-30 18:22:18浏览次数:14  
标签:exporter -- MongoDB 数据库 prometheus collect Prometheus mongodb

监控环境:Prometheus

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

监控工具:mongodb_exporter

 

1、创建Mongodb监控可读账号

 
mongodb admin 库中执行

use admin
db.createUser({ 
    user: "prometheus",
    pwd: "prometheus",
    roles: [
        { role: "read", db: "admin" },
        { role: "readAnyDatabase", db: "admin" },
        { role: "clusterMonitor", db: "admin" }
    ]
});

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:[email protected]:27017/admin --collect.database --collect.collection --collect.topmetrics  --collect.indexusage  --collect.connpoolstats --suppress.collectshardingstatus  &

mongodb_exporter暴露的endpoint端口默认为9216

 
[root@prometheus-server exporter]# ./mongodb_exporter --help
usage: mongodb_exporter [<flags>]

exports various MongoDB metrics in Prometheus format.

Flags:
  -h, --help                   Show context-sensitive help (also try --help-long and --help-man).
      --web.auth-file=WEB.AUTH-FILE  
                               Path to YAML file with server_user, server_password keys for HTTP Basic authentication (overrides HTTP_AUTH environment variable).
      --web.ssl-cert-file=WEB.SSL-CERT-FILE  
                               Path to SSL certificate file.
      --web.ssl-key-file=WEB.SSL-KEY-FILE  
                               Path to SSL key file.
      --web.listen-address=":9216"  
                               Address to listen on for web interface and telemetry.
      --web.telemetry-path="/metrics"  
                               Path under which to expose metrics.
      --collect.database       Enable collection of Database metrics
      --collect.collection     Enable collection of Collection metrics
      --collect.topmetrics     Enable collection of table top metrics
      --collect.indexusage     Enable collection of per index usage stats
      --collect.connpoolstats  Collect MongoDB connpoolstats
      --suppress.collectshardingstatus  
                               Suppress the collection of Sharding Status
      --mongodb.uri=[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]  
                               MongoDB URI, format
      --test                   Check MongoDB connection, print buildInfo() information and exit.
      --version                Show application version.
      --log.level="info"       Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]
      --log.format="logger:stderr"  
                               Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"

 

 
配置启动服务
vim /usr/lib/systemd/system/mongodb_exporter.service
[Unit]
Description=mongodb_exporter
Documentation=https://github.com/percona/mongodb_exporter
After=network.target

[Service]
Type=simple
User=prometheus
Environment="MONGODB_URI=mongodb://mongodb_exporter:123456@localhost:27017"
ExecStart=/usr/local/bin/mongodb_exporter --log.level=error \
  --collect.database \
  --collect.collection \
  --collect.topmetrics \
  --collect.indexusage \
  --collect.connpoolstats

Restart=on-failure

[Install]
WantedBy=multi-user.target

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

 
  - job_name: 'mongo_cluster'
    file_sd_configs:
      - files: ['/usr/local/prometheus/sd_config/mongo_cluster.yaml']
        refresh_interval: 5s
root:/usr/local/prometheus# cat /usr/local/prometheus/sd_config/mongo_cluster.yaml
- targets:
        - "192.168.88.140:9216"
        - "192.168.88.141:9216"
        - "192.168.88.142:9216"
  labels:
          project: mongo
          unitname: "Mongodb_exporter"
          service: mongo

5、grafana配置mongo展示图

导入图:16974

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

 

 

 


__EOF__

 
  • 本文作者: 南宫乘风
  • 本文链接: https://www.cnblogs.com/heian99/p/16712479.html
  • 关于博主: 评论和私信会在第一时间回复。或者直接私信我。
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
  • 声援博主: 如果您觉得文章对您有帮助,可以点击文章右下角推荐】一下。
  人生得意须尽欢,莫使金樽空对月。 天生我材必有用,千金散尽还复来。       南宫乘风
粉丝 - 76 关注 - 6     +加关注 0 0       « 上一篇: Jenkins集成Kubernetes集群
» 下一篇: Prometheus监控进程

标签:exporter,--,MongoDB,数据库,prometheus,collect,Prometheus,mongodb
From: https://www.cnblogs.com/gaoyanbing/p/18168546

相关文章

  • Java实现自定义指标数据远程写入Prometheus
    主要的流程如下:1>prometheus添加启动参数2>调用http请求来远程写,数据格式是protobuf(一种自定义的编码格式),编码格式是snappy(一种压缩格式)3>远程写通过snappy先压缩,然后将通过protobuf编码的字节数组发送请求;prometheus官网文档远程写提供remote.proto(包含编码和解码),remote.pr......
  • simpread-课程 24:工作单元之数据库事务【AOP】
    一、工作单元事务代码分析在上一个课程,我们已经实现了数据库事务功能,来保证数据的完整性。通过上一个课程的实现方式,我们在每一个Action开头和结尾,都需要添加对应的代码,才能实现事务功能,具体见以下截图:这种实现方式存在以下2个问题:在具体业务开发中,一个请求往往都会涉......
  • JDBC与各数据库产品连接的驱动及URL示例
    数据库驱动类JDBC连接Oracleoracle.jdbc.driver.OracleDriverjdbc:oracle:thin:@//127.0.0.1:1521/SchemaNameSQLServercom.microsoft.sqlserver.jdbc.SQLServerDrivernet.sourceforge.jtds.jdbc.Driverjdbc:sqlserver://127.0.0.1:1433;databa......
  • openGauss 创建和管理数据库
    创建和管理数据库前提条件用户必须拥有数据库创建的权限或者是数据库的系统管理员权限才能创建数据库,赋予创建数据库的权限参见管理用户及权限。背景信息初始时,openGauss包含两个模板数据库template0、template1,以及一个默认的用户数据库postgres。postgres默认的兼容数据库......
  • openGauss 归档账本数据库
    归档账本数据库前提条件系统中需要有审计管理员或者具有审计管理员权限的角色。数据库正常运行,并且对防篡改数据库执行了一系列增、删、改等操作,保证在查询时段内有账本操作记录结果产生。数据库已经正确配置审计文件的存储路径audit_directory。背景信息账本数据库归档......
  • openGauss 管理数据库安全
    管理数据库安全客户端接入认证管理用户及权限设置数据库审计设置账本数据库详情查看:https://opengauss.org详情查看:https://docs-opengauss.osinfra.cn......
  • 使用PowerDesigner连接数据库并反向工程生成所有表及关系
    配置对数据库的JDBC连接时,总是提示连接失败!也没有任何其他信息,查阅网上资料并实际验证,按如下步骤可以成功:1、因为PowerDesigner是32位的程序,需要使用x86-32位版本的JDK2、配置PowerDesigner-》Tools-》GeneralOptions-》variables ,配置jar、java等路径配置为32位JDK3、......
  • openGauss 数据库基础概念介绍
    相关概念数据库数据库用于管理各类数据对象,与其他数据库隔离。创建数据对象时可以指定对应的表空间,如果不指定相应的表空间,相关的对象会默认保存在PG_DEFAULT空间中。数据库管理的对象可分布在多个表空间上。表空间在openGauss中,表空间是一个目录,可以存在多个,里面存储的是它所......
  • openGauss 设置账本数据库
    设置账本数据库账本数据库概述查看账本历史操作记录校验账本数据一致性归档账本数据库修复账本数据库详情查看:https://opengauss.org详情查看:https://docs-opengauss.osinfra.cn......
  • openGauss 设置数据库审计
    设置数据库审计审计概述查看审计结果维护审计日志设置文件权限安全策略统一审计策略概述详情查看:https://opengauss.org详情查看:https://docs-opengauss.osinfra.cn......