Skip to content

Repository files navigation

AI Usage Monitor

Monitor AI service usage (Claude, Copilot, Cursor) with real-time metrics and notifications.

License: MITGo Version

Features

  • Multi-Provider: Claude, Copilot, Cursor
  • Real-time Monitoring: Track quota usage automatically
  • REST API: Built-in API server on port 18000
  • Notifications: Apprise integration (Discord, Telegram, ServerChan, etc.)
  • Auto-Start: Managed by Homebrew Services

Installation

brew tap saaskit-dev/tap
brew install ai-usage

安装后自动启动服务。

Commands

# 查看状态
ai-usage status
# 服务管理
brew services start ai-usage
brew services stop ai-usage
brew services restart ai-usage
# API 调用
curl http://localhost:18000/usage

Configuration

配置文件: /opt/homebrew/etc/ai-usage.yaml

默认配置(无需配置文件即可运行):

  • 端口: 18000
  • 间隔: 5min
  • Provider: 只启用 Claude

完整配置示例:

server:
addr: ":18000"monitor:
interval: "300s"notify:
apprise_urls:
- "schan://your-sendkey"rules:
- event: depleted # 配额耗尽
- event: probe_error # 探测失败providers:
claude:
enabled: true# paths: # 额外的 Claude 凭证路径# - ~/.claude-work/copilot:
enabled: falsetoken: "ghp_xxx"cursor:
enabled: falsetoken: "xxx"

API Endpoints

EndpointDescription
GET /healthz健康检查
GET /usage所有 Provider 用量
GET /config当前配置
GET /notify通知状态
curl http://localhost:18000/healthz
curl http://localhost:18000/usage

响应示例:

{
"usage": [
{
"provider": "claude",
"email": "user@example.com",
"quotas": [
{
"type": "daily",
"percent_remaining": 75,
"used": 25,
"limit": 100,
"reset_text": "Resets in 6h"
}
]
}
],
"last_updated": "2024-01-15T10:00:00Z",
"ready": true
}

Notifications

支持的通知渠道(通过 Apprise):

notify:
apprise_urls:
# ServerChan (微信)
- "schan://SCTxxxxx"# Discord
- "discord://webhook_id/webhook_token"# Telegram
- "tgram://bot_token/chat_id"# 自定义 Webhook
- "jsons://webhook.example.com/notify"

通知规则:

rules:
- event: depleted # 配额耗尽
- event: probe_error # 探测失败
- event: threshold # 低于阈值threshold: 50
- event: reset_soon # 即将重置before: "10m"

通知示例:

⚠️ Claude 低用量告警 (20%)
✅ daily: 20% (40/50) · Resets in 2h
> 配额不足,请注意使用
_03-10 14:30_

Paths

文件路径
配置/opt/homebrew/etc/ai-usage.yaml
日志/opt/homebrew/var/log/ai-usage.log
数据/opt/homebrew/var/ai-usage/usage.json

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages