返回顶部
p

prometheus查询Prometheus指标

Query Prometheus monitoring metrics, alerts, and cluster status. Use when user needs to: (1) Query firing/pending alerts, (2) Check cluster/node/pod status, (3) Get nginx request metrics, (4) Query any PromQL metrics from Prometheus, (5) Monitor system health and performance. Accepts parameters like metric_name, query_type, time_range, prom_url.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
117
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

prometheus

Prometheus 监控查询

从 Prometheus 查询指标、告警和集群状态。

两种访问模式

1. 直接 URL 访问(推荐)

当 Prometheus 可通过网络访问时使用(云服务、远程服务器等):

bash

使用远程 Prometheus URL


python scripts/query_prometheus.py \
--prom-url https://prometheus.example.com \
--query up

查询告警

python scripts/query_prometheus.py \ --prom-url https://prometheus.example.com \ --alerts

2. Kubernetes 端口转发

当 Prometheus 仅可通过 kubectl 访问时使用:

bash

终端 1:端口转发 Prometheus


kubectl port-forward -n prometheus svc/prometheus 9090:9090

终端 2:查询指标

python scripts/query_prometheus.py \ --prom-url http://localhost:9090 \ --query up

查询脚本

使用 scripts/query_prometheus.py 查询指标:

bash

查询特定指标(默认:http://localhost:9090)


python scripts/query_prometheus.py --query up

显式指定 URL

python scripts/query_prometheus.py \ --prom-url http://localhost:9090 \ --query rate(httprequeststotal[5m])

查询告警

python scripts/query_prometheus.py --alerts

默认值: 如果未指定 --prom-url,则使用 http://localhost:9090。

常见查询类型

告警

promql

所有触发中的告警


ALERTS{alertstate=firing}

待处理的告警

ALERTS{alertstate=pending}

集群状态

promql

节点状态


kubenodestatus_condition{condition=Ready}

Pod 状态

kubepodstatus_phase{phase=Running} kubepodstatus_phase{phase=Failed}

命名空间 Pod 数量

count by (namespace) (kubepodinfo)

Nginx 指标

promql

请求速率


rate(nginxhttprequests_total[5m])

连接统计

nginxconnectionsactive nginxconnectionsreading nginxconnectionswriting nginxconnectionswaiting

请求持续时间(p99)

histogramquantile(0.99, rate(nginxhttprequestdurationsecondsbucket[5m]))

自定义指标

替换为实际指标名称:

promql

当前值


5 分钟速率

rate([5m])

1 小时平均值

avg([1h])

参数

  • - prom-url:Prometheus URL(默认:http://localhost:9090)
  • query:PromQL 查询字符串
  • alerts:查询所有告警及其状态的标志
  • time:评估时间戳(ISO 8601)
  • start:范围查询的开始时间
  • end:范围查询的结束时间
  • step:查询分辨率步长(用于范围查询)
  • timeout:查询超时时间(秒,默认:30)

输出

返回格式化后的指标结果。对于即时查询,返回当前值。对于告警,返回告警名称、状态(触发中/待处理)和标签。

示例

检查集群健康状态

bash

所有触发中的告警


python scripts/query_prometheus.py --alerts

节点状态

python scripts/queryprometheus.py --query kubenodestatuscondition{condition=Ready}

Nginx 负载

bash

请求速率


python scripts/queryprometheus.py --query rate(nginxhttprequeststotal[5m])

活跃连接数

python scripts/queryprometheus.py --query nginxconnections_active

自定义指标

bash
python scripts/queryprometheus.py --query mycustom_metric
python scripts/queryprometheus.py --query rate(mycustom_metric[5m])

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 prometheus-query-1775931782 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 prometheus-query-1775931782 技能

通过命令行安装

skillhub install prometheus-query-1775931782

下载

⬇ 下载 prometheus v1.0.0(免费)

文件大小: 3.52 KB | 发布时间: 2026-4-12 11:06

v1.0.0 最新 2026-4-12 11:06
- Major refactor: Migrated from Node.js CLI-based implementation to a single Python script for querying Prometheus.
- Added scripts/query_prometheus.py as the new entry point; previous Node.js-related files removed.
- SKILL.md rewritten for new workflow: focuses on direct Prometheus URL or Kubernetes port-forward for connectivity.
- CLI usage is now via Python, with support for querying metrics, alerts, and customizable parameters.
- Legacy support for multi-instance, config files, and Node.js CLI commands has been removed.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部