root / plugins / memcached / memcached_servers_ @ 8589c6df
Historique | Voir | Annoter | Télécharger (7,06 ko)
| 1 |
#!/usr/bin/env perl |
|---|---|
| 2 |
=head1 NAME |
| 3 |
|
| 4 |
memcached_servers_ - Munin multigraph plugin to monitor multiple memcache servers |
| 5 |
|
| 6 |
=head1 CONFIGURATION |
| 7 |
|
| 8 |
You need to configure the to-be-used servers and the corresponding labels separated |
| 9 |
by spaace in your environment. Example: |
| 10 |
|
| 11 |
[memcached_servers_*] |
| 12 |
env.addresses cache1.server.com:11211 cache2.server.com:11211 |
| 13 |
env.labels master slave |
| 14 |
|
| 15 |
Please note that the number of labels and addresses must be equal. |
| 16 |
|
| 17 |
|
| 18 |
=head1 MULTIGRAPH |
| 19 |
|
| 20 |
With munin multigraph capabilities, you can generate different graphs. Available |
| 21 |
graphs include: |
| 22 |
|
| 23 |
=over |
| 24 |
|
| 25 |
=item bytes: memcached bytes usage |
| 26 |
|
| 27 |
=item hits: get and set hits |
| 28 |
|
| 29 |
=item items: number of stored items |
| 30 |
|
| 31 |
=item requests: number of requests |
| 32 |
|
| 33 |
=item traffic: traffic |
| 34 |
|
| 35 |
=back |
| 36 |
|
| 37 |
Link the plugin to get the desirec output, for example: memcached_multi_bytes |
| 38 |
|
| 39 |
|
| 40 |
=head1 DEPENDENCIES |
| 41 |
|
| 42 |
=over |
| 43 |
|
| 44 |
=item Cache::Memcached |
| 45 |
|
| 46 |
=back |
| 47 |
|
| 48 |
|
| 49 |
=head1 ACKNOWLEDGEMENTS |
| 50 |
|
| 51 |
This plugin is based on the available memcached plugins at |
| 52 |
L<https://github.com/munin-monitoring/contrib/tree/master/plugins/memcached> |
| 53 |
|
| 54 |
=head1 AUTHORS |
| 55 |
|
| 56 |
Jonas Kaufmann <jonas@windfinder.com> |
| 57 |
|
| 58 |
=cut |
| 59 |
|
| 60 |
use strict; |
| 61 |
use warnings; |
| 62 |
use Cache::Memcached; |
| 63 |
use File::Basename; |
| 64 |
|
| 65 |
#Configuration of used servers in environment |
| 66 |
my @addresses = split(/ /, $ENV{addresses});
|
| 67 |
my @labels = split(/ /, $ENV{labels});
|
| 68 |
|
| 69 |
if ($#addresses < 0 || $#labels < 0) {
|
| 70 |
print "Error: you need to configure addresses and labels in your environment.\n"; |
| 71 |
exit 1; |
| 72 |
} |
| 73 |
|
| 74 |
if ($#addresses != $#labels) {
|
| 75 |
print "Error: number of addresses and labels must be equal.\n"; |
| 76 |
exit 1; |
| 77 |
} |
| 78 |
|
| 79 |
# Configuration of modes for multigraph |
| 80 |
my @modes = qw(bytes hits items requests traffic); |
| 81 |
|
| 82 |
my $mode = substr(basename($0), length('memcached_servers_'));
|
| 83 |
if (($mode eq '') || ! grep($_ eq $mode, @modes)) {
|
| 84 |
$mode = $modes[0]; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
# Output for munin config |
| 89 |
my $cmd = shift || ''; |
| 90 |
if ($cmd eq 'config') {
|
| 91 |
# Labels and basic graph information |
| 92 |
if ($mode eq 'bytes') {
|
| 93 |
print "graph_title Memcached bytes used\n"; |
| 94 |
print "graph_args --base 1024 -l 0\n"; |
| 95 |
print "graph_vlabel bytes\n"; |
| 96 |
print "graph_category memory\n"; |
| 97 |
print "graph_info This graph monitors the size of the memcached cache.\n"; |
| 98 |
} elsif ($mode eq 'hits') {
|
| 99 |
print "graph_title Memcached cache hits and misses\n"; |
| 100 |
print "graph_args --base 1000 -l 0\n"; |
| 101 |
print "graph_vlabel requests\n"; |
| 102 |
print "graph_category memory\n"; |
| 103 |
print "graph_info This graph monitors the number of cache hits and misses.\n"; |
| 104 |
} elsif ($mode eq 'items') {
|
| 105 |
print "graph_title Memcached cached items\n"; |
| 106 |
print "graph_args --base 1000 -l 0\n"; |
| 107 |
print "graph_vlabel items\n"; |
| 108 |
print "graph_category memory\n"; |
| 109 |
print "graph_info This graph monitors the number of items stored by the memcached server.\n"; |
| 110 |
} elsif ($mode eq 'requests') {
|
| 111 |
print "graph_title Memcached requests\n"; |
| 112 |
print "graph_args --base 1000 -l 0\n"; |
| 113 |
print "graph_vlabel requests\n"; |
| 114 |
print "graph_category memory\n"; |
| 115 |
print "graph_info This graph monitors the number of get and set requests.\n"; |
| 116 |
} elsif ($mode eq 'traffic') {
|
| 117 |
print "graph_title Memcached network traffic\n"; |
| 118 |
print "graph_args --base 1000 -l 0\n"; |
| 119 |
print "graph_vlabel bits per \${graph_period}\n";
|
| 120 |
print "graph_category memory\n"; |
| 121 |
print "graph_info This graph monitors the network traffic of the memcached server.\n"; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
# Graph configuration |
| 126 |
for (my $i = 0; $i < @labels; $i++) {
|
| 127 |
if ($mode eq 'bytes') {
|
| 128 |
print "bytes_" . $labels[$i] . ".label bytes used (" . $labels[$i] . ")\n";
|
| 129 |
print "bytes_" . $labels[$i] . ".info Number of bytes currently used (" . $labels[$i] . ")\n";
|
| 130 |
print "bytes_" . $labels[$i] . ".min 0\n"; |
| 131 |
print "maxbytes_" . $labels[$i] . ".label maximum available (" . $labels[$i] . ")\n";
|
| 132 |
print "maxbytes_" . $labels[$i] . ".info The configured cache size (" . $labels[$i] . ")\n";
|
| 133 |
print "maxbytes_" . $labels[$i] . ".min 0\n"; |
| 134 |
} elsif ($mode eq 'hits') {
|
| 135 |
print "hits_" . $labels[$i] . ".label hits (" . $labels[$i] . ")\n";
|
| 136 |
print "hits_" . $labels[$i] . ".info Number of cache hits (" . $labels[$i] . ")\n";
|
| 137 |
print "hits_" . $labels[$i] . ".min 0\n"; |
| 138 |
print "hits_" . $labels[$i] . ".type DERIVE\n"; |
| 139 |
print "misses_" . $labels[$i] . ".label misses (" . $labels[$i] . ")\n";
|
| 140 |
print "misses_" . $labels[$i] . ".info Number of cache misses (" . $labels[$i] . ")\n";
|
| 141 |
print "misses_" . $labels[$i] . ".min 0\n"; |
| 142 |
print "misses_" . $labels[$i] . ".type DERIVE\n"; |
| 143 |
} elsif ($mode eq 'items') {
|
| 144 |
print "items_" . $labels[$i] . ".label items (" . $labels[$i] . ")\n";
|
| 145 |
print "items_" . $labels[$i] . ".info Number of cached items (" . $labels[$i] . ")\n";
|
| 146 |
print "items_" . $labels[$i] . ".min 0\n"; |
| 147 |
} elsif ($mode eq 'requests') {
|
| 148 |
print "gets_" . $labels[$i] . ".label gets (" . $labels[$i] . ")\n";
|
| 149 |
print "gets_" . $labels[$i] . ".info Number of get requests (" . $labels[$i] . ")\n";
|
| 150 |
print "gets_" . $labels[$i] . ".min 0\n"; |
| 151 |
print "gets_" . $labels[$i] . ".type DERIVE\n"; |
| 152 |
print "sets_" . $labels[$i] . ".label sets (" . $labels[$i] . ")\n";
|
| 153 |
print "sets_" . $labels[$i] . ".info Number of set requests (" . $labels[$i] . ")\n";
|
| 154 |
print "sets_" . $labels[$i] . ".min 0\n"; |
| 155 |
print "sets_" . $labels[$i] . ".type DERIVE\n"; |
| 156 |
} elsif ($mode eq 'traffic') {
|
| 157 |
print "up_" . $labels[$i] . ".label bits in (" . $labels[$i] . ")\n";
|
| 158 |
print "up_" . $labels[$i] . ".info Traffic received by memcached (" . $labels[$i] . ")\n";
|
| 159 |
print "up_" . $labels[$i] . ".min 0\n"; |
| 160 |
print "up_" . $labels[$i] . ".cdef up_" . $labels[$i] . ",8,*\n"; |
| 161 |
print "up_" . $labels[$i] . ".type COUNTER\n"; |
| 162 |
print "down_" . $labels[$i] . ".label bits out (" . $labels[$i] . ")\n";
|
| 163 |
print "down_" . $labels[$i] . ".info Traffic sent by memcached (" . $labels[$i] . ")\n";
|
| 164 |
print "down_" . $labels[$i] . ".min 0\n"; |
| 165 |
print "down_" . $labels[$i] . ".cdef down_" . $labels[$i] . ",8,*\n"; |
| 166 |
print "down_" . $labels[$i] . ".type COUNTER\n"; |
| 167 |
} |
| 168 |
} |
| 169 |
exit 0; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
# Output for data queries |
| 175 |
for (my $i = 0; $i < @addresses; $i++) {
|
| 176 |
my $memd = new Cache::Memcached { 'servers' => [$addresses[$i]] };
|
| 177 |
my $memstats = $memd->stats(['misc']); |
| 178 |
|
| 179 |
if ($mode eq 'bytes') {
|
| 180 |
print "bytes_" . $labels[$i] . ".value " . |
| 181 |
$memstats->{hosts}->{$addresses[$i]}->{misc}->{bytes} . "\n";
|
| 182 |
print "maxbytes_" . $labels[$i] . ".value " . |
| 183 |
$memstats->{hosts}->{$addresses[$i]}->{misc}->{limit_maxbytes} . "\n";
|
| 184 |
} elsif ($mode eq 'hits') {
|
| 185 |
print "hits_" . $labels[$i] . ".value " . |
| 186 |
$memstats->{hosts}->{$addresses[$i]}->{misc}->{get_hits} . "\n";
|
| 187 |
print "misses_" . $labels[$i] . ".value " . |
| 188 |
$memstats->{hosts}->{$addresses[$i]}->{misc}->{get_misses} . "\n";
|
| 189 |
} elsif ($mode eq 'items') {
|
| 190 |
print "items_" . $labels[$i] . ".value " . |
| 191 |
$memstats->{hosts}->{$addresses[$i]}->{misc}->{curr_items} . "\n";
|
| 192 |
} elsif ($mode eq 'requests') {
|
| 193 |
print "gets_" . $labels[$i] . ".value " . $memstats->{hosts}->{$addresses[$i]}->{misc}->{cmd_get} . "\n";
|
| 194 |
print "sets_" . $labels[$i] . ".value " . $memstats->{hosts}->{$addresses[$i]}->{misc}->{cmd_set} . "\n";
|
| 195 |
} elsif ($mode eq 'traffic') {
|
| 196 |
print "up_" . $labels[$i] . ".value " . $memstats->{hosts}->{$addresses[$i]}->{misc}->{bytes_read} . "\n";
|
| 197 |
print "down_" . $labels[$i] . ".value " . $memstats->{hosts}->{$addresses[$i]}->{misc}->{bytes_written} . "\n";
|
| 198 |
} |
| 199 |
|
| 200 |
} |
| 201 |
|
