Skip to main content

LogWatch 客户端 - 包裹命令并上传日志到监控服务器

Project description

╔══════════════════════════════════════════════════════════════════════════╗
║                                                                          ║
║   ██╗      ██████╗  ██████╗ ██╗    ██╗ █████╗ ████████╗ ██████╗██╗  ██╗ ║
║   ██║     ██╔═══██╗██╔════╝ ██║    ██║██╔══██╗╚══██╔══╝██╔════╝██║  ██║ ║
║   ██║     ██║   ██║██║  ███╗██║ █╗ ██║███████║   ██║   ██║     ███████║ ║
║   ██║     ██║   ██║██║   ██║██║███╗██║██╔══██║   ██║   ██║     ██╔══██║ ║
║   ███████╗╚██████╔╝╚██████╔╝╚███╔███╔╝██║  ██║   ██║   ╚██████╗██║  ██║ ║
║   ╚══════╝ ╚═════╝  ╚═════╝  ╚══╝╚══╝ ╚═╝  ╚═╝   ╚═╝    ╚═════╝╚═╝  ╚═╝ ║
║                                                                          ║
╚══════════════════════════════════════════════════════════════════════════╝

⚡ 实时日志监控客户端 ⚡

PyPI Python License

┌─────────────────────────────────────────────────────────────┐
│  包裹任意命令 → 实时上传日志 → LogWatch 服务端              │
└─────────────────────────────────────────────────────────────┘

🚀 快速开始

📦 安装

# 推荐使用 uv(更快)
uv tool install logwatch-client

# 或使用 pip
pip install logwatch-client

⚙️ 初始化

# 交互式配置向导
lw --setup

# 健康检查
lw --health

🎯 运行任务

lw --user-id 104698 --user-token ut_xxx python long_running_test.py

lw 会为每次执行自动生成新的 UUID task_id。这个 ID 只代表这一次运行;服务端删除后不会复用,也不会被后续推送重新激活。

如果任务在服务端被删除,客户端会把后续日志转为本地归档,不再尝试重新激活该任务;若只是网络中断,则会进入低频离线探测并在恢复后继续上传。




🤖 AI 辅助安装与配置

让 AI 助手自动完成安装和配置流程

📋 准备工作

在开始之前,请准备以下信息:

  • 🌐 服务端地址 — 例如 http://127.0.0.1:8000
  • 🆔 用户 ID — 在网页中查看
  • 🔑 用户 Token — 在网页设置中创建
✨ 一键安装(推荐)

复制以下内容发给 AI 助手(Codex / Claude Code):

请帮我安装和配置 logwatch-client:
参考 AI 协作手册 (https://raw.githubusercontent.com/Becomingw/logwatch_client/refs/heads/main/docs/ai-assistant-playbook.md) 来完成
🛠️ 手动安装
# 安装客户端
uv tool install logwatch-client || pip install logwatch-client

# 运行配置向导
lw --setup

# 验证安装
lw --health



📝 配置文件

配置文件路径: ~/.lwconfig

最小可用配置

server=http://127.0.0.1:8000
machine=my-macbook
user_id=104698
user_token=ut_xxx

💡 鉴权说明: 客户端上报接口统一使用 user_id + user_token




💻 常用命令

# 配置向导
lw --setup

# 健康检查
lw --health

# 运行任务(带名称)
lw --name "train-exp-1" python train.py

# 指定服务器
lw --server http://127.0.0.1:8000 python train.py

# 跳过连通性检查
lw --no-check python train.py



📖 命令行参数

参数 简写 说明
--name -n 任务名称
--server -s 服务器地址
--machine -m 机器标识
--user-id -u 用户 ID
--user-token 用户 Token
--setup 交互式配置向导(含连通+上报测试)
--health 健康检查(连通性/队列/离线邮件)
--no-check 跳过启动前连通性检查
--init 已废弃,等价于 --setup



⚙️ 完整配置项

展开查看所有配置选项
# ═══════════════════════════════════════════════════════════
# 基础配置
# ═══════════════════════════════════════════════════════════
server=http://127.0.0.1:8000
machine=my-macbook
user_id=104698
user_token=ut_xxx

# ═══════════════════════════════════════════════════════════
# 上传配置
# ═══════════════════════════════════════════════════════════
upload_interval_seconds=2
batch_size=100
batch_interval_ms=5000
compression_level=6
publish_grace_seconds=1
upload_circuit_break_max=5

# ═══════════════════════════════════════════════════════════
# 日志管理
# ═══════════════════════════════════════════════════════════
log_retention_days=7
log_max_files=1000
force_offline=false

# ═══════════════════════════════════════════════════════════
# 邮件通知
# ═══════════════════════════════════════════════════════════
email_enabled=false
email_notify_on=all
email_notify_on_start=false
smtp_host=smtp.example.com
smtp_port=465
smtp_user=your-email@example.com
smtp_pass=your-password
smtp_use_tls=true
email_from=your-email@example.com
email_to=notify@example.com



🔧 运行机制

📁 本地存储

  • 日志目录 ~/.lw_logs
  • 队列数据库 ~/.lw_logs/queue.db (SQLite WAL)

📤 上传策略

  • 批量上传 每 100 条或 5 秒触发
  • 心跳上报 默认每 30 秒
  • 失败重试 指数退避

🔍 健康检查

  • 连通性探测 GET /api/health
  • 离线模式 达到阈值后自动进入低频探测



🔁 协议语义

  • task_id 表示一次运行实例,客户端不会复用,服务端也不会接受复用
  • 服务端删除任务后会保留 tombstone,旧客户端后续 eventlogheartbeatlast-ack 推送会收到 409 task_deleted
  • 客户端收到 task_deleted 后停止该任务后续上报,并将本地队列标记为 archived
  • 客户端收到 task_not_running 时不会立即放弃任务,而是按可重试异常处理
  • 网络故障与任务删除是两类不同状态:前者允许恢复,后者不允许复活原任务


┌─────────────────────────────────────────────────────────────┐
│                                                             │
│  Made with ⚡ by LogWatch Team                              │
│  📚 Documentation • 🐛 Issues • 💬 Discussions              │
│                                                             │
└─────────────────────────────────────────────────────────────┘

© 2024 LogWatch • MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logwatch_client-0.1.4.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logwatch_client-0.1.4-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file logwatch_client-0.1.4.tar.gz.

File metadata

  • Download URL: logwatch_client-0.1.4.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for logwatch_client-0.1.4.tar.gz
Algorithm Hash digest
SHA256 981fbe8b300a17d87d3ebe03b798eb6dd2c5b0cf2de6046acab1d0553eb55f85
MD5 dd99b6bd15bdb8e1c1ae8a81a1705556
BLAKE2b-256 2c1fd133af202ce4a6d45a94c7ca68f9d033c5d51751211cf6a966b37bdf2f37

See more details on using hashes here.

File details

Details for the file logwatch_client-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: logwatch_client-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for logwatch_client-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 242bcf713eb9bf323293e4c13a95881416dce560da1d5322a04a3b399d38bdda
MD5 d1c9ccb5f49a10676751617228d3f9f4
BLAKE2b-256 efc95d58a530edf06077cebad06d4291141cbd84851651050d8df331d247277c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page