From d254343aa68ccec6aa1419d1da1260ab7794ef5c Mon Sep 17 00:00:00 2001 From: Nicolas BOUTHORS Date: Fri, 19 Aug 2011 14:04:17 +0200 Subject: [PATCH] Initial version --- plugins/other/memcached_bytes_all | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 plugins/other/memcached_bytes_all diff --git a/plugins/other/memcached_bytes_all b/plugins/other/memcached_bytes_all new file mode 100755 index 00000000..72a5d679 --- /dev/null +++ b/plugins/other/memcached_bytes_all @@ -0,0 +1,76 @@ +#!/usr/bin/env perl +# ex:ts=4 +# Copyright © Nicolas BOUTHORS / Smile +# +# Licence GPLv2 +# +# Based on a script distributed on munin-exchange. + +use strict; +use warnings; + +use Cache::Memcached; + +my %instances = (); + +# Will look into /etc for memcached config files and extract TCP listening port +# from the config file. +sub fetch_instances() { + my @files = glob("/etc/memcached_*.conf"); + undef $/; + for my $f (@files) { + $f =~ m/.*memcached_(.*)\.conf/; + my $instance_name = $1; + + open(CONF, $f); + my $confdata = ; + close(CONF); + + if ($confdata =~ m/-p ([0-9]+)/m) { + $instances{$instance_name}{'port'} = $1; + } + } +} + +fetch_instances(); + +my $cmd = shift || ''; + +if ($cmd eq 'config') { + print "graph_title Memcached bytes used for all instances\n"; + print "graph_args --base 1024 -l 0\n"; + print "graph_vlabel bytes\n"; + print "graph_category memcached\n"; + print "graph_info This graph monitors the size of the memcached cache for every instance.\n"; + + foreach my $instance_name (keys(%instances)) { + my $pretty_name = $instance_name; + $pretty_name =~ s/[^a-zA-Z0-9]/_/g; + + print "${pretty_name}_bytes.label $instance_name used\n"; + print "${pretty_name}_bytes.info Number of bytes currently used\n"; + print "${pretty_name}_bytes.min 0\n"; + print "${pretty_name}_bytes.draw LINE2\n"; + print "${pretty_name}_maxbytes.label $instance_name maximum\n"; + print "${pretty_name}_maxbytes.info The configured cache size\n"; + print "${pretty_name}_maxbytes.min 0\n"; + } + + exit 0; +} + +foreach my $instance_name (keys(%instances)) { + my $ip = "127.0.0.1"; + my $port = $instances{$instance_name}{'port'}; + my $pretty_name = $instance_name; + $pretty_name =~ s/[^a-zA-Z0-9]/_/g; + + my $address = "$ip:$port"; + + my $memd = new Cache::Memcached { 'servers' => [$address] }; + my $memstats = $memd->stats(['misc']); + + print "${pretty_name}_bytes.value " . $memstats->{hosts}->{$address}->{misc}->{bytes} . "\n"; + print "${pretty_name}_maxbytes.value " . + $memstats->{hosts}->{$address}->{misc}->{limit_maxbytes} . "\n"; +}