Skip to main content

远程主机资源监控工具:SSH 采集 CPU / 内存 / 网络 / 磁盘 / 温度 + 持续 ping,支持 Web 实时面板与日志回放

Project description

远程主机监控工具

持续 ping 目标 IP 并通过 SSH 采集目标机器的系统资源(CPU / 内存 / Swap / 网络带宽 / 磁盘 IO / loadavg),实时写入 CSV 日志。

功能

  • Ping:默认每 0.5s 一次,延迟精度 0.001 ms(小数点后 3 位 ms),记录每次结果与超时。
  • SSH 资源采集:默认每 2s 一次,通过 /proc 计算 1 秒区间内的 CPU 占用率、网络/磁盘速率,输出:
    • cpu_percent(整机 CPU 使用率)
    • mem_total_kb / mem_used_kb / mem_avail_kb / mem_percent
    • swap_total_kb / swap_used_kb / swap_percent
    • net_rx_Bps / net_tx_Bps(所有非 lo 网卡求和,单位 B/s)
    • disk_read_Bps / disk_write_Bps
    • loadavg(1/5/15 分钟负载)
    • per_interface(每块网卡的 rx/tx 速率)
  • 实时写盘:每条记录立即 flush 到 CSV。
  • 断线自动重连:SSH 断开后指数退避重连。
  • Ctrl+C 优雅退出,打印统计。

安装

pip install -r requirements.txt

目标机器要求:Linux,可用 python3(若无则自动降级到 shell 版本,但数据项会较少)。

使用

# 用 SSH 密钥
python3 monitor.py 192.168.1.100 -u root -k ~/.ssh/id_rsa

# 用密码(交互输入)
python3 monitor.py 192.168.1.100 -u root --ask-pass

# 自定义频率与输出目录
python3 monitor.py 10.0.0.5 -u ubuntu --ping-interval 1.0 --res-interval 1 -o ./logs

输出

-o 指定目录(默认 ./logs)下生成:

  • ping_<host>_<时间戳>.csvtimestamp, host, latency_ms, status
  • resource_<host>_<时间戳>.csv:见上方字段列表

运行期间每 5 秒在控制台打印一次 ping 丢包 / min/avg/max 汇总。

参数

参数 说明 默认
host 目标 IP / 主机名 必填
-u/--user SSH 用户名 当前用户
-P/--port SSH 端口 22
-k/--key SSH 私钥路径 无(优先尝试 ssh-agent / 默认密钥)
-p/--password SSH 密码
--ask-pass 交互输入密码
--ping-interval Ping 间隔(秒) 1.0
--res-interval 资源采样间隔(秒) 2.0
-o/--output 日志目录 ./logs

注意

  • 本机需具备 ping 命令;Linux 下 -W 超时为整数秒。
  • 若目标机器 ping 禁用 ICMP,ping 会全部超时,但 SSH 资源采集仍正常工作。
  • CPU/网络/磁盘速率由脚本内睡眠 1 秒两次采样差分计算,因此实际采集周期 ≈ res-interval 但不小于 1 秒。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fourier_resm-1.0.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fourier_resm-1.0.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file fourier_resm-1.0.0.tar.gz.

File metadata

  • Download URL: fourier_resm-1.0.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for fourier_resm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ed2a9c78043b10cc9aae1715a915867754bcb6a0c9aad517ffb60cee2128299d
MD5 5903e26490607e6e520eaba5045e9ce5
BLAKE2b-256 35887eb7d6a0cb4d96dba3f59ca1c080ba7381e8e2fd9bec14eb4e29d2055898

See more details on using hashes here.

File details

Details for the file fourier_resm-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fourier_resm-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for fourier_resm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9edddf73eb2429df6e332776159fe85facd42c0a61dbe77e040d7947e1224519
MD5 4ccbc4e60eb9ae228dab5d626dbff2df
BLAKE2b-256 744887d5d49d666ff8e7894673388b1d3699fa827f7036b1bb0df7b23460bf48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page