Docs 菜单
Docs 主页
/
MongoDB Ops Manager
/ /

与 Prometheus 集成

在此页面上

  • 先决条件
  • 步骤
  • 示例配置
  • 适用于 Prometheus 的性能指标
  • MongoDB 指标标签
  • MongoDB 信息指标
  • 硬件指标
  • 硬件指标标签

Prometheus 按给定时间间隔从配置的目标收集指标,评估规则表达式,显示结果,并可在观察到特定条件时触发警报。

我们的集成允许您配置 Ops Manager,将有关部署的指标数据发送到 Prometheus 实例。

  • Prometheus 集成可在使用 MongoDB 助手 的12 自动化托管0 集群中使用。 。15 。7646 或更高版本。 MongoDB 助手12 。0 。15 。7646 与 Ops Manager6 一起发布。0 。7 。

  • 有一个正常工作的 Prometheus 实例。要设置工作实例,请参阅其 安装指南。

  • (可选)使用 Grafana 以可视化您的 Prometheus 指标。

将 Ops Manager 与 Prometheus 集成 :

1
  1. 如果尚未显示,请从导航栏的 Organizations 菜单中选择包含所需项目的组织。

  2. 如果尚未显示该页,请从导航栏的 Projects(项目)菜单中选择所需的项目。

  3. Projects菜单旁边,展开Options菜单,然后单击Integrations

2
3

重要

复制用户名和密码,将其存储在安全位置。离开此屏幕后,您将无法访问密码。

4

提示

默认值 0.0.0.0:9216会抓取本地计算机上所有 IPv4地址上端口9216上的指标。

5

如果启用此设置,Ops Manager 将确保 Prometheus 实例使用https来抓取指标。

字段
说明
TLS 证书密钥文件路径

PEM 文件路径,其中包含启动https Prometheus 抓取端点所需的证书和密钥。

您应对以下事项负责:

  • TLS 证书密钥文件的颁发和续订。

  • 在自动化代理日志中检查端点是否正确启动。

tlsCertificateKeyFilePassword
如果证书密钥文件已加密,则为必填项。
6
探索方法
说明
此方法需要 Prometheus v2 。28 及更高版本。它会生成 scrape_config 配置文件 的一部分 通过 HTTP 端点发现目标。

此方法允许 Prometheus 读取YAMLJSON文档,以配置要抓取的目标。

您负责通过向Discovery API发出请求并将其结果存储在targets.json文件中来提供目标。

如需发出请求,请替换以下选项卡中的占位符文本,或用其他语言创建自己的脚本。

# Sets the `Authorization` header on every scrape
# request with the username and password from the
# previous step. The URL that Prometheus fetches the
# targets from.
# Replace the <group-id> with the project ID of your
# Atlas instance.
curl --header 'Accept: application/json' \
--user <username>:<password> \
--request GET "https://cloud.mongodb.com/prometheus/v1.0/groups/{GROUP-ID}/discovery"

如果您需要安装requests 库,请参阅其 安装指南。

import time, json, requests
# This script sets the `Authorization` header on every
# scrape request with the configured username and
# password. Then it tells Prometheus to fetch targets
# from the specified URL.
#
# Note: Replace the <username> and <password> with the
# values in the previous step, and <group-id> with the
# project ID of your Atlas instance.
basic_auth_user="<username>"
basic_auth_password="<password>"
discovery_api_url="https://cloud.mongodb.com/prometheus/v1.0/groups/{GROUP-ID}/discovery"
# The script updates your targets.json file every
# minute, if it successfully retrieves targets.
#
# Note: Replace the <path-to-targets.json> with the
# path to your targets.json file.
starttime = time.time()
while True:
r = requests.get(discovery_api_url, auth=(basic_auth_user, basic_auth_password))
if r.status_code == 200:
with open('<path-to-targets.json>', 'w') as f:
json.dump(r.json(), f)
time.sleep(60.0 - ((time.time() - starttime) % 60.0))

要了解有关“发现 API”的更多信息,请参阅返回 Prometheus 的最新目标

