Skip to content

Instantly share code, notes, and snippets.

@MikAghumyan
Created February 6, 2025 11:37
Show Gist options
  • Save MikAghumyan/883d5274314bc71a985d7c04e776a558 to your computer and use it in GitHub Desktop.
Save MikAghumyan/883d5274314bc71a985d7c04e776a558 to your computer and use it in GitHub Desktop.
"monitoring.sh" 45L, 1360B 33,4 All
#!/bin/bash
arch=$(uname -a)
cpu_sockets=$(lscpu | grep Socket | awk '{print $2}')
vcpu=$(nproc)
total_mem=$(free -m | grep Mem | awk '{print $2}')
used_mem=$(free -m | grep Mem | awk '{print $3}')
percent_mem=$(free -m | grep Mem | awk '{print $3/$2 * 100}')
total_storage=$(df -h --block-size=G --total | awk '/total/ {print $2}')
used_storage=$(df -h --block-size=G --total | awk '/total/ {print $3}')
percent_storage=$(df --block-size=G --total | awk '/total/ {print $5}')
cpu1=$(mpstat | tail -n 1 | awk '{print $4}')
cpu2=$(mpstat | tail -n 1 | awk '{print $6}')
percent_cpu=$(echo "$cpu1 + $cpu2" | bc)
boot_date=$(who -b | awk '{print $3 " " $4}')
lvm_active=$(lsblk | grep -q "lvm" && echo "yes" || echo "no")
active_connections=$(ss -tun | grep -v "State" | wc -l)
users=$(w | grep "pts" | wc -l)
IPv4=$(hostname -I | awk '{print $1}')
MAC=$(ip link show | awk '/ether/ {print $2}' | head -n 1)
sudo_count=$(echo "obase=10; ibase=36; $(cat /var/log/sudo/seq)" | bc)
wall "#Architecture: $arch
#CPU physical: $cpu_sockets
#vCPU: $vcpu
#Memory Usage: $used_mem/${total_mem}MB (${percent_mem}%%)
#Disk Usage: $used_storage/${total_storage}GB $percent_storage%
#CPU load: $cmd3%%
#Last boot: $boot_date
#LVM use: $lvm_active
#Connections TCP: $active_connections ESTABLISHED
#User log: $users
#Network: IP $IPv4 ($MAC)
#Sudo: $sudo_count
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment