Skip to main content

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

# gpu 显存占用量(MB), 多块卡时计算总和。
gpu_min = client.gpu.min
gpu_max = client.gpu.max
gpu_avg = client.gpu.avg

开发测试

export MONITOR_SERVER=http://192.168.88.50:8001
HOME_URL=$MONITOR_SERVER$
VERSION_URL="$MONITOR_SERVER/version"
START_URL="$MONITOR_SERVER/start-monitoring"
STAT_URL="$MONITOR_SERVER/statistic"
STOP_URL="$MONITOR_SERVER/stop-monitoring"

# 打开回显
set -x

cur $VERSION_URL
sleep 1s
curl $HOME_URL
sleep 1s

curl $START_URL
sleep 2s
curl $STAT_URL
sleep 1s
curl $STOP_URL




```python
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

Metadata

Release files for xmovsystemmonitor 1.4.8

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

Source distribution (sdist)

Source distribution for xmovsystemmonitor 1.4.8
File Size Uploaded Provenance Actions
xmovsystemmonitor-1.4.8.tar.gz 10.8 kB Without provenance Details for xmovsystemmonitor-1.4.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xmovsystemmonitor 1.4.8
File Interpreter ABI Platform Actions
xmovsystemmonitor-1.4.8-py3-none-any.whl Python 3 none any Details for xmovsystemmonitor-1.4.8-py3-none-any.whl

Total release size: 22.2 kB

Release files / xmovsystemmonitor-1.4.8.tar.gz

Download URL xmovsystemmonitor-1.4.8.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb2e79824b65b302bb560586cd769b1f4c6ce8d8b009313ba0ed77e9d1f2ae4a
BLAKE2b-256 checksum
How to use checksums
5d027d29c97e2c228f31ad9c31727357ab1910b46c52410da49d5119668132cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Release files / xmovsystemmonitor-1.4.8-py3-none-any.whl

Download URL xmovsystemmonitor-1.4.8-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c619da982e423c665fdfdfb5340b35cefb3ee7a2028342b9055dc297356150b8
BLAKE2b-256 checksum
How to use checksums
ddb683a50e0db5eadef8f4c37449c9a361dd8ce1363e672e748cefe843e7c42f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.19

Security for xmovsystemmonitor 1.4.8

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.

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