7
8
  1. 将生成的代码片段复制到 scrape_configs 配置文件 的 部分 并替换占位符文本。

    有关这两种方法的配置文件示例,请参阅示例配置

  2. 重新启动 Prometheus 实例。

  3. 在 Prometheus 实例中,单击顶部导航栏中的 Status,然后单击 Targets 以查看部署的指标。

以下显示了 配置文件 的示例 当您使用HTTP Service 发现 文件服务发现 方法时。

这两种方法的配置文件都包含以下字段:

字段
说明
scrape_interval
时间,表示抓取目标的频率。该设置支持最短 10 秒。
job_name
分配给抓取指标的人类可读标签。
metrics_path
指示从何处获取目标指标的 HTTP 资源路径。
scheme
为请求配置的 Prometheus 协议模式,可以是httphttps 。 如果配置https ,则必须指定tlsPemPath
basic_auth
在每次抓取请求中使用的授权标头。

HTTP 服务发现方法还包含具有以下子字段的 http_sd_configs 字段:

字段
说明
url
Prometheus 从中获取目标的 URL。
refresh_interval
指示何时重新查询端点的时间。
basic_auth
用于向 API 服务器进行身份验证的凭据。
global:
scrape_interval: 15s
scrape_configs:
- job_name: "CM-Testing-mongo-metrics"
scrape_interval: 10s
metrics_path: /metrics
scheme : https
basic_auth:
username: prom_user_61e6e34e93eac1632d39f457
password: V7hTyLfkjwiWQbv
http_sd_configs:
- url: https://cloud.mongodb.com/prometheus/v1.0/groups/61e6e34e93eac1632d39f457/discovery
refresh_interval: 60s
basic_auth:
username: prom_user_61e6e34e93eac1632d39f457
password: V7hTyLfkjwiWQbv

“文件服务发现”方法还包含带有以下子字段的 file_sd_configs 字段:

字段
说明
files
包含要从中提取指标抓取目标的文件的列表。
global:
scrape_interval: 15s
scrape_configs:
- job_name: "CM-Testing-mongo-metrics"
scrape_interval: 10s
metrics_path: /metrics
scheme : https
basic_auth:
username: prom_user_61e6e34e93eac1632d39f457
password: V7hTyLfkjwiWQbv
file_sd_configs:
- files:
- /usr/local/etc/targets.json

当您使用 Prometheus 与MongoDB Atlas cluster 集成:

每个 MongoDB 指标都包含以下标签:

标签
说明
group_id
标识项目的唯一十六进制数字字符串。
org_id
标识组织的唯一十六进制数字字符串。
cl_role
人类可读标签,用于定义集群角色。
cl_name
用于标识集群的人类可读标签。
rs_nm
用于标识副本集的人类可读标签。
rs_state
表示副本集状态的数字。
process_port
进程运行的端口。

mongodb_info 是一个始终具有 1 值的仪表盘。该指标包含所有 MongoDB 指标标签以及以下标签:

标签
说明
mongodb_version
表示主要版本、次要版本和补丁的字符串。
replica_state_name
字符串,用于表示副本集成员状态
process_type
指示正在运行的进程的字符串。其值可以是 mongodmongosconfig

注意

您还可以在 Prometheus 表达式浏览器中查看每个硬件指标的说明。

