Prometheus监控MongoDB

news/2024/5/19 0:30:55 标签: mongodb, prometheus

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_exporter

MongoDB Prometheus exporter

Flags:
  -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=true
                                                      MongoDB 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 specified
                                                      or 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.<name>
      --collector.collstats-limit=0                   Disable collstats, dbstats, topmetrics and indexstats collector if there are more than <n> 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: 1m
    file_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


http://www.niftyadmin.cn/n/50760.html

相关文章

威胁情报是什么

文章目录前言一、威胁情报是什么&#xff1f;数据与情报IOC二、威胁情报的分类1.战略情报2.技术情报3.战术情报4.运营情报三、总结四、参考前言 只要有斗争冲突&#xff0c;就有那些研究、分析和努力去了解对手的人。一场战争的输赢&#xff0c;取决于你对对手的了解&#xff0…

关于华为网络设备操作系统的介绍

1、什么是VRP VRP是华为公司数据通信产品的通用操作系统平台&#xff0c;作为华为公司从低端到核心的全系列路由器、以太网交换机、业务网关等产品的软件核心引擎。 功能&#xff1a;实现统一的用户界面和管理界面、实现控制平面功能&#xff0c;并定义转发平面接口规范、实现…

从0开始学python -26

Python3 迭代器与生成器 迭代器 迭代是Python最强大的功能之一&#xff0c;是访问集合元素的一种方式。 迭代器是一个可以记住遍历的位置的对象。 迭代器对象从集合的第一个元素开始访问&#xff0c;直到所有的元素被访问完结束。迭代器只能往前不会后退。 迭代器有两个基本…

【数据结构-JAVA】排序

排序在现实生活中的应用可谓相当广泛&#xff0c;比如电商平台中&#xff0c;选购商品时&#xff0c;使用价格排序或是综合排序、高考填报志愿的时候&#xff0c;会参考全国大学排名的情况。下面介绍一些计算机中与排序相关的概念&#xff1a;排序&#xff1a;所谓排序&#xf…

Python @property详解

Python property详解 Python的装饰器,用来修饰方法,使调用方法变成读取属性 作用&#xff1a; 使用property装饰器来创建只读属性&#xff0c;property装饰器会将方法转换为相同名称的只读属性,可以与所定义的属性配合使用&#xff0c;这样可以防止属性被修改 使用方式: 1…

Dubbo 源码分析 – 集群容错之 LoadBalance

一致性 hash 算法由麻省理工学院的 Karger 及其合作者于1997年提供出的&#xff0c;算法提出之初是用于大规模缓存系统的负载均衡。它的工作过程是这样的&#xff0c;首先根据 ip 获取其他的信息为缓存节点生成一个 hash&#xff0c;并将这个 hash 投射到 [0, 232 – 1] 的圆环…

学习数据库第一天

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录前言一、数据库的开启和关闭二、数据库的登录 添加数据库以及表1.登录数据库2.查看数据库三 数据表前言 提示&#xff1a;这里可以添加本文要记录的大概内容&#x…

终于找到blender渲染总是崩溃的原因了

如果您开始渲染&#xff0c;Blender 会崩溃&#xff0c;并在渲染过程中自动关闭&#xff0c;可能是由于这两个主要原因之一。Blender 用完了可用内存显卡有问题在本文中&#xff0c;我们将了解如何处理 Blender 在渲染时崩溃的情况。Blender内存不足如果我们从 RAM 问题开始。要…