Skip to main content

AMonitor Python SDK

目标

Python SDK 运行在被监控进程一侧,提供:

  • 启动 WS 服务端,接收 Agent 下发的 action
  • 周期发送 heartbeat
  • 向 Agent 发送 event
  • 返回 action_ack

安装与运行(uv)

uv sync
uv run python -m amonitor_sdk.example

最小示例

from amonitor_sdk.server import start_server

async def on_action(action: str, params: dict):
    if action == "restart":
        return {"ok": True, "message": "restarted"}
    return {"ok": False, "message": "unknown action"}

start_server(host="0.0.0.0", port=8765, target_id="server-a", action_handler=on_action)

交互说明

  1. Agent 连接 SDK WS 地址。
  2. SDK 启动后按间隔发送 heartbeat。
  3. SDK 收到 action 后执行 action_handler。
  4. SDK 将执行结果封装为 action_ack 返回。

开发规范(Python)

代码风格

  • Python 版本:>=3.11
  • 强制类型注解,公开 API 需要完整函数签名。
  • 不使用单字母变量名(循环计数器除外)。
  • 异步代码优先使用 async/await,避免阻塞调用。

项目结构

  • src/amonitor_sdk/server.py:服务端与消息处理主逻辑
  • src/amonitor_sdk/models.py:协议模型
  • src/amonitor_sdk/example.py:最小可运行示例

依赖与命令

  • 新增依赖后执行 uv sync
  • 运行检查:uv run --with dev ruff check src
  • 本地 smoke:uv run python -c "import amonitor_sdk"

测试与验收

  • 单模块测试:cd .. && make test
  • 幂等验收:cd .. && RUN_E2E=1 make test

协议约束

  • 必须携带 msg_id、type、timestamp
  • payload 保持业务透传,SDK 不做业务字段裁剪
  • action_ack.payload.action_msg_id 必须等于原 action 的 msg_id

Release files for amonitor-sdk 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amonitor-sdk 1.1.1
File Size Uploaded
amonitor_sdk-1.1.1.tar.gz 45.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amonitor-sdk 1.1.1
File Interpreter ABI Platform
amonitor_sdk-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.3 kB

Release files / amonitor_sdk-1.1.1.tar.gz

Download URL amonitor_sdk-1.1.1.tar.gz
Size 45.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f7aa6f4a6426f90a0c76760ebf426c8483b6df158736e042a28c2ed7485bb35
BLAKE2b-256 checksum
How to use checksums
db0196df4e3e706fc065de14fd4fffcf7898f5cb7b4f37abc9a996ecceb7793a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.5

Release files / amonitor_sdk-1.1.1-py3-none-any.whl

Download URL amonitor_sdk-1.1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8556abb86bc725a4b3ccca8da99ec522c1759e1cc90a389e504ba107e9323ca
BLAKE2b-256 checksum
How to use checksums
4a8ab312ca52baa0e20d7341ea13901ead027d3c6c96d1e57be7381a9a907da0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.5

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page