|
#!/bin/bash |
|
|
|
|
|
uptime_string=$(uptime -p) |
|
uptime_string=${uptime_string//up /} |
|
|
|
|
|
boot_time=$(uptime -s) |
|
|
|
|
|
cpu_usage=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') |
|
|
|
|
|
ram_total=$(free -g | awk 'NR==2{printf "%.0fGB", $2}') |
|
ram_used=$(free -m | awk 'NR==2{printf "%.2fMB", $3/1024}') |
|
ram_free=$(free -m | awk 'NR==2{printf "%.2fMB", $4/1024}') |
|
|
|
|
|
rx_bytes=$(cd .. && cat /sys/class/net/eth0/statistics/rx_bytes) |
|
tx_bytes=$(cd .. && cat /sys/class/net/eth0/statistics/tx_bytes) |
|
rx_mb=$(echo "scale=2; $rx_bytes/1024/1024" | bc) |
|
tx_mb=$(echo "scale=2; $tx_bytes/1024/1024" | bc) |
|
|
|
|
|
read_bytes=$(cd .. && cat /sys/block/sda/stat | awk '{print $3}') |
|
write_bytes=$(cd .. && cat /sys/block/sda/stat | awk '{print $7}') |
|
read_mb=$(echo "scale=2; $read_bytes/1024/1024" | bc) |
|
write_mb=$(echo "scale=2; $write_bytes/1024/1024" | bc) |
|
|
|
|
|
echo "This VPS has been running for $uptime_string from $boot_time +0800π" |
|
echo "CPU: $cpu_usage" |
|
echo "RAM: $ram_used/$ram_total" |
|
echo "Network RX/TX: ${rx_mb}MB/${tx_mb}MB" |
|
echo "IO R/W: ${read_mb}MB/${write_mb}MB" |