-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoring.sh
More file actions
81 lines (69 loc) · 2.98 KB
/
Copy pathmonitoring.sh
File metadata and controls
81 lines (69 loc) · 2.98 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# **************************************************************************** #
# #
# ::: :::::::: #
# monitoring.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: echavez- <echavez-@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/01/31 12:22:02 by echavez- #+# #+# #
# Updated: 2023/01/31 14:39:09 by echavez- ### ########.fr #
# #
# **************************************************************************** #
#!/bin/bash
function ft_ram()
{
# RAM INFO
## Variables
local _free=$(free -m | grep Mem | awk '{print $3}')
local _total=$(free -m | grep Mem | awk '{print $2}')
local _usage_percent=$(free -m | grep Mem | awk '{printf("%.2f"), $3 / $2 * 100}')
## Return formated info
echo "${_free}/${_total}MB (${_usage_percent}%)"
}
function ft_mem()
{
# DISK MEMORY INFO
## Disk description lines
local _mem_mb=$(df -Bm | grep '^/dev/' | grep -v '/boot$') # megas
local _mem_gb=$(df -Bg | grep '^/dev/' | grep -v '/boot$') # gigas
## Variables
local _free=$(echo "$_mem_mb" | awk '{free_mem += $4} END {print free_mem}')
local _total=$(echo "$_mem_gb" | awk '{total_mem += $2} END {print total_mem}')
local _usage_percent=$(echo "$_mem_mb" | awk '{used_mem += $3} {total_mem += $2} END \
{printf("%.2f"), used_mem / total_mem * 100}')
## Return formated info
echo "${_free}/${_total}GB (${_usage_percent}%)"
}
function ft_ip_mac()
{
# IP & MAC ADDRESS
## Variables
local _ip=$(hostname -I)
local _mac=$(ip a | grep link/ether | awk '{print $2}')
##Return formated info
echo "IP $_ip ($_mac)"
}
architecture=$(uname -a)
phy_proc=$(grep "^physical id" /proc/cpuinfo | sort -u | wc -l)
vir_proc=$(grep "^processor" /proc/cpuinfo | wc -l)
av_ram=$(ft_ram)
av_mem=$(ft_mem)
cpu_load=$(top -bn1 | grep '^%Cpu' | awk '{printf("%.1f%%"), $2}')
last_reboot=$(who -b | awk '{print $3" "$4" "$5}')
lvm_active=$(lsblk | grep -m1 lvm | awk '{if ($1) {print "yes"} else {print "no"} }')
active_connections=$(ss -t | grep ESTAB | wc -l)
active_users=$(who | cut -d" " -f1 | sort -u | wc -l)
ip_mac=$(ft_ip_mac)
sudo_commands=$(grep 'sudo:session' /var/log/auth.log | grep -v 'session closed\|COMMAND' | wc -l)
wall " #Architecture: $architecture
#CPU physical: $phy_proc
#vCPU: $vir_proc
#Memory Usage: $av_ram
#Disk Usage: $av_mem
#CPU Load: $cpu_load
#Last boot: $last_reboot
#LVM use: $lvm_active
#Connections TCP: $active_connections
#User log: $active_users
#Network: $ip_mac
#Sudo: $sudo_commands cmd"