返回顶部
p

prometheus查询Prometheus数据

Query Prometheus monitoring data to check server metrics, resource usage, and system health. Use when the user asks about server status, disk space, CPU/memory usage, network stats, or any metrics collected by Prometheus. Supports multiple Prometheus instances with aggregated queries, config file or environment variables, and HTTP Basic Auth.

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

prometheus

Prometheus 技能

从一个或多个实例查询 Prometheus 监控数据。支持通过单个命令跨多个 Prometheus 服务器进行联邦查询。

快速开始

1. 初始设置

运行交互式配置向导:

bash
cd ~/.openclaw/workspace/skills/prometheus
node scripts/cli.js init

这将在你的 OpenClaw 工作区(~/.openclaw/workspace/prometheus.json)中创建一个 prometheus.json 配置文件。

2. 开始查询

bash

查询默认实例


node scripts/cli.js query up

一次性查询所有实例

node scripts/cli.js query up --all

列出已配置的实例

node scripts/cli.js instances

配置

配置文件位置

默认情况下,该技能会在你的 OpenClaw 工作区中查找配置:

~/.openclaw/workspace/prometheus.json

优先级顺序:

  1. 1. PROMETHEUS_CONFIG 环境变量指定的路径
  2. ~/.openclaw/workspace/prometheus.json
  3. ~/.openclaw/workspace/config/prometheus.json
  4. ./prometheus.json(当前目录)
  5. ~/.config/prometheus/config.json

配置格式

在你的工作区中创建 prometheus.json(或使用 node cli.js init):

json
{
instances: [
{
name: production,
url: https://prometheus.example.com,
user: admin,
password: secret
},
{
name: staging,
url: http://prometheus-staging:9090
}
],
default: production
}

字段说明:

  • - name — 实例的唯一标识符
  • url — Prometheus 服务器 URL
  • user / password — 可选的 HTTP 基本认证凭据
  • default — 未指定时使用的默认实例

环境变量(旧版)

对于单实例设置,可以使用环境变量:

bash
export PROMETHEUS_URL=https://prometheus.example.com
export PROMETHEUS_USER=admin # 可选
export PROMETHEUS_PASSWORD=secret # 可选

使用方法

全局标志

标志描述
-c, --config <path>配置文件路径
-i, --instance <name>
指定目标实例 | | -a, --all | 查询所有已配置的实例 |

命令

设置

bash

交互式配置向导


node scripts/cli.js init

查询指标

bash
cd ~/.openclaw/workspace/skills/prometheus

查询默认实例

node scripts/cli.js query up

查询指定实例

node scripts/cli.js query up -i staging

一次性查询所有实例

node scripts/cli.js query up --all

使用自定义配置文件

node scripts/cli.js query up -c /path/to/config.json

常用查询

磁盘空间使用率:
bash
node scripts/cli.js query 100 - (nodefilesystemavailbytes / nodefilesystemsizebytes * 100) --all

CPU 使用率:
bash
node scripts/cli.js query 100 - (avg by (instance) (irate(nodecpuseconds_total{mode=idle}[5m])) * 100) --all

内存使用率:
bash
node scripts/cli.js query (nodememoryMemTotalbytes - nodememoryMemAvailablebytes) / nodememoryMemTotal_bytes * 100 --all

负载平均值:
bash
node scripts/cli.js query node_load1 --all

列出已配置的实例

bash
node scripts/cli.js instances

输出:
json
{
default: production,
instances: [
{ name: production, url: https://prometheus.example.com, hasAuth: true },
{ name: staging, url: http://prometheus-staging:9090, hasAuth: false }
]
}

其他命令

bash

列出匹配模式的所有指标


node scripts/cli.js metrics nodememory*

获取标签名称

node scripts/cli.js labels --all

获取标签的值

node scripts/cli.js label-values instance --all

查找时间序列

node scripts/cli.js series {name=~nodecpu., instance=~.:9100} --all

获取活跃告警

node scripts/cli.js alerts --all

获取抓取目标

node scripts/cli.js targets --all

多实例输出格式

使用 --all 时,结果包含来自所有实例的数据:

json
{
resultType: vector,
results: [
{
instance: production,
status: success,
resultType: vector,
result: [...]
},
{
instance: staging,
status: success,
resultType: vector,
result: [...]
}
]
}

单个实例的错误不会导致整个查询失败——它们会在结果数组中以 status: error 的形式出现。

常用查询参考

指标PromQL 查询
磁盘空闲百分比nodefilesystemavailbytes / nodefilesystemsizebytes 100
磁盘已用百分比
100 - (nodefilesystemavailbytes / nodefilesystemsizebytes 100) | | CPU 空闲百分比 | avg by (instance) (irate(nodecpuseconds_total{mode=idle}[5m])) * 100 | | 内存已用百分比 | (nodememoryMemTotalbytes - nodememoryMemAvailablebytes) / nodememoryMemTotal_bytes * 100 | | 网络接收 | rate(nodenetworkreceivebytestotal[5m]) | | 网络发送 | rate(nodenetworktransmitbytestotal[5m]) | | 运行时间 | nodetimeseconds - nodeboottime_seconds | | 服务状态 | up |

注意事项

  • - 即时查询的时间范围默认为最近 1 小时
  • 使用范围查询 [5m] 进行速率计算
  • 所有查询返回 JSON,data.result 包含结果
  • 实例标签通常显示为 host:port 格式
  • 使用 --all 时,查询会并行执行以获得更快的结果
  • 配置存储在技能目录之外,以便在技能更新后仍然保留

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 prometheus-1776329175 技能

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

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

通过命令行安装

skillhub install prometheus-1776329175

下载

⬇ 下载 prometheus v1.1.0(免费)

文件大小: 10.43 KB | 发布时间: 2026-4-17 15:56

v1.1.0 最新 2026-4-17 15:56
Multi-instance support, config file support, .env fallback, interactive init command

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

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

p2p_official_large
返回顶部