forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcached_
executable file
·261 lines (254 loc) · 6.49 KB
/
memcached_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/perl
#
# Plugin to monitor memcache statistics
#
# This module has 3 separate graph DATASETS:
# rates
# bytes
# counters
#
# For each of them, symlink the memcached_ script to memcached_DATASET.
#
# If multiple memcache instances are running memcached_INSTANCE_DATASET can be
# used and INSTANCE can be any instance name that will show up in the title.
# In thise case your config should specify a different port/host for each like
# using the following in plugin configuration file:
#
# [memcached_pages_*]
# env.port=11212
#
# Parameters supported:
#
# config
# autoconf
# suggest
#
# Configurable variables
#
# host Host of the memcache daemon
# port Port of the memcache daemon
#
# Author: Robin H. Johnson <[email protected]>
# Edited for suggest/instance names: Daniel Black <[email protected]> - 2014-08-26
#
# Slightly based on the original version by Joshua Thijssen
#
# Magic markers:
#%# family=auto
#%# capabilities=suggest autoconf
use strict;
my $ret = undef;
if (! eval "require Cache::Memcached;") {
$ret = "Cache::Memcached not found";
}
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 11211;
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
if ($ret) {
print "no ($ret)\n";
exit 1;
}
# Todo: we can always connect to a memcache server without any errors so I cannot really
# find a way to detect the presence of a memcache instance. Maybe a forced write/read/delete
# but there should be a better way somewhere...
print "yes\n";
exit 0;
}
if ( exists $ARGV[0] and $ARGV[0] eq "suggest" ) {
print "rates\nbytes\ncounters\n";
exit 0;
}
if($ret) {
print "no ($ret)\n";
exit 1;
}
# We do everything by this array
my %all_vars = (
rates => {
graph_title => 'Memcached - Commands',
master => {
graph_args => '--base 1000',
graph_vlabel => '/${graph_period}',
graph_category => 'memcache',
},
memcache_cache_hits => {
label => 'Cache hits',
type => 'DERIVE',
min => '0',
max => '5000',
draw => 'LINE2',
info => 'Number of cache hits',
stat_group => 'misc',
stat_name => 'get_hits'
},
memcache_cache_misses => {
label => 'Cache misses',
type => 'DERIVE',
min => '0',
max => '5000',
draw => 'LINE2',
info => 'Number of cache misses',
stat_group => 'misc',
stat_name => 'get_misses'
},
memcache_cmd_get => {
label => 'GET requests',
type => 'DERIVE',
min => '0',
max => '5000',
draw => 'LINE2',
info => 'Number of GET commands seen',
stat_group => 'misc',
stat_name => 'cmd_get'
},
memcache_cmd_set => {
label => 'SET requests',
type => 'DERIVE',
min => '0',
max => '5000',
draw => 'LINE2',
info => 'Number of SET commands seen',
stat_group => 'misc',
stat_name => 'cmd_set'
},
memcache_total_items => {
label => 'New items*5',
type => 'DERIVE',
min => '0',
max => '5000',
draw => 'LINE2',
info => 'New items*5',
cdef => 'memcache_total_items,5,*',
stat_group => 'misc',
stat_name => 'total_items'
},
memcache_total_connections => {
label => 'New connections*100',
type => 'DERIVE',
min => '0',
max => '5000',
cdef => 'memcache_total_connections,100,*',
draw => 'LINE2',
info => 'New connections*100',
stat_group => 'misc',
stat_name => 'total_connections'
},
},
bytes => {
graph_title => 'Memcached - Network traffic',
master => {
graph_args => '--base 1000',
graph_vlabel => 'bytes in(-)/out(+) per ${graph_period}',
graph_category => 'memcache',
},
memcache_bytes_read => {
label => 'Bytes read',
type => 'COUNTER',
draw => 'LINE2',
info => 'Bytes read from network',
graph => 'no',
stat_group => 'misc',
stat_name => 'bytes_read'
},
memcache_bytes_written => {
label => 'Bytes written',
negative => 'memcache_bytes_read',
type => 'COUNTER',
draw => 'LINE2',
info => 'Bytes written to network',
stat_group => 'misc',
stat_name => 'bytes_written'
},
},
counters => {
graph_title => 'Memcached - Current values',
master => {
graph_args => '--base 1000',
#graph_args => '--base 1000 --loga',
graph_vlabel => 'Totals',
graph_category => 'memcache',
graph_scale => 'no',
},
memcache_curr_items => {
label => 'Current items',
type => 'GAUGE',
min => '0',
draw => 'LINE2',
info => 'Number of items in cache',
stat_group => 'misc',
stat_name => 'curr_items'
},
memcache_curr_connections => {
label => 'Current connections*100',
type => 'GAUGE',
min => '0',
draw => 'LINE2',
cdef => 'memcache_curr_connections,100,*',
info => 'Number of connections*100',
stat_group => 'misc',
stat_name => 'curr_connections'
},
memcache_bytes_allocated => {
label => 'Bytes allocated (KiB)',
type => 'GAUGE',
min => '0',
draw => 'LINE2',
cdef => 'memcache_bytes_allocated,1024,/',
info => 'Bytes allocated (KiB)',
stat_group => 'misc',
stat_name => 'bytes'
},
}
);
$0 =~ /memcached(_([^_]*))?_(.+)*$/;
my $instance = $2;
my $func = $3;
exit 2 unless defined $func;
my %vars = %{$all_vars{$func}};
# STAT rusage_user 3941.052868
# STAT rusage_system 18436.366246
# STAT connection_structures 1112
# STAT bytes 382985002
# STAT limit_maxbytes 536870912
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
my %v = %{$vars{'master'}};
my $graph_title = $vars{'graph_title'};
if (defined($instance)) {
$graph_title .= " - $instance";
}
print "graph_title $graph_title\n";
foreach my $k ( keys %v ) {
print "$k ".$v{$k}."\n"
}
print 'graph_order ';
foreach my $k ( sort(keys %vars) ) {
if($k eq 'master') { next; }
if($k eq 'graph_title') { next; }
print $k." ";
}
print "\n";
foreach my $k ( sort(keys %vars) ) {
if($k eq 'master') { next; }
if($k eq 'graph_title') { next; }
my %v = %{$vars{$k}};
foreach my $k2 (keys %v) {
if($k2 eq 'stat_group' or $k2 eq 'stat_name') { next; }
print "$k.$k2 ".$v{"$k2"}."\n";
}
}
exit 0;
}
my $mc = new Cache::Memcached { 'servers' => [ "$HOST:$PORT" ] };
my $stats = $mc->stats ('misc');
foreach my $k ( sort(keys %vars) ) {
if($k eq 'master') { next; }
if($k eq 'graph_title') { next; }
my %v = %{$vars{$k}};
if($v{type} eq 'COMPUTE') { next; }
my $sg = $v{stat_group};
my $sn = $v{stat_name};
my $value = $stats->{hosts}->{"$HOST:$PORT"}->{$sg}->{$sn};
defined($value) or $value = 'U';
print "$k.value ".$value."\n";
}