Skip to main content

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

Project description

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

实时日志监控 · 零依赖 · 开箱即用

PyPI Python License Linux macOS


包裹任意命令,实时上传日志到监控服务器

快速开始 · 配置说明 · 邮件通知



快速开始

使用 uv(推荐)

uv tool install logwatch-client

使用 pip

pip install logwatch-client
从源码安装
cd logwatch_client
uv pip install -e .

使用方式

# 基础用法 - 包裹命令执行,自动上传日志
lw python train.py

# 指定任务名称
lw --name "resnet-v2-training" python train.py

# 指定服务器地址
lw --server http://your-server.com:8000 python train.py

# 强制离线模式(仅本地记录 + 邮件通知)
lw --offline python train.py

系统要求

环境 要求
Python 3.8+
操作系统 Linux / macOS(使用 PTY 捕获输出)

配置

首次使用前,运行以下命令生成配置模板:

lw --init

配置文件位于 ~/.lwconfig

# ┌─────────────────────────────────────────┐
# │       LogWatch 客户端配置文件            │
# └─────────────────────────────────────────┘

# 服务器地址(必填)
server=http://your-server.com:8000

# 机器标识(可选,默认使用 hostname)
machine=my-gpu-server

# 用户 ID(用于鉴权/多用户隔离)
user_id=alice
完整配置项
# 日志上传间隔(秒,默认 2 秒)
upload_interval_seconds=2

# 发布前等待窗口(秒,默认 1 秒)
# 瞬间退出的程序不会产生无效日志
publish_grace_seconds=1

# 本地日志保留天数(默认 7 天)
log_retention_days=7

# 本地日志最大文件数(默认 1000)
log_max_files=1000

# 日志超过该大小才 gzip 压缩(KB,默认 64)
upload_gzip_min_kb=64

# 上传失败重试次数(默认 3)
upload_retry_times=3

# 上传失败重试间隔(秒,默认 2)
upload_retry_interval_seconds=2

# 熔断时长(分钟,默认 5)
upload_circuit_break_minutes=5

# 熔断次数阈值(默认 3)
upload_circuit_break_max=3

# 强制始终使用离线模式
force_offline=false

邮件通知

在离线模式下,任务完成后可通过邮件发送通知。支持 HTML 格式的精美邮件模板。

邮件配置

~/.lwconfig 中添加:

# ── 邮件通知配置 ─────────────────────────

# 是否启用邮件通知
email_enabled=true

# 通知类型:all=全部, failed=仅失败, success=仅成功
email_notify_on=all

# 任务开始时是否发送通知
email_notify_on_start=false

# SMTP 服务器配置
smtp_host=smtp.example.com
smtp_port=465
smtp_user=your-email@example.com
smtp_pass=your-password-or-auth-code
smtp_use_tls=true

# 发件人和收件人
email_from=your-email@example.com
email_to=notify@example.com
常见邮箱 SMTP 配置
邮箱服务 SMTP 地址 端口 说明
QQ 邮箱 smtp.qq.com 465 需要开启 SMTP 服务并获取授权码
163 邮箱 smtp.163.com 465 需要开启 SMTP 服务并设置授权码
Gmail smtp.gmail.com 587 需要开启两步验证并使用应用密码
Outlook smtp.office365.com 587 使用账户密码

命令行参数

参数 简写 说明 默认值
--name -n 任务名称 自动生成
--server -s 服务器地址 读取 ~/.lwconfig
--machine -m 机器标识 系统 hostname
--user-id -u 用户 ID 读取 ~/.lwconfig
--init - 生成配置文件模板 -
--no-check - 跳过服务器连通性检查 -
--offline - 强制离线模式 -

特性

零依赖
仅使用 Python 标准库
实时上传
每 2 秒增量上传日志
离线模式
支持本地记录 + 邮件通知
熔断保护
网络波动自动重试


Made with ☕ by LogWatch Team

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.2.tar.gz (15.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.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logwatch_client-0.1.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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.2.tar.gz
Algorithm Hash digest
SHA256 d1fbe7bd1b38e4ea9b1ca9743cb20819407f14df9ace7ad460e5cfd68fd35810
MD5 a30ff1870902746fc8e35b0557e5151c
BLAKE2b-256 d68b19199219feb26f35216aef02f5eb1961d73fd992d64a51f0fdf178179fd6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logwatch_client-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9a6c50711c04a25d0ca9d3b807882bef529d04a2ecff9b734650512e084485e0
MD5 47113a9633906758edb13cc9ef50a990
BLAKE2b-256 65d0d5d301550b254c746252e4837b3937d80889f0890eb4fe1fad582d6371e5

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