Projet

Général

Profil

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

root / plugins / mysql / hs_read @ 527cb89f

Historique | Voir | Annoter | Télécharger (1,47 ko)

1 527cb89f Konstantin Kuklin
#!/bin/bash
2 75d48c96 Konstantin Kuklin
#
3
: <<=cut
4
5
=head1 NAME
6
7
hs_read - Plugin to monitor HandlerSocket read port usage.
8
9
=head1 APPLICABLE SYSTEMS
10
11
All Linux systems
12
13
=head1 CONFIGURATION
14
15
The following is default configuration
16
17
  [hs_read_connections]
18
	env.mysql_host      localhost
19
	env.mysql_port	    3306
20
	env.mysql_user      root
21
	env.mysql_password  pass
22
23
=head1 AUTHOR
24
25
Konstantin Kuklin <konstantin.kuklin@gmail.com>
26
27
=head1 LICENSE
28
29
MIT
30
31
=cut
32
33
. $MUNIN_LIBDIR/plugins/plugin.sh
34
35
if [ "$1" = "autoconf" ]; then
36
    echo no
37
    exit 0
38
fi
39
40
if [ "$1" = "config" ]; then
41
42
    echo 'graph_title HS Read port connections'
43 c69a5761 Konstantin Kuklin
    echo "graph_args --base 1000 -l 0"
44
    echo 'graph_category mysql'
45 75d48c96 Konstantin Kuklin
    echo 'total.label Total'
46
    echo 'total.draw AREA'
47
    echo 'total.min 0'
48
    echo 'active.label Active'
49
    echo 'active.draw LINE2'
50
    echo 'active.min 0'
51
    exit 0
52
fi
53
54
# query
55
command='mysql';
56
57 c69a5761 Konstantin Kuklin
if [[ ! -z $mysql_host ]]; then
58 75d48c96 Konstantin Kuklin
    command="$command -h $mysql_host"
59
fi
60
61 c69a5761 Konstantin Kuklin
if [  -z $mysql_user ]; then
62 75d48c96 Konstantin Kuklin
    command="$command -u root"
63 c69a5761 Konstantin Kuklin
else
64
    command="$command -u $mysql_user"
65 75d48c96 Konstantin Kuklin
fi
66
67 c69a5761 Konstantin Kuklin
if [[ ! -z $mysql_password ]]; then
68 75d48c96 Konstantin Kuklin
    command="$command -p$mysql_password"
69
fi
70
71 c69a5761 Konstantin Kuklin
if [[ ! -z $mysql_port ]]; then
72 75d48c96 Konstantin Kuklin
    command="$command -P $mysql_port"
73
fi
74
75
totalConnections=$(echo 'show processlist;' | $command | awk ' /'mode=rd'/ {x += $11}; END {print x}')
76
totalActiveConnections=$(echo 'show processlist;' | $command | awk ' /'mode=rd'/ {x += $13}; END {print x}')
77
78 c69a5761 Konstantin Kuklin
echo "total.value $totalConnections";
79
echo "active.value $totalActiveConnections";