supervision cloud
|
1 |
# vim: ft=sh |
2 | ||
3 |
function nginx () { |
|
4 |
nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local" |
|
5 |
nc -zw2 paris12.pcf.fr 80 || echo "injoignable sur port 80 distant" |
|
6 |
nc -zw2 paris12.pcf.fr 443 || echo "injoignable sur port 443 distant" |
|
7 |
} |
|
8 | ||
9 |
function core_temp () { |
|
10 |
local min=60 |
|
11 |
local level=("warning" "severe" "danger!") |
|
12 |
local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) )) |
|
13 |
if test $step -gt 1; then |
|
14 |
# if test $step -gt 5000; then # en été il fait plus chaud, c'est normal que ça monte à 60° régulièrement |
|
15 |
step=$((step / 10000)) |
|
16 |
test $step -le 2 || step=2 |
|
17 |
echo "${level[step]}: température > $((min + step * 10))°" |
|
18 |
fi |
|
19 |
} |
|
20 | ||
21 |
function core_alim () { |
|
22 |
eval $(/opt/vc/bin/vcgencmd measure_volts core) |
|
23 |
volt_fmt=${volt/\.} |
|
24 |
volt_fmt=${volt_fmt/V} |
|
25 |
test $volt_fmt -lt 12000 -o $volt_fmt -gt 15000 && echo "$volt" |
|
26 |
} |
|
27 | ||
ajoute contrôle de sous alim...
|
28 |
function undervoltage () { |
29 |
test $(grep -c "hwmon hwmon1" /var/log/syslog) -gt 0 && echo "Undervoltage detected!" |
|
30 |
} |
|
31 | ||
gère swap et cache
|
32 |
function clean_swap () { |
33 |
_turn 2 || return |
|
libère le cache plus réguliè...
|
34 |
echo 1 > /proc/sys/vm/drop_caches |
fix bad return code
|
35 |
if LANG=C free -m | awk ' |
gère swap et cache
|
36 |
/^Swap:/ { |
37 |
used = $3 |
|
38 |
} |
|
39 |
END { |
|
fix bad return code
|
40 |
bash_exit_code = !(used > 31) |
41 |
exit bash_exit_code |
|
gère swap et cache
|
42 |
} |
43 |
'; then |
|
44 |
systemctl stop dphys-swapfile \ |
|
45 |
&& systemctl stop zram \ |
|
46 |
&& systemctl start zram \ |
|
47 |
&& systemctl start dphys-swapfile \ |
|
48 |
|| echo 'erreur' |
|
49 |
fi |
|
50 |
} |
|
51 | ||
supervision cloud
|
52 |
function mem_pressure () { |
53 |
local meminfo=($(</proc/meminfo)) |
|
54 |
local level=(danger severe warning) |
|
55 |
local margin=30000 |
|
56 |
for ((i=0; i<${#meminfo[@]}; i+=3)); do |
|
57 |
test ${meminfo[i]} == 'MemAvailable:' && break |
|
58 |
done |
|
59 |
meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 )) |
|
60 |
test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB" |
|
61 |
} |
|
alerte sur toner black
|
62 | |
63 |
function printer () { |
|
64 |
_turn 24 || return |
|
65 |
local min=20 |
|
66 |
local level=(extreme danger warning info) |
|
67 |
local printer=192.168.1.54 |
|
68 |
local prtMarkerSuppliesMaxCapacity=1.3.6.1.2.1.43.11.1.1.8.1 |
|
69 |
local prtMarkerSuppliesLevel=1.3.6.1.2.1.43.11.1.1.9.1 |
|
70 |
local left=$(snmpget -v 1 -c public $printer ${prtMarkerSuppliesLevel}.4) |
|
71 |
local full=$(snmpget -v 1 -c public $printer ${prtMarkerSuppliesMaxCapacity}.4) |
|
72 | ||
73 |
if test ${full#*:} -ne 0; then |
|
74 |
local step=$(((${left#*:}*100/${full#*:})/5)) |
|
75 |
if test $step -le ${#level[@]}; then |
|
76 |
echo "${level[$step]} toner black" |
|
77 |
fi |
|
78 |
fi |
|
79 |
} |