Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / healthcheck / healthcheck_process @ da59e03c

Historique | Voir | Annoter | Télécharger (2,22 ko)

1
#!/bin/bash
2
#
3
#healthcheck on munin
4
#check process and alert.
5
#
6
#programed by rti (hiroyuki fujie) super.rti@gmail.com @super_rti
7
#LICENSE: NYSL (public domain)
8
#
9
#config file
10
#      /etc/munin/plugin-conf.d/munin-node
11
#
12
#example minimum config
13
#---------------------------------------------------
14
#[healthcheck_process]
15
#env.process_1 httpd
16
#---------------------------------------------------
17
#
18
#chcek two process
19
#---------------------------------------------------
20
#[healthcheck_process]
21
#env.process_1 httpd
22
#env.process_2 samba
23
#---------------------------------------------------
24
#
25
#chcek three process
26
#---------------------------------------------------
27
#[healthcheck_process]
28
#env.process_1 httpd
29
#env.process_2 samba
30
#env.process_3 mysqld
31
#---------------------------------------------------
32
#
33
#
34
#
35

    
36
#edakari speed up.
37
CHECKMAX=`env | grep process_ | wc -l`
38
let CHECKMAX="$CHECKMAX + 1"
39

    
40
if [ "$1" = "autoconf" ]; then
41
    if [ $CHECKMAX -le 1 ]; then
42
         echo no
43
         exit 1
44
    fi
45
    echo yes
46
    exit 0
47
fi
48

    
49
if [ "$1" = "config" ]; then
50

    
51
    echo 'graph_title process memory Usage(MB)'
52
    echo "graph_args --base 1000 -l 0 --vertical-label MB"
53
    echo 'graph_scale no'
54
    echo 'graph_vlabel process memory'
55
    echo 'graph_category healthcheck'
56
    echo 'graph_info This graph shows the Memory used by process'
57

    
58
    for(( I = 1; I < $CHECKMAX; ++I ))
59
    do
60
         eval process=\$process_${I}
61
         eval alertmemory=\$alertmemory_${I}
62
         if [ "x${process}" = "x" ]; then
63
              continue
64
         fi
65

    
66
         echo "$process.label $process"
67
         echo "$process.info Memory used by $process"
68
         echo "$process.draw LINE2"
69
         echo "$process.min -10"
70
         echo "$process.critical 0:"
71
    done
72

    
73
    exit 0
74
fi
75

    
76
for(( I = 1; I < $CHECKMAX; ++I ))
77
do
78
     eval process=\$process_${I}
79
     if [ "x${process}" = "x" ]; then
80
         continue
81
     fi
82

    
83
     vrets=(`ps u --no-headers -C $process | awk 'BEGIN { count = 0 ; sum = 0; } { count ++ ; sum += $6/1024 ; } END { printf("%d %d\n",count,sum); }'`)
84
     count=${vrets[0]}
85
     value=${vrets[1]}
86
     if [ $count -le 0 ]; then
87
         echo "$process.value -10"
88
         echo "$process.extinfo process down"
89
     else
90
         echo "$process.value $value"
91
     fi
92
done