32 个版本
0.11.0-beta.17 | 2023 年 12 月 18 日 |
---|---|
0.11.0-beta.15 | 2023 年 11 月 14 日 |
0.11.0-beta.12 | 2022 年 5 月 24 日 |
0.11.0-beta.10 | 2022 年 3 月 19 日 |
0.10.7 | 2019 年 7 月 23 日 |
#151 in 命令行工具
124 每月下载量
1.5MB
4K SLoC
包含 (WOFF 字体, 105KB) front-end/fonts/fa-solid-900.woff, (WOFF 字体, 79KB) front-end/fonts/fa-solid-900.woff2, (WOFF 字体, 51KB) front-end/fonts/RobotoMono-Bold.woff2, (WOFF 字体, 53KB) front-end/fonts/RobotoMono-Light.woff2, (WOFF 字体, 51KB) front-end/fonts/RobotoMono-Medium.woff2, (WOFF 字体, 51KB) front-end/fonts/RobotoMono-Regular.woff2
M Prober
该程序旨在收集 Linux 系统信息,包括主机名、内核版本、运行时间、实时时钟时间、平均负载、CPU、内存、网络接口、块设备和进程。它可以作为一个常规的 CLI 工具,也可以作为一个具有前端网页和有用 HTTP API 的网络应用程序。
帮助
EXAMPLES:
mprober hostname # Show the hostname
mprober kernel # Show the kernel version
mprober uptime # Show the uptime
mprober uptime -m # Show the uptime and refresh every second
mprober uptime -p # Show the uptime without colors
mprober uptime -l # Show the uptime with darker colors (fitting in with light themes)
mprober uptime -s # Show the uptime in seconds
mprober time # Show the RTC (UTC) date and time
mprober time -m # Show the RTC (UTC) date and time and refresh every second
mprober time -p # Show the RTC (UTC) date and time without colors
mprober time -l # Show the RTC (UTC) date and time with darker colors (fitting in with light themes)
mprober cpu # Show load average and current CPU stats on average
mprober cpu -m 1000 # Show load average and CPU stats on average and refresh every 1000 milliseconds
mprober cpu -p # Show load average and current CPU stats on average without colors
mprober cpu -l # Show load average and current CPU stats on average with darker colors (fitting in with light themes)
mprober cpu -s # Show load average and current stats of CPU cores separately
mprober cpu -i # Only show CPU information
mprober memory # Show current memory stats
mprober memory -m 1000 # Show memory stats and refresh every 1000 milliseconds
mprober memory -p # Show current memory stats without colors
mprober memory -l # Show current memory stats with darker colors (fitting in with light themes)
mprober memory -u kb # Show current memory stats in KB
mprober network # Show current network stats
mprober network -m 1000 # Show network stats and refresh every 1000 milliseconds
mprober network -p # Show current network stats without colors
mprober network -l # Show current network stats with darker colors (fitting in with light themes)
mprober network -u kb # Show current network stats in KB
mprober volume # Show current volume stats
mprober volume -m 1000 # Show current volume stats and refresh every 1000 milliseconds
mprober volume -p # Show current volume stats without colors
mprober volume -l # Show current volume stats without colors
mprober volume -u kb # Show current volume stats in KB
mprober volume -i # Only show volume information without I/O rates
mprober volume --mounts # Show current volume stats including mount points
mprober process # Show a snapshot of the current processes
mprober process -m 1000 # Show a snapshot of the current processes and refresh every 1000 milliseconds
mprober process -p # Show a snapshot of the current processes without colors
mprober process -l # Show a snapshot of the current processes with darker colors (fitting in with light themes)
mprober process -i # Show a snapshot of the current processes but not including CPU usage
mprober process -u kb # Show a snapshot of the current processes. Information about memory size is in KB
mprober process --truncate 10 # Show a snapshot of the current processes with a specific truncation length to truncate user, group, program's names
mprober process --top 10 # Show a snapshot of current top-10 (ordered by CPU and memory usage) processes
mprober process -t # Show a snapshot of the current processes with the start time of each process
mprober process --pid-filter 3456 # Show a snapshot of the current processes which are related to a specific PID
mprober process --user-filter user1 # Show a snapshot of the current processes which are related to a specific user
mprober process --group-filter gp1 # Show a snapshot of the current processes which are related to a specific group
mprober process --tty-filter tty # Show a snapshot of the current processes which are related to specific tty names matched by a regex
mprober process --program-filter ab # Show a snapshot of the current processes which are related to specific program names or commands matched by a regex
mprober web # Start a HTTP service on port 8000 to monitor this computer. The default time interval is 3 seconds
mprober web -m 2 # Start a HTTP service on port 8000 to monitor this computer. The time interval is set to 2 seconds
mprober web -p 7777 # Start a HTTP service on port 7777 to monitor this computer
mprober web --addr 127.0.0.1 # Start a HTTP service on 127.0.0.1:8000 to monitor this computer
mprober web -a auth_key # Start a HTTP service on port 8000 to monitor this computer. APIs need to be invoked with an auth key
mprober web --only-api # Start a HTTP service on port 8000 to serve only HTTP APIs
mprober benchmark # Run benchmarks
mprober benchmark --disable-cpu # Run benchmarks except for benchmarking CPU
mprober benchmark --enable-memory # Benchmark the memory
Usage: mprober <COMMAND>
Commands:
hostname Show the hostname
kernel Show the kernel version
uptime Show the uptime
time Show the RTC (UTC) date and time
cpu Show CPU stats
memory Show memory stats
network Show network stats
volume Show volume stats
process Show process stats
web Start a HTTP service to monitor this computer
benchmark Run benchmarks to measure the performance of this environment
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
要求
- Linux 内核版本:3.10+
使用方法
安装/卸载
从 crates.io,
cargo install mprober
# cargo uninstall mprober
从 GitHub (x86 和 x86_64),
(curl -s https://api.github.com/repos/magiclen/m-prober/releases/latest | sed -r -n 's/.*"browser_download_url": *"(.*\/mprober_'$(uname -m)')".*/\1/p' | wget -i -) && sudo mv mprober_$(uname -m) /usr/local/bin/mprober && sudo chmod +x /usr/local/bin/mprober
# sudo rm /usr/local/bin/mprober
CLI
获取主机名
mprober hostname
除了 hostname
,h
,host
,name
和 servername
之外,也可以接受。
获取内核版本
mprober kernel
除了 kernel
,k
,l
和 linux
之外,也可以接受。
获取系统运行时间
mprober uptime
除了 uptime
,u
,up
,utime
和 ut
之外,也可以接受。
获取 RTC 时间
mprober time
除了 time
,t
,systime
,stime
,st
,utc
,utctime
,rtc
,rtctime
和 date
之外,也可以接受。
显示 CPU 统计信息
mprober cpu
除了 cpu
,c
,cpus
,core
,cores
,load
,processor
和 processors
以外,还可以接受。
显示内存统计信息
mprober memory
除了 memory
,m
,mem
,f
,free
,memories
,swap
,ram
,dram
,ddr
,cache
,buffer
,buffers
,buf
和 buff
也可以接受。
显示网络统计信息
mprober network
除了 network
,n
,net
,networks
,bandwidth
和 traffic
也可以接受。
显示存储统计信息
mprober volume
除了 volume
,v
,storage
,volumes
,d
,disk
,disks
,blk
,block
,blocks
,mount
,mounts
,ssd
和 hdd
也可以接受。
颜色模式
环境变量 MPROBER_LIGHT
和 MPROBER_FORCE_PLAIN
可以用来控制输出颜色。
基准测试
为了基准测试CPU、内存和存储的性能,
mprober benchmark
除了 benchmark
,b
,bench
和 performance
也可以接受。
使用 --disable-xxx
或 --enable-xxx
标志可以控制要运行哪些基准测试。
Web (HTTP)
启动服务器
mprober web
除了 web
,w
,server
和 http
也可以接受。
一旦启动服务器,您可以通过Firefox或Chrome等网页浏览器打开 http://0.0.0.0:8000
。
要更改监听端口,请使用 -p <端口>
选项。要更改检测时间间隔,请使用 -m <SECONDS>
选项,其中 <SECONDS>
的范围从 1
到 15
。
HTTP API
GET /api/hostname
{
"code": 0,
"data": "magiclen-linux"
}
GET /api/kernel
{
"code": 0,
"data": "4.15.0-48-generic"
}
GET /api/uptime
{
"code": 0,
"data": 31694
}
数据单位是 秒。
GET /api/time
{
"code": 0,
"data": {
"date": "2019-05-03",
"time": "12:43:14"
}
}
这是RTC时间。
GET /api/cpu
{
"code": 0,
"data": {
"cpus": [
{
"cores": 4,
"mhz": [
2571.96,
2688.208,
2604.095,
2700.238,
2700.034,
2699.908,
2700.329,
2699.986
],
"model_name": "Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz",
"threads": 8
}
],
"load_average": {
"fifteen": 1.02,
"five": 0.83,
"one": 0.61
}
}
}
GET /api/cpu-detect
{
"code": 0,
"data": {
"cpus": [
{
"cores": 4,
"mhz": [
1808.254,
1787.732,
1430.044,
1845.768,
1751.993,
1751.121,
1769.048,
1663.091
],
"model_name": "Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz",
"threads": 8
}
],
"cpus_stat": [
0.08386009270965024,
0.09152542372881356,
0.10472972972972971,
0.11295681063122924,
0.06418918918918919,
0.09364548494983276,
0.06397306397306397,
0.053691275167785234,
0.0821917808219178
],
"load_average": {
"fifteen": 1.02,
"five": 0.84,
"one": 0.74
}
}
}
cpus_stat
字段中的第一个值是每个核心的平均使用率。其余值是每个逻辑CPU核心的使用率。
GET /api/memory
{
"code": 0,
"data": {
"memory": {
"available": 22659469312,
"buffers": 10412032,
"cache": 19094446080,
"free": 4154060800,
"shared": 119246848,
"total": 33633140736,
"used": 10374221824
},
"swap": {
"cache": 385024,
"free": 4082888704,
"total": 4094685184,
"used": 11411456
}
}
}
数字单位是 字节。
GET /api/network-detect
{
"code": 0,
"data": [
{
"download_rate": 0.0,
"download_total": 55713769,
"interface": "lo",
"upload_rate": 0.0,
"upload_total": 55713769
},
{
"download_rate": 702.0,
"download_total": 7461474545,
"interface": "enp0s20f0u4",
"upload_rate": 1280.6666666666667,
"upload_total": 331829069
}
]
}
总数单位是 字节。速率单位是 字节/秒。
GET /api/volume
{
"code": 0,
"data": [
{
"device": "sda2",
"mount_points": [
"/",
"/var/lib/docker/btrfs"
],
"read_total": 7612149760,
"size": 249809600512,
"used": 70506823680,
"write_total": 12919939072
},
{
"device": "sdb1",
"mount_points": [
"/storage"
],
"read_total": 7080878080,
"size": 239938535424,
"used": 218200993792,
"write_total": 21799934464
},
{
"device": "sdc2",
"mount_points": [
"/home"
],
"read_total": 27511930880,
"size": 496011051008,
"used": 370128474112,
"write_total": 56615944192
}
]
}
总数单位是 字节。
GET /api/volume-detect
{
"code": 0,
"data": [
{
"device": "sda2",
"mount_points": [
"/",
"/var/lib/docker/btrfs"
],
"read_rate": 0.0,
"read_total": 7612149760,
"size": 249809600512,
"used": 70506823680,
"write_rate": 0.0,
"write_total": 12928978944
},
{
"device": "sdb1",
"mount_points": [
"/storage"
],
"read_rate": 0.0,
"read_total": 7080878080,
"size": 239938535424,
"used": 218200993792,
"write_rate": 0.0,
"write_total": 21799934464
},
{
"device": "sdc2",
"mount_points": [
"/home"
],
"read_rate": 0.0,
"read_total": 27511934976,
"size": 496011051008,
"used": 370131861504,
"write_rate": 4965717.333333333,
"write_total": 56771334144
}
]
}
总数单位是 字节。速率单位是 字节/秒。
GET /api/all
{
"code": 0,
"data": {
"cpus": [
{
"cores": 4,
"mhz": [
1200.121,
1200.272,
1200.12,
1200.055,
1200.098,
1200.034,
1200.014,
1200.124
],
"model_name": "Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz",
"threads": 8
}
],
"cpus_stat": [
0.04951741502308015,
0.043333333333333335,
0.030405405405405407,
0.05743243243243243,
0.056666666666666664,
0.04983388704318937,
0.05387205387205387,
0.05405405405405406,
0.05067567567567568
],
"hostname": "magiclen-linux",
"kernel": "4.15.0-48-generic",
"load_average": {
"fifteen": 0.8,
"five": 0.53,
"one": 0.28
},
"memory": {
"available": 22578839552,
"buffers": 10412032,
"cache": 19104878592,
"free": 4062957568,
"shared": 119230464,
"total": 33633140736,
"used": 10454892544
},
"network": [
{
"download_rate": 0.0,
"download_total": 55798721,
"interface": "lo",
"upload_rate": 0.0,
"upload_total": 55798721
},
{
"download_rate": 9.333333333333334,
"download_total": 7463048290,
"interface": "enp0s20f0u4",
"upload_rate": 28.666666666666668,
"upload_total": 333465932
}
],
"rtc_time": {
"date": "2019-05-03",
"time": "12:54:34"
},
"swap": {
"cache": 385024,
"free": 4082888704,
"total": 4094685184,
"used": 11411456
},
"uptime": 32437,
"volumes": [
{
"device": "sda2",
"mount_points": [
"/",
"/var/lib/docker/btrfs"
],
"read_rate": 0.0,
"read_total": 7612149760,
"size": 249809600512,
"used": 70506831872,
"write_rate": 0.0,
"write_total": 12939075584
},
{
"device": "sdb1",
"mount_points": [
"/storage"
],
"read_rate": 0.0,
"read_total": 7080878080,
"size": 239938535424,
"used": 218200993792,
"write_rate": 0.0,
"write_total": 21799934464
},
{
"device": "sdc2",
"mount_points": [
"/home"
],
"read_rate": 0.0,
"read_total": 27521441792,
"size": 496011051008,
"used": 370118373376,
"write_rate": 744106.6666666666,
"write_total": 56883159040
}
]
}
}
授权
如果您需要将上述HTTP API暴露到互联网上,为了防止这些API被任何人调用,您可以在程序中启用一个简单的授权机制。
从CLI启动HTTP服务器时,您可以添加一个 -a <AUTH_KEY>
选项。然后,每个API都需要通过包含发送 AUTH_KEY
的 Authorization
标头的请求来调用。
此外,您可能想要禁用网页。只需添加一个 --only-api
标志。
待办事项
- 进程快照(HTTP,文档)
- 数据库检测
- 基准(网络)
许可证
依赖项
~24–60MB
~1M SLoC