Docs 菜单
Docs 主页
/
MongoDB Atlas
/ /

与 Prometheus 集成

在此页面上

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

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

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

Atlas for Government 不支持 Prometheus 集成。

  • Prometheus 集成仅在 M10+ 集群可用。

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

  • 将托管 Prometheus 实例的设备的 IP 添加到 IP 访问列表。

    注意

    如果您将 0.0.0.0/0 添加到 IP 访问列表(该列表允许从公共互联网中的任何位置访问集群),Atlas 会禁用 Prometheus 集成。

    如果 0.0.0.0/0 已在 IP 访问列表中,Atlas 会阻止您配置 Prometheus 集成。

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

配置 Atlas 与 Prometheus 的集成 :

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

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

  3. Projects(项目)菜单旁边,展开 Options(选项)菜单,然后单击 Integrations(项目设置)。

    显示“项目集成”页面。

2
3

Prometheus 身份验证档案专门设计用于 MongoDB Atlas 中的 Prometheus 集成。 Atlas 使用这些凭证仅访问 Prometheus 发现端点,并从 Atlas 节点抓取 Prometheus 指标。它们仅限于这些功能,除了访问和收集监控数据之外没有任何其他权限或功能。

重要

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

4
探索方法
说明

此方法要求使用 Prometheus v2.28 及更高版本。它会自动生成配置文件scrape_config 部分,通过 HTTP 端点发现目标。

  1. 将托管 Prometheus 实例的设备的 IP 添加到 IP 访问列表。这授予 Prometheus 网络访问权限,以从您的 Atlas 集群中抓取指标。确保 0.0.0.0/0 不在清单上。拥有此条目将禁用集成。

  2. 在 Atlas 用户界面中的 Choose Discovery API Target Type 步骤中,执行以下任务之一:

    • 选择 Public Internet Targets

    • 选择 Private IP for Peering Targets

    Atlas 不支持 Prometheus 集成的私有端点。

  3. 将以下代码片段插入到 Prometheus.yml 文件的 scrape_configs 部分,并使用 Prometheus 集成的值对其进行更新。

    - job_name: "<insert-job-name>"
    scrape_interval: 10s
    metrics_path: /metrics
    scheme: https
    basic_auth:
    username: <insert-prometheus-user-id>
    password: <insert-password>
    http_sd_configs:
    - url: <url-of-the-service-discovery-configuration>
    refresh_interval: 60s
    basic_auth:
    username: <insert-prometheus-user-id>
    password: <insert-password>

此方法允许 Prometheus 读取 YAML 或 JSON 文档,以配置要抓取的目标。您负责向 Discovery API 发出请求并将其结果存储在 targets.json 文件,以此提供目标。

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

curl --header 'Accept: application/json'
# Sets the `Authorization` header on every scrape request with the
# username and password from the previous step.
--user <username>:<password>
# The URL that Prometheus fetches the targets from.
# Replace the <group-id> with the project ID of your Atlas instance.
--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 的最新目标

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

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

  2. 重新启动 Prometheus 实例。

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

以下给出当您使用 HTTP SDFile Service Discovery 方法时的配置文件的示例。

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

字段
说明
scrape_interval
时间,表示抓取目标的频率。该设置支持最短 10 秒。
job_name
分配给抓取指标的人类可读标签。
metrics_path
指示从何处获取目标指标的 HTTP 资源路径。
scheme
您想为请求配置的协议方案。
basic_auth
在每次抓取请求中使用的授权标头。

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

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

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

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

当您将 Prometheus 与 Atlas 集群集成时,以下指标可用:

每个 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_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_sectors_read
计数器
读取的扇区数。
hardware_disk_metrics_sectors_written
计数器
写入扇区数。
hardware_disk_metrics_total_time_milliseconds
计数器
此区块设备处于活动状态的总时间。
hardware_disk_metrics_weighted_time_io_milliseconds
计数器
用于 I/O 的加权时间。
hardware_disk_metrics_write_count
计数器
已处理的写 I/O 数量。
hardware_disk_metrics_write_time_milliseconds
计数器
写入请求的总等待时间。
hardware_platform_num_logical_cpus
仪表盘
当前进程可用的逻辑 CPU 数。
hardware_process_cpu_children_kernel_milliseconds
计数器
在内核模式下为此进程安排的等待子级的时间量。
hardware_process_cpu_children_user_milliseconds
计数器
在用户模式下为此进程安排的等待子级的时间量。
hardware_process_cpu_kernel_milliseconds
计数器
在内核模式下为此进程安排的时间量。
hardware_process_cpu_user_milliseconds
计数器
在使用模式下为此进程安排的时间量。
hardware_system_cpu_guest_milliseconds
计数器
在 Linux 内核的控制下为客户机操作系统运行虚拟 CPU 所花费的时间。
hardware_system_cpu_guest_nice_milliseconds
计数器
调整优先级后运行客户机所花费的时间。
hardware_system_cpu_idle_milliseconds
计数器
在空闲任务中花费的时间。
hardware_system_cpu_io_wait_milliseconds
计数器
等待 I/O 完成的时间。
hardware_system_cpu_irq_milliseconds
计数器
服务中断花费的时间。
hardware_system_cpu_kernel_milliseconds
计数器
在系统模式下花费的时间。
hardware_system_cpu_nice_milliseconds
计数器
在低优先级用户模式 (nice) 下所用的时间。
hardware_system_cpu_soft_irq_milliseconds
计数器
修复 softirqs 所用的时间。
hardware_system_cpu_steal_milliseconds
计数器
在虚拟环境中运行时在其他操作系统中花费的时间。
hardware_system_cpu_user_milliseconds
计数器
在用户模式下花费的时间。
hardware_system_memory_buffers_kilobytes
仪表盘
原始磁盘区块的临时存储,不应变得非常大。
hardware_system_memory_cached_kilobytes
仪表盘
从磁盘读取文件的内存缓存。其中不包括 SwapCached
hardware_system_memory_mem_available_kilobytes
仪表盘
在不进行交换的情况下,估计有多少内存可用于启动新应用程序。
hardware_system_memory_mem_free_kilobytes
仪表盘
LowFree + HighFree 之和。
hardware_system_memory_mem_total_kilobytes
仪表盘
总可用 RAM(物理 RAM 减去几个保留位和内核二进制代码)。
hardware_system_memory_shared_mem_kilobytes
仪表盘
内容驻留在虚拟内存中的文件系统消耗的内存量。
hardware_system_memory_swap_free_kilobytes
仪表盘
未使用交换空间总量。
hardware_system_memory_swap_total_kilobytes
仪表盘
可用的交换空间总量。
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
计数器
接口传输的数据字节数。
hardware_system_vm_page_swap_in
计数器
系统已交换到磁盘的页面数量。
hardware_system_vm_page_swap_out
计数器
系统已交换到磁盘的页面数量。

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

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

后退

PagerDuty