Projet

Général

Profil

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

root / plugins / apache / apache_cache_disk_count @ 8589c6df

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

1 71f28aaf Raphaël Droz
#!/bin/bash
2
3
: << =cut
4
5
=head1 NAME
6
7
Munin plugin to monitor apache mod_cache_disk usage.
8
9
=head1 CONFIGURATION
10
11
[apache_cache_disk_count]
12
	user www-data
13
	env.cache_path /var/cache/apache2/mod_cache_disk
14
	env.strings css js
15
	env.label_cs CSS
16
	env.colour_css FFFF00
17
	env.label_js JS
18
	env.colour_js FF0000
19
20
=head1 AUTHOR
21
22
Raphaël Droz <raphael.droz+floss@gmail.com>
23
24
=head1 LICENSE
25
26
GPLv2
27
28
=head1 MAGICK MARKERS
29
30
 #%# family=auto
31
 #%# capabilities=autoconf
32
33
=cut
34
35
. $MUNIN_LIBDIR/plugins/plugin.sh
36
37
my_cache_path="${cache_path:-/var/cache/apache2/mod_cache_disk}"
38
declare -a fieldnames labels colours
39
40
getenvdata() {
41
    let during_autoconf=0
42
    [[ $1 == -v ]] && during_autoconf=1
43
    arg=( "${strings:-}" )
44
    for i in ${arg[*]}; do
45
        if [[ ! $i =~ ^[a-zA-Z0-9]+$ ]]; then
46
            (( $during_autoconf )) && echo "no ($i isn't a valid fixed-string)"
47
            ok=0
48
            continue
49
        fi
50
        label=label_$i
51
        if [[ -z "${!label}" ]]; then
52
            (( $during_autoconf )) && echo "no ($i isn't given a label)"
53
            ok=0
54
            continue
55
        fi
56
        colour=colour_$i
57
        if [[ -z "${!colour}" ]]; then
58
            (( $during_autoconf )) && echo "no ($i isn't given a colour)"
59
            ok=0
60
            continue
61
        fi
62
63
        fieldnames+=($i)
64
        labels+=("${!label}")
65
        colours+=("${!colour}")
66
    done
67
}
68
69
if [[ $1 == autoconf ]]; then
70
    let ok=1
71
72
    [[ -z $strings ]] && echo "no strings to monitor defined" && ok=0
73
    ! type -P htcacheclean &>/dev/null && echo "can't find htcacheclean" && ok=0
74
    ! test -d "$my_cache_path" && echo "cache_path \"$cache_path\" is not readable" && ok=0
75
76
    getenvdata -v
77
78
    (( ${#fieldnames[*]} == 0 )) && echo "no (no valid strings)" && ok=0
79
    (( $ok == 1 )) && echo yes
80
    exit 0
81
fi
82
83
getenvdata
84
85
if [[ $1 == config ]]; then
86
cat <<EOF
87
graph_title Apache mod_cache_disk usage
88
graph_title Number of entries in mod_cache_disk Apache cache
89
graph_args --base 1000 -l 0
90
graph_vlabel Y
91 65652aa0 dipohl
graph_category webserver
92 71f28aaf Raphaël Droz
graph_order ${fieldnames[*]} total
93
total.draw LINE1
94
total.label all
95
total.type GAUGE
96
total.min 0
97
EOF
98
99
    let i=0
100
    while (( $i < ${#fieldnames[*]} )); do
101
        string=${fieldnames[$i]}
102
        label="${labels[$i]}"
103
        colour="${colours[$i]}"
104
        cat <<EOF
105
${string}.draw AREASTACK
106
${string}.label ${label}
107
${string}.colour ${colour}
108
EOF
109
        ((i++))
110
    done
111
    exit 0
112
fi
113
114
total=$(htcacheclean -a -p "$my_cache_path"|wc -l)
115
asset_count=$(htcacheclean -a -p "$my_cache_path"|egrep -o "\.($(echo ${fieldnames[*]}|tr ' ' '|'))"|sort|uniq --count)
116
printf "total.value %d\n" "$total"
117
for i in ${fieldnames[*]}; do
118
    c=$(echo "$asset_count"|sed -rn "/$i/s;^\s*([0-9]+).*;\1;p")
119
    [[ -z $c ]] && c=U
120
    printf "%s.value %s\n" "$i" "$c"
121
done
122
123
exit 0