A Python library for xmov systemmonitor
Project description
xmovsystemmonitor
一个用于监测系统CPU和内存使用率的工具,提供HTTP API接口,可以用于监控系统性能(内存、CPU)。
Features
安装
# 本地
pip install xmovsystemmonitor -i https://pypi.org/simple/
# 阿里云
pip install xmovsystemmonitor -i http://pypi.aliyun.com/simple/
用法
# 服务端,被监测端运行此命令
python -m xmovsystemmonitor
# 指定主机和端口, 并指定最大记录数量
python -m xmovsystemmonitor --host 0.0.0.0 --port 8000 --max-num 3000
测试代码,可以运行在本地,也可以运行在远程服务器上。
from xmovsystemmonitor.client.client import Client
import time
client = Client()
client.start() # 启动监控, 启动后会立即开始采集数据, 每次start会清空之前采集的数据
time.sleep(10) # 睡眠10秒
client.stop() # 停止监控, 停止后会立即停止采集数据, 并抓取统计信息
cpu_min = client.cpu.min
cpu_max = client.cpu.max
cpu_avg = client.cpu.avg
memory_min = client.memory.min
memory_max = client.memory.max
memory_avg = client.memory.avg
开发测试
import pytest
import requests
import json
from functools import partial
json_dump = partial(json.dumps, indent=4, ensure_ascii=False)
def test_get_system_info():
response = requests.get("http://localhost:8000/")
print(response.json())
assert response.status_code == 200
assert "cpu_percent" in response.json()
assert "memory_percent" in response.json()
def test_start_monitoring():
response = requests.get("http://localhost:8000/start-monitoring")
print(response.json())
assert response.status_code == 200
assert "message" in response.json()
assert response.json()["message"] == "监控已启动"
def test_stop_monitoring():
response = requests.get("http://localhost:8000/stop-monitoring")
print(response.json())
assert response.status_code == 200
assert "message" in response.json()
assert response.json()["message"] == "监控已停止"
def test_statistic():
response = requests.get("http://localhost:8000/statistic")
print(json_dump(response.json()))
assert response.status_code == 200
assert "cpu_percent" in response.json()
assert "memory_percent" in response.json()
assert "data_list" in response.json()
开发配置
# 克隆仓库
git clone git@github.com:atanx/xmovsystemmonitor.git
cd xmovsystemmonitor
# 安装开发依赖
pip install -e ".[dev]"
# 手动修改修改__init__.py中的__version__, 然后打包
make build
# 上传到xmov-pypi, 需要安装twine, 配置~/.pypirc
make upload
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xmovsystemmonitor-1.3.4.tar.gz.
File metadata
- Download URL: xmovsystemmonitor-1.3.4.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
357ba495e38beaf6c01a5af16124bca01b09272160e59e73ce48faf71622462d
|
|
| MD5 |
18f9d18a927513b265ec621867fa4371
|
|
| BLAKE2b-256 |
c8e9f5517400c318e1fb724b36764dca59823f89c7b795a02f4ff01774b2e667
|
File details
Details for the file xmovsystemmonitor-1.3.4-py3-none-any.whl.
File metadata
- Download URL: xmovsystemmonitor-1.3.4-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27d41e31cec1016320dd3fca7e93a0cc1b3703415df52f2148a297f72542a662
|
|
| MD5 |
fe18902877c13eb8e53a2630de56f32c
|
|
| BLAKE2b-256 |
910675acfee9f2c1275f49d14f717c0de71bd4a66fa7f40cc252f671befe913a
|