scripts / monitoring.d / raspberrypi /
Newer Older
89 lines | 3.004kb
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
1
# vim: ft=sh
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
2
dir=$1
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
3

            
4
function nginx () {
5
    nc -zw2 127.0.0.1 80 || echo "injoignable sur port 80 local"
6
    nc -zw2 sebmarque.hd.free.fr 80 || echo "injoignable sur port 80 distant"
7
    nc -zw2 sebmarque.hd.free.fr 443 || echo "injoignable sur port 443 distant"
8
}
9

            
10
function searx () {
11
    nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888"
12
}
13

            
14
function gitprep () {
15
    nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020"
16
}
17

            
18
function cherrymusic () {
19
    nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080"
20
}
21

            
ajout du monitoring des diff...
Sébastien MARQUE authored on 2017-02-24
22
function webapps () {
23
    local webapps_conf="$dir/${HOSTNAME}.webapps.conf"
24
    if test -r $webapps_conf; then
25
        local useragent=
26
        local host=
27
        local proto=
28
        local webapps=()
29
        local no_access=()
30
        eval "$(< $webapps_conf)"
31
        test -z "$useragent" && echo "manque user-agent" && return
32
        test -z "$host" && echo "manque hôte" && return
33
        test -z "$proto" && echo "manque protocole" && return
34
        test $(( ${#webapps[@]} % 3 )) -ne 0 && echo "mauvais nombre de paramètres de tests" && return
35
        for ((i=0; i<${#webapps[@]}; i+=3)); do
36
            http_response=$(curl --silent --max-time 2 --user-agent "$useragent" --output /dev/null --write-out "%{response_code}" $proto://$host/${webapps[i]})
37
            test $http_response -ne ${webapps[i+2]} && no_access[${#no_access[@]}]="${webapps[i+1]} ($http_response)"
38
        done
39
        if test ${#no_access[@]} -ne 0; then
40
            echo "réponse incorrecte: ${no_access[@]}"
41
        fi
42
    else
43
        echo "pas de conf! ($webapps_conf)"
44
    fi
45
}
46

            
ajout de la supervision
Sébastien MARQUE authored on 2017-02-22
47
function core_temp () {
48
    local min=60
49
    local level=("warning" "severe" "danger!")
50
    local step=$(( $(</sys/class/thermal/thermal_zone0/temp) - (min * 1000) ))
51
    if test $step -gt 0; then
52
        step=$((step / 10000))
53
        test $step -le 3 || step=2
54
        echo "${level[step]}: température > $((min + step * 10))°"
55
    fi
56
}
57

            
58
function core_alim () {
59
    eval $(/opt/vc/bin/vcgencmd measure_volts core)
60
    test $volt == "1.2000V" || echo "$volt"
61
}
62

            
63
function load_avg () {
64
    local procs=4
65
    local load=($(</proc/loadavg))
66
    local avg=(1 5 15)
67
    for ((i=0; i<${#avg[@]}; i++)); do
68
        test ${load[i]%.*} -ge $procs && echo "charge moyenne à ${avg[i]}min = ${load[i]}"
69
    done
70
}
71

            
72
function mem_pressure () {
73
    local meminfo=($(</proc/meminfo))
74
    local level=(danger severe warning)
75
    local margin=30000
76
    for ((i=0; i<${#meminfo[@]}; i+=3)); do
77
        test ${meminfo[i]} == 'MemAvailable:' && break
78
    done
79
    meminfo[i+2]=$(( ( ${meminfo[i+1]} - $margin ) / 100000 ))
80
    test ${meminfo[i+2]} -ge ${#range[@]} || echo "${level[${meminfo[i+2]}]}: available ${meminfo[i+1]}kB"
81
}
82

            
83
function mpd_tablette () {
84
    local tablette=192.168.0.53
85
    local port=6600
86
    local nfs=$(ss -no state established 'sport = :nfs' dst $tablette | grep -c $)
87
    test $nfs -lt 3 && echo "tablette non connectée à la zique"
88
    nc -zw2 $tablette $port || echo "MPD injoignable"
89
}