-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitoramento_recursos.sh
More file actions
61 lines (52 loc) · 1.6 KB
/
monitoramento_recursos.sh
File metadata and controls
61 lines (52 loc) · 1.6 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
#---------------------------------------------------------------
# MONITOR DE RECURSOS
#---------------------------------------------------------------
cron="S" # Se for utilizar a crontab mudar para "S" assim o script
# será executado apenas uma vez e a crontab fará o novo
# start, quando necessário.
delay="300" # Se for deixar o script executando pelo loop interno
# indicar aqui o número de segundos entre as verificações.
# ex: "300" que correponde a 5 minutos.
ve_filesystem ()
{
df -h | grep -v ^Filesystem | while read line
do
percent=`echo $line | awk '{ print $5 }' | sed 's/%//g'`
if [ "$percent" -gt "70" ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` - TIPO: FILESYSTEM - $percent % de Ulilizazao do Filesystem `echo $line | awk '{ print $1 }'`" >> centraldealertas.txt
fi
done
}
ve_memoria ()
{
percent=`free -m | awk '/^Mem/{ print $3,"*100","/",$2}' | sed 's/ //g' | bc`
if [ "$percent" -gt "70" ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` - TIPO: MEMORIA - $percent % da Memoria utilizada" >> centraldealertas.txt
fi
}
ve_cpu ()
{
percent=`vmstat 1 2 | sed 1,3d | awk '{ print $('$locale') }'`
if [ "$percent" -lt "30" ]; then
echo "`date +"%Y-%m-%d %H:%M:%S"` - TIPO: CPU LOAD - `expr 100 - $percent` % de CPU Utilizada" >> centraldealertas.txt
fi
}
start ()
{
ve_filesystem
ve_memoria
ve_cpu
case "$cron" in
"N" | "n" )
sleep "$delay"
start
;;
esac
}
ve_vmstat ()
{
cvstat=`vmstat | sed -e 1,1d -e 3,3d | sed 's/id.*//g' | wc -w`
locale=`expr $cvstat + 1`
}
ve_vmstat
start