名称
操作系统
类型
说明
hardware_system_cpu_nice
Unix、Darwin
计数器
在低优先级用户模式下花费的时间。
hardware_system_cpu_io_wait
Unix
计数器
等待 I/O 完成的时间。
hardware_system_cpu_irq
Unix
计数器
服务中断花费的时间。
hardware_system_cpu_soft_irq
Unix
计数器
服务软中断所花费的时间。
hardware_system_cpu_steal
Unix
计数器
在虚拟环境中运行时在其他操作系统中花费的时间。
hardware_system_cpu_guest
Unix
计数器
在 Linux 内核的控制下为客户机操作系统运行虚拟 CPU 所花费的时间。
hardware_system_cpu_guest_nice
Unix
计数器
调整优先级后运行客户机所花费的时间。
hardware_system_cpu_kernel_milliseconds
所有
计数器
在系统模式下花费的时间。
hardware_system_cpu_user_milliseconds
所有
计数器
在用户模式下花费的时间。
hardware_disk_metrics_weighted_time_io
Unix
计数器
用于 I/O 的加权时间。
hardware_disk_metrics_physical_write_count
Unix
计数器
已处理的物理写入 I/O 数量。
hardware_disk_metrics_physical_read_count
Unix
计数器
已处理的物理读 I/O 数量。
hardware_disk_metrics_total_time
Unix
计数器
此区块设备处于活动状态的总时间。
hardware_disk_metrics_idle_time
Windows
计数器
在空闲任务中花费的时间。
hardware_disk_metrics_disk_space_free_bytes
所有
仪表盘
已挂载文件系统中的可用磁盘空间。
hardware_disk_metrics_disk_space_used_bytes
所有
仪表盘
挂载的文件系统中使用的磁盘空间。
hardware_disk_metrics_read_count
所有
计数器
已处理的读取 I/O 数量。
hardware_disk_metrics_read_time_milliseconds
所有
计数器
读取请求的总等待时间。
hardware_disk_metrics_write_count
所有
计数器
已处理的写 I/O 数量。
hardware_disk_metrics_write_time_milliseconds
所有
计数器
写入请求的总等待时间。
hardware_process_cpu_children_user
Unix
计数器
在用户模式下为此进程安排的等待子级的时间量。
hardware_process_cpu_children_kernel
Unix
计数器
在内核模式下为此进程安排的等待子级的时间量。
hardware_process_cpu_kernel_milliseconds
所有
计数器
在内核模式下为此进程安排的时间量。
hardware_process_cpu_user_milliseconds
所有
计数器
在使用模式下为此进程安排的时间量。
hardware_system_vm_page_swap_in
Unix
计数器
系统已交换到磁盘的页面数量。
hardware_system_vm_page_swap_out
Unix
计数器
系统已交换到磁盘的页面数量。
hardware_system_memory_mem_total
Unix
仪表盘
总可用 RAM(物理 RAM 减去几个保留位和内核二进制代码)。
hardware_system_memory_mem_free
Unix
仪表盘
LowFree + HighFree 之和。
hardware_system_memory_mem_available
Unix
仪表盘
在不进行交换的情况下,估计有多少内存可用于启动新应用程序。
hardware_system_memory_buffers
Unix
仪表盘
原始磁盘区块的临时存储,不应变得非常大。
hardware_system_memory_cached
Unix
仪表盘
从磁盘读取文件的内存缓存。其中不包括 SwapCached
hardware_system_memory_swap_total
Unix
仪表盘
可用的交换空间总量。
hardware_system_memory_swap_free
Unix
仪表盘
未使用交换空间总量。
hardware_system_memory_shared_mem
Unix
仪表盘
内容驻留在虚拟内存中的文件系统消耗的内存量。
hardware_system_memory_swap_free_kilobytes
所有
仪表盘
未使用交换空间总量。
hardware_system_memory_swap_total_kilobytes
所有
仪表盘
可用的交换空间总量。
hardware_platform_num_logical_cpus
所有
仪表盘
当前进程可用的逻辑 CPU 数。
hardware_system_network_eth0_bytes_in_bytes
所有
计数器
接口接收的数据字节数。
hardware_system_network_eth0_bytes_out_bytes
所有
计数器
接口传输的数据字节数。
hardware_system_network_lo_bytes_in_bytes
所有
计数器
接口接收的数据字节数。
hardware_system_network_lo_bytes_out_bytes
所有
计数器
接口传输的数据字节数。

每个硬件指标都包含以下标签:

标签
说明
group_id
标识项目的唯一十六进制数字字符串。
org_id
标识组织的唯一十六进制数字字符串。
process_port
进程运行的端口。
disk_name
标识磁盘的人类可读标签。

后退

与 PagerDuty 集成