Prometheus Skill
Query Prometheus monitoring data from one or multiple instances. Supports federation across multiple Prometheus servers with a single command.
Quick Start
1. Initial Setup
Run the interactive configuration wizard:
CODEBLOCK0
This will create a prometheus.json config file in your OpenClaw workspace (~/.openclaw/workspace/prometheus.json).
2. Start Querying
CODEBLOCK1
Configuration
Config File Location
By default, the skill looks for config in your OpenClaw workspace:
CODEBLOCK2
Priority order:
- 1. Path from
PROMETHEUS_CONFIG environment variable - INLINECODE3
- INLINECODE4
- INLINECODE5 (current directory)
- INLINECODE6
Config Format
Create prometheus.json in your workspace (or use node cli.js init):
CODEBLOCK3
Fields:
- -
name — unique identifier for the instance - INLINECODE10 — Prometheus server URL
- INLINECODE11 /
password — optional HTTP Basic Auth credentials - INLINECODE13 — which instance to use when none specified
Environment Variables (Legacy)
For single-instance setups, you can use environment variables:
CODEBLOCK4
Usage
Global Flags
| Flag | Description |
|---|
| INLINECODE14 | Path to config file |
| INLINECODE15 |
Target specific instance |
|
-a, --all | Query all configured instances |
Commands
Setup
CODEBLOCK5
Query Metrics
CODEBLOCK6
Common Queries
Disk space usage:
CODEBLOCK7
CPU usage:
CODEBLOCK8
Memory usage:
CODEBLOCK9
Load average:
CODEBLOCK10
List Configured Instances
CODEBLOCK11
Output:
CODEBLOCK12
Other Commands
CODEBLOCK13
Multi-Instance Output Format
When using --all, results include data from all instances:
CODEBLOCK14
Errors on individual instances don't fail the entire query — they appear with "status": "error" in the results array.
Common Queries Reference
| Metric | PromQL Query |
|---|
| Disk free % | INLINECODE19 |
| Disk used % |
100 - (node_filesystem_avail_bytes / node_filesystem_size_bytes * 100) |
| CPU idle % |
avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100 |
| Memory used % |
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100 |
| Network RX |
rate(node_network_receive_bytes_total[5m]) |
| Network TX |
rate(node_network_transmit_bytes_total[5m]) |
| Uptime |
node_time_seconds - node_boot_time_seconds |
| Service up |
up |
Notes
- - Time range defaults to last 1 hour for instant queries
- Use range queries
[5m] for rate calculations - All queries return JSON with
data.result containing the results - Instance labels typically show
host:port format - When using
--all, queries run in parallel for faster results - Config is stored outside the skill directory so it persists across skill updates
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. PROMETHEUS_CONFIG 环境变量指定的路径
- ~/.openclaw/workspace/prometheus.json
- ~/.openclaw/workspace/config/prometheus.json
- ./prometheus.json(当前目录)
- ~/.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 node
memory*
获取标签名称
node scripts/cli.js labels --all
获取标签的值
node scripts/cli.js label-values instance --all
查找时间序列
node scripts/cli.js series {
name=~node
cpu.
, 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 - (node
filesystemavail
bytes / nodefilesystem
sizebytes 100) |
| CPU 空闲百分比 | avg by (instance) (irate(node
cpuseconds_total{mode=idle}[5m])) * 100 |
| 内存已用百分比 | (node
memoryMemTotal
bytes - nodememory
MemAvailablebytes) / node
memoryMemTotal_bytes * 100 |
| 网络接收 | rate(node
networkreceive
bytestotal[5m]) |
| 网络发送 | rate(node
networktransmit
bytestotal[5m]) |
| 运行时间 | node
timeseconds - node
boottime_seconds |
| 服务状态 | up |
注意事项
- - 即时查询的时间范围默认为最近 1 小时
- 使用范围查询 [5m] 进行速率计算
- 所有查询返回 JSON,data.result 包含结果
- 实例标签通常显示为 host:port 格式
- 使用 --all 时,查询会并行执行以获得更快的结果
- 配置存储在技能目录之外,以便在技能更新后仍然保留