返回顶部
o

openclaw-daily-opsOpenClaw日常运维

Daily cost reporting + session hygiene for OpenClaw deployments. Tracks per-session API spend, shows 7-day trend, and wipes zombie sessions >24h old to prevent context snowball. Zero personal info — configure with your own paths and Discord channel. Runs nightly via cron.

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

openclaw-daily-ops

OpenClaw 每日运维

一个夜间定时任务,完成两项工作:了解你的花费,清除无用会话。

  • - 解析所有 OpenClaw 会话 JSONL 文件 → 计算每个会话当天的 API 成本
  • 向 Discord 发布包含 7 天趋势的清晰成本报告
  • 清除超过 24 小时且上下文大于 1MB 的会话(僵尸会话清理器)
  • 将所有日志记录到 state/cost-log.json 和 state/session-reset-log.json

零 AI 信用点消耗——纯 Python + 一条 Discord 消息。



设置

1. 配置

将 config.example.json 复制为 config.json 并填写你的配置值:

bash
cp config.example.json config.json

编辑 config.json:

json
{
sessions_dir: ~/.openclaw/agents/main/sessions,
workspace_dir: ~/.openclaw/workspace,
discord_webhook: https://discord.com/api/webhooks/YOUR/WEBHOOK,
discorduserid: YOURDISCORDUSER_ID,
channel_names: {
channel:YOURCHANNELID: #your-channel-name
},
zombieminage_hours: 24,
zombieminsize_mb: 1,
alerthighcost: 50,
alertlowcost: 10,
timezoneoffsethours: -6
}

如何获取 Discord Webhook:

  1. 1. 进入你的 Discord 频道 → 编辑频道 → 集成 → Webhooks → 新建 Webhook
  2. 复制 Webhook URL

如何获取你的 Discord 用户 ID:

  1. 1. 在 Discord 中启用开发者模式(设置 → 高级 → 开发者模式)
  2. 右键点击你的用户名 → 复制用户 ID

频道名称(可选):将你的 OpenClaw 频道会话键映射为报告中可读的名称。在 ~/.openclaw/agents/main/sessions/sessions.json 中查找会话键。

2. 测试

bash
python3 scripts/cost_report.py --config config.json --dry-run

此命令会打印报告,但不会发布到 Discord 或写入日志。

3. 设置定时任务

添加一个夜间 OpenClaw 定时任务。在 OpenClaw 配置中或通过 CLI 设置:

Schedule: 0 21 *(每天晚 9 点——根据你的时区调整)
Model: haiku(成本报告很简单,不需要重型模型)
Payload: 读取 /path/to/openclaw-daily-ops/SKILL.md 并严格遵循。

或者作为系统定时任务运行:

bash

添加到 crontab -e


0 21 * python3 /path/to/openclaw-daily-ops/scripts/costreport.py --config /path/to/config.json >> /path/to/costreport.log 2>&1


报告样式

📊 每日成本报告 — 2026年3月9日

💰 总计:$4.21 · 830万 tokens

按会话分类:
🔴 #general — $2.45 · 410万 tok
🟡 #posting — $1.32 · 280万 tok
🟢 heartbeat — $0.44 · 140万 tok

7天趋势:$12 → $8 → $6 → $5 → $4 → $4 → $4

✅ 预算内
🔄 已重置 2 个过期会话(释放 3.2MB)

颜色编码:

  • - 🔴 会话成本 > $5
  • 🟡 会话成本 $1–$5
  • 🟢 会话成本 < $1



技能步骤(用于 OpenClaw 定时任务负载)

当作为 OpenClaw 定时任务代理运行时,代理应:

步骤 1 — 运行成本解析器

执行 scripts/cost_report.py --config /path/to/config.json 并捕获输出。

步骤 2 — 运行僵尸会话清理器

执行 scripts/zombie_killer.py --config /path/to/config.json 并捕获输出。

步骤 3 — 格式化并发布

将两个输出合并为上述报告格式,并发布到你的 Discord Webhook。

配置参考

类型描述
sessionsdir字符串OpenClaw 会话目录路径
workspacedir
字符串 | OpenClaw 工作区路径(用于状态日志) | | discord_webhook | 字符串 | 用于发布报告的 Discord Webhook URL | | discorduserid | 字符串 | 你的 Discord ID——在紧急警报中标记 | | channel_names | 对象 | 将会话键映射为显示名称(可选) | | zombieminage_hours | 数字 | 超过此时间的会话将被重置(默认:24) | | zombieminsize_mb | 数字 | 重置的最小文件大小(默认:1MB) | | alerthighcost | 数字 | 🚨 紧急标志的每日成本阈值(默认:$50) | | alertlowcost | 数字 | ✅ 预算内标志的每日成本阈值(默认:$10) | | timezoneoffsethours | 数字 | 你的 UTC 偏移量,用于日期过滤(默认:-6 对应 CST) |

文件结构

openclaw-daily-ops/
├── SKILL.md ← 本文件
├── config.example.json ← 配置模板(复制为 config.json)
├── scripts/
│ ├── cost_report.py ← 解析会话,计算成本,发布到 Discord
│ └── zombie_killer.py ← 清除过期会话,记录清理内容
└── state/ ← 自动创建
├── cost-log.json ← 滚动 90 天成本历史
└── session-reset-log.json ← 所有僵尸会话清理日志



常见问题

问:这会破坏我的活跃会话吗?
不会。僵尸会话清理器只重置超过 24 小时且大于 1MB 的会话。活跃会话永远不会被触及。

问:重置是什么意思?
它会将会话 JSONL 文件截断为空。OpenClaw 会在下次使用时重新创建。所有日志在清除前都会保存到 session-reset-log.json。

问:我可以调整阈值吗?
可以——在 config.json 中调整 zombieminagehours 和 zombieminsizemb。

问:这适用于 Andre/多机器设置吗?
适用。在每台机器上使用各自的 config.json 运行设置。两者都可以发布到同一个 Discord Webhook。

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 openclaw-daily-ops-1776356054 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 openclaw-daily-ops-1776356054 技能

通过命令行安装

skillhub install openclaw-daily-ops-1776356054

下载

⬇ 下载 openclaw-daily-ops v1.0.0(免费)

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

v1.0.0 最新 2026-4-17 15:37
openclaw-daily-ops 1.0.0 — Initial release

- Tracks daily OpenClaw per-session API costs and 7-day trends, posting nightly Discord reports
- Wipes ("resets") zombie sessions older than 24h and larger than 1MB to prevent excessive context growth
- Logs all actions to `state/cost-log.json` and `state/session-reset-log.json`
- Zero personal info required; highly configurable for paths, Discord integration, thresholds, and naming
- Designed for robust and friendly night-to-night operations via cron

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

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

p2p_official_large
返回顶部