进阶 uptime.kuma.pet 2026-11-20 10:30:00 · 3 阅读

第7章 Prometheus 集成

Prometheus 集成:向其他平台传递指标

如果您已经在使用 Prometheus.io,或支持 Prometheus exporter 格式的平台,您可以通过访问 `http://:/metrics` 获取各个监控目标的指标数据。

可用于筛选的标签(Labels)包括:

| 标签名称 | 描述 | | :--- | :--- | | monitor_name | 监控项的“友好名称”(Friendly Name) | | monitor_type | 监控检查类型(HTTP、关键字、TCP) | | monitor_url | 被监控的 URL(适用于 HTTP、关键字类型) | | monitor_hostname | 被监控的主机名(适用于 TCP 类型) | | monitor_port | 被监控的端口(适用于 TCP 类型) |

Prometheus 配置

请将以下内容添加到您的 Prometheus 配置文件中:

- job_name: "uptime" scrape_interval: 30s scheme: http metrics_path: "/metrics" static_configs: - targets: ["uptime-kuma.url"] basic_auth: # 仅在启用身份验证(默认设置)时需要 username: password:

提示

您也可以使用 API 密钥进行身份验证。一旦添加第一个 API 密钥,该端点将永久禁用基本身份验证(basic authentication)功能。

您应该能在 Prometheus 中看到 `monitor_response_time` 和 `monitor_status` 指标。

示例 PromQL 查询

假设我们针对 bbc.co.uk 和 google.com 设置了 HTTP 监控:

# 显示按站点分组的所有响应速率 sum(monitor_response_time) by (monitor_name)

# 仅显示 BBC.co.uk 的响应时间 sum(monitor_response_time{monitor_url="https://www.bbc.co.uk/"})

# 显示 Google.com 的当前状态 monitor_status{monitor_name="Google"}

关于 Cloudflare 的备注

默认情况下,Cloudflare 对包括 Uptime Kuma 在内的 API 请求并不友好,Cloudflare 可能会阻止来自 Uptime Kuma 的请求。

通过 CLI 重置密码

下一页

评论 (0)