-
Notifications
You must be signed in to change notification settings - Fork 9
/
monitoring.sh
57 lines (44 loc) · 2.36 KB
/
monitoring.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!bin/bash
## Command substitutions
ARCH=$(uname -a) # alternatively, "uname -snrvmo"
PCPU=$(grep -c 'physical id' /proc/cpuinfo) # -c => print count of matching lines
VCPU=$(grep -c processor /proc/cpuinfo)
FULLRAM=$(free -m | grep Mem: | awk '{print $2}')
USEDRAM=$(free -m | grep Mem: | awk '{print $3}')
PCTRAM=$(free -m | grep Mem: | awk '{printf("%.2f"), $3/$2*100}')
FULLDISK=$(df -BG | grep /dev/ | grep -v /boot | awk '{fd += $2} END {print fd}') # grep -v means invert match
USEDDISK=$(df -BM | grep /dev/ | grep -v /boot | awk '{ud += $3} END {print ud}')
PCTDISK=$(df -Bm | grep /dev/ | grep -v /boot | awk '{ud += $3} {fd += $2} END {printf("%d"), ud/fd*100}')
CPU=$(top -bn1 | grep '^%Cpu' | cut -c 9- | xargs | awk '{printf("%.1f%%"), $1 + $3}')
LASTBOOT=$(who -b | awk '$1 == "system" {print $3 " " $4}')
LVM=$(if [ $(lsblk | grep "lvm" | wc -l) -eq 0 ]; then echo no; else echo yes; fi)
TCP=$(netstat -an | grep ESTABLISHED | wc -l) # display connection for TCP
TCPMSSG=$(if [ ${TCP} -eq 0 ]; then echo NOT ESTABLISHED; else echo ESTABLISHED; fi)
USERLOG=$(users | wc -w) # wc -w => counts words
IP=$(hostname -I)
MAC=$(ip link show | awk '$1 == "link/ether" {print $2}')
SUDO=$(journalctl _COMM=sudo | grep COMMAND | wc -l)
## Shows the architecture of the operating system and its kernel version
echo "#Architecture: ${ARCH}"
## Shows the number of physical processors (CPUs)
echo "#CPU physical: ${PCPU}"
## Shows the number of virtual processors (vCPUs)
echo "#vCPU: ${VCPU}"
## Shows the current available RAM on your server and its utilization rate as percentage
echo "#Memory Usage: ${USEDRAM}/${FULLRAM}MB (${PCTRAM}%)"
## Shows the current available memory on your server and its utilization rate as a percentage
echo "#Disk Usage: ${USEDDISK}/${FULLDISK}Gb (${PCTDISK}%)"
## Shows the current utilization rate of your processors as a percentage
echo "#CPU load: ${CPU}"
## Shows the date and time of the last reboot
echo "#Last boot: ${LASTBOOT}"
## Shows whether LVM is active or not
echo "#LVM use: ${LVM}"
## Shows the number of active connections
echo "#Connections TCP: ${TCP} ${TCPMSSG}"
## Shows the number of users using the server
echo "#User log: ${USERLOG}"
## Shows the IPv4 address of your server and its MAC (Media Access Control) address
echo "#Network: IP ${IP} (${MAC})"
## Shows the number of commands executed with the sudo program
echo "#Sudo: ${SUDO} cmd"