# atomcode-flask-server-probe **Repository Path**: LiaCin/atomcode-flask-server-probe ## Basic Information - **Project Name**: atomcode-flask-server-probe - **Description**: AtomCode headless SRE server asset probe (Flask+pytest+systemd, no psutil) - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-19 - **Last Updated**: 2026-07-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # server-probe 轻量级服务器资产巡检 HTTP 服务,基于 Python 3.10+ / Flask 实现。 ## 项目结构 ``` /root/atomcode_demo/ app.py # Flask 应用 requirements.txt # 依赖列表 test_api.py # pytest 测试 server-probe.service # systemd unit 文件 README.md # 本文件 ``` ## API 接口 | 方法 | 路径 | 说明 | |------|------|------| | GET | /healthz | 健康检查,返回 `{"status":"ok"}` | | GET | /api/metrics | 系统指标(CPU、内存、磁盘、负载) | | GET | /api/info | 系统信息与 atomcode 版本 | ## 快速启动 ```bash # 1. 创建虚拟环境并安装依赖 python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt # 2. 启动服务(开发模式) flask --app app run --host 127.0.0.1 --port 8088 # 3. 使用 systemd 托管 cp server-probe.service /etc/systemd/system/ systemctl daemon-reload systemctl enable --now server-probe ``` ## 运行测试 ```bash source .venv/bin/activate pytest test_api.py -v ``` ## 验证记录 pytest 验证(2026-07-19,Python 3.10.12 / pytest-9.1.1): - test_api.py::TestHealthz::test_healthz_returns_ok PASSED - test_api.py::TestMetrics::test_metrics_returns_required_fields PASSED - test_api.py::TestInfo::test_info_returns_required_fields PASSED - 结论:3 passed in 1.12s 接口联调(flask 开发模式,端口 8088): - GET /healthz -> {"status":"ok"} (HTTP 200) - GET /api/metrics -> {"hostname":"lavm-cw9k5dvspp","cpu_count":2,"mem_percent":15.7,"disk_root_percent":51.8,"load_avg":[0.13,0.09,0.08]} (HTTP 200) - GET /api/info -> {"os_name":"Linux","kernel":"5.15.0-60-generic","python_version":"3.10.12","atomcode_version":"atomcode 5.0.0 (unknown)" (HTTP 200)