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)
交互说明
- Agent 连接 SDK WS 地址。
- SDK 启动后按间隔发送
heartbeat。 - SDK 收到
action后执行action_handler。 - 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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| amonitor_sdk-1.1.1.tar.gz | 45.0 kB | Without provenance | Details for amonitor_sdk-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| amonitor_sdk-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for amonitor_sdk-1.1.1-py3-none-any.whl |
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
|
Security for amonitor-sdk 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.