"Fossies" - the Fresh Open Source Software Archive

Member "munin-2.0.67/plugins/node.d/memcached_.in" (22 Feb 2021, 6103 Bytes) of package /linux/misc/munin-2.0.67.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "memcached_.in": 2.0.66_vs_2.0.67.

    1 #!@@PERL@@
    2 # -*- cperl -*-
    3 #
    4 # Plugin to monitor memcache statistics
    5 #
    6 # This module has 3 seperate graph datasets:
    7 # rates
    8 # bytes
    9 # counters
   10 #
   11 # For each of them, symlink the memcached_ script to memcached_FOO where foo is
   12 # the datset name.
   13 #
   14 # Parameters supported:
   15 #
   16 #  config
   17 #  autoconf
   18 #  suggest
   19 #
   20 # Configurable variables
   21 #
   22 # host  Host of the memcache daemon
   23 # port  Port of the memcache daemon
   24 #
   25 # Author: Robin H. Johnson <robbat2@gentoo.org>
   26 # Slightly based on the original version by Joshua Thijssen
   27 # <jthijssen@noxlogic.nl>
   28 #
   29 # Magic markers:
   30 #%# family=contrib
   31 #%# capabilities=autoconf
   32 use strict;
   33 my $ret = undef;
   34 if (! eval "require Cache::Memcached;") {
   35 	$ret = "Cache::Memcached not found";
   36 }
   37 my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
   38 my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 11211;
   39 if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) {
   40 	if ($ret) {
   41 		print "no ($ret)\n";
   42 	} else {
   43 		use Net::Ping;
   44 		my $p = Net::Ping->new();
   45 		$p->port_number($PORT);
   46 		if ($p->ping($HOST, 1)) {
   47 			print "yes\n";
   48 			exit 0;
   49 		}
   50 		print "no (cannot connect to $HOST on port $PORT)\n";
   51 	}
   52 	exit 0;
   53 }
   54 
   55 if (exists $ARGV[0] and $ARGV[0] eq "suggest") {
   56 	print "bytes\n";
   57 	print "counters\n";
   58 	print "rates\n";
   59 	exit 0;
   60 }
   61 
   62 if($ret) {
   63 	# refuse to execute "config" or "fetch" due to a missing requirement
   64 	print "memcached_ plugin fails to run: $ret\n";
   65 	exit 1;
   66 }
   67 
   68 # We do everything by this array
   69 my %all_vars = (
   70 		rates => {
   71 			master => {
   72 				graph_title => 'Memcached - Commands',
   73 				graph_args => '--base 1000',
   74 				graph_vlabel => '/${graph_period}',
   75 				graph_category => 'memcache',
   76 			},
   77 			memcache_cache_hits => {
   78 				label => 'Cache hits',
   79 				type => 'DERIVE',
   80 				min => '0',
   81 				max => '5000',
   82 				draw => 'LINE2',
   83 				info => 'Number of cache hits',
   84 				stat_group => 'misc',
   85 				stat_name => 'get_hits'
   86 			},
   87 			memcache_cache_misses  => {
   88 				label => 'Cache misses',
   89 				type => 'DERIVE',
   90 				min => '0',
   91 				max => '5000',
   92 				draw => 'LINE2',
   93 				info => 'Number of cache misses',
   94 				stat_group => 'misc',
   95 				stat_name => 'get_misses'
   96 			},
   97 			memcache_cmd_get => {
   98 				label => 'GET requests',
   99 				type => 'DERIVE',
  100 				min => '0',
  101 				max => '5000',
  102 				draw => 'LINE2',
  103 				info => 'Number of GET commands seen',
  104 				stat_group => 'misc',
  105 				stat_name => 'cmd_get'
  106 			},
  107 			memcache_cmd_set => {
  108 				label => 'SET requests',
  109 				type => 'DERIVE',
  110 				min => '0',
  111 				max => '5000',
  112 				draw => 'LINE2',
  113 				info => 'Number of SET commands seen',
  114 				stat_group => 'misc',
  115 				stat_name => 'cmd_set'
  116 			},
  117 			memcache_total_items => {
  118 				label => 'New items*5',
  119 				type => 'DERIVE',
  120 				min => '0',
  121 				max => '5000',
  122 				draw => 'LINE2',
  123 				info => 'New items*5',
  124 				cdef => 'memcache_total_items,5,*',
  125 				stat_group => 'misc',
  126 				stat_name => 'total_items'
  127 			},
  128 			memcache_total_connections => {
  129 				label => 'New connections*100',
  130 				type => 'DERIVE',
  131 				min => '0',
  132 				max => '5000',
  133 				cdef => 'memcache_total_connections,100,*',
  134 				draw => 'LINE2',
  135 				info => 'New connections*100',
  136 				stat_group => 'misc',
  137 				stat_name => 'total_connections'
  138 			},
  139 		},
  140 		bytes => {
  141 			master => {
  142 				graph_title => 'Memcached - Network traffic',
  143 				graph_args => '--base 1000',
  144 				graph_vlabel => 'bytes in(-)/out(+) per ${graph_period}',
  145 				graph_category => 'memcache',
  146 			},
  147 			memcache_bytes_read => {
  148 				label => 'Bytes read',
  149 				type => 'COUNTER',
  150 				draw => 'LINE2',
  151 				max => '1000000',
  152 				info => 'Bytes read from network',
  153 				graph => 'no',
  154 				stat_group => 'misc',
  155 				stat_name => 'bytes_read'
  156 			},
  157 			memcache_bytes_written => {
  158 				label => 'Bytes written',
  159 				negative => 'memcache_bytes_read',
  160 				type => 'COUNTER',
  161 				max => '1000000',
  162 				draw => 'LINE2',
  163 				info => 'Bytes written to network',
  164 				stat_group => 'misc',
  165 				stat_name => 'bytes_written'
  166 			},
  167 		},
  168 		counters => {
  169 			master => {
  170 				graph_title => 'Memcached - Current values',
  171 				graph_args => '--base 1000',
  172 				#graph_args => '--base 1000 --loga',
  173 				graph_vlabel => 'Totals',
  174 				graph_category => 'memcache',
  175 				graph_scale => 'no',
  176 			},
  177 			memcache_curr_items => {
  178 				label => 'Current items',
  179 				type => 'GAUGE',
  180 				min => '0',
  181 				draw => 'LINE2',
  182 				info => 'Number of items in cache',
  183 				stat_group => 'misc',
  184 				stat_name => 'curr_items'
  185 			},
  186 			memcache_curr_connections => {
  187 				label => 'Current connections*100',
  188 				type => 'GAUGE',
  189 				min => '0',
  190 				draw => 'LINE2',
  191 				cdef => 'memcache_curr_connections,100,*',
  192 				info => 'Number of connections*100',
  193 				stat_group => 'misc',
  194 				stat_name => 'curr_connections'
  195 			},
  196 			memcache_bytes_allocated => {
  197 				label => 'Bytes allocated (KiB)',
  198 				type => 'GAUGE',
  199 				min => '0',
  200 				draw => 'LINE2',
  201 				cdef => 'memcache_bytes_allocated,1024,/',
  202 				info => 'Bytes allocated (KiB)',
  203 				stat_group => 'misc',
  204 				stat_name => 'bytes'
  205 			},
  206 		}
  207 		);
  208 
  209 $0 =~ /memcached_(.+)*$/;
  210 my $func = $1;
  211 exit 2 unless defined $func;
  212 my %vars = %{$all_vars{$func}};
  213 
  214 #	   STAT rusage_user 3941.052868
  215 #	   STAT rusage_system 18436.366246
  216 #	   STAT connection_structures 1112
  217 #	   STAT bytes 382985002
  218 #	   STAT limit_maxbytes 536870912
  219 
  220 if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
  221 	my %v = %{$vars{'master'}};
  222 	foreach my $k ( keys %v ) {
  223 		print "$k ".$v{$k}."\n"
  224 	}
  225 	print 'graph_order ';
  226 	foreach my $k ( sort(keys %vars) ) {
  227 		if($k eq 'master') { next; }
  228 		print $k." ";
  229 	}
  230 	print "\n";
  231 	foreach my $k ( sort(keys %vars) ) {
  232 		if($k eq 'master') { next; }
  233 		my %v = %{$vars{$k}};
  234 		foreach my $k2 (keys %v) {
  235 			if($k2 eq 'stat_group' or $k2 eq 'stat_name') { next; }
  236 			print "$k.$k2 ".$v{"$k2"}."\n";
  237 		}
  238 	}
  239 	exit 0;
  240 }
  241 my $mc = new Cache::Memcached { 'servers' => [ "$HOST:$PORT" ] };
  242 my $stats = $mc->stats ('misc');
  243 
  244 foreach my $k ( sort(keys %vars) ) {
  245 	if($k eq 'master') { next; }
  246 	my %v = %{$vars{$k}};
  247 	if($v{type} eq 'COMPUTE') { next; }
  248 	my $sg = $v{stat_group};
  249 	my $sn = $v{stat_name};
  250 	my $value = $stats->{hosts}->{"$HOST:$PORT"}->{$sg}->{$sn};
  251 	defined($value) or $value = 'U';
  252 	print "$k.value ".$value."\n";
  253 }
  254 # vim:syntax=perl ts=4 sw=4: