#!/usr/bin/perl -w # # Copyright (C) 2006 Rodolphe Quiedeville # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 dated June, # 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # If you improve this script please send your version to my email address # with the copyright notice upgrade with your name. # # Wildcard-plugin to monitor the ccache stats. To monitor an # user cache, link ccache_ to this file. E.g. # # ln -s /usr/share/munin/plugins/ccache_ /etc/munin/plugins/ccache_loic # # ...will monitor loic ccache stats. # # $Log$ # Revision 1.2 2006/04/28 rodo # Bugfix # # Revision 1.1 2006/04/27 rodo # More stats # # Revision 1.0 2006/04/26 rodo # Created by Rodolphe Quiedeville # # Configurable variables # # ccache - Override default ccache command # ccache_dir - Override default cache dir # # Magic markers (optinal - used by munin-config and some installation # scripts): # #%# family=compilation #%# capabilities=autoconf use strict; $0 =~ /ccache_size_(.+)*$/; my $user = $1; exit 2 unless defined $user; $ENV{CCACHE_DIR} = exists $ENV{'ccache_dir'} ? $ENV{'ccache_dir'} : "/home/$user/.ccache"; my $CCACHE = exists $ENV{'ccache'} ? $ENV{'ccache'} : "/usr/bin/ccache"; my $cache = "$CCACHE -s"; (-d $ENV{CCACHE_DIR}) || die "Can't open $ENV{CCACHE_DIR}\n"; (-x $CCACHE) || die "Can't exec $CCACHE\n"; # cache directory /home/rodo/.ccache # cache size 20 Kbytes # max cache size 1024 Kbytes my %WANTED = ( "cache size" => "size", "max cache size" => "max" ); my %DATAS = ( "cache size" => 0, "max cache size" => 0 ); my %MULTIS= ( "K" => 1024, "M" => 1048576, "G" => 1073741824); open(CCH, "$cache|") or exit 4; while () { my ($k, $v, $multi) = (/([\w|\s]+\w)\s+(\d+\.?\d*)\s([K|M|G])bytes$/); next unless ($k); $DATAS{$k} = $v * $MULTIS{$multi} if (exists $WANTED{$k}); } close(CCH); my $size_warn = int($DATAS{"max cache size"} * 0.9); my $size_crit = int($DATAS{"max cache size"} * 0.95); if ($ARGV[0] and $ARGV[0] eq "config" ){ print "graph_title ccache size for $user\n"; print "graph_args --base 1024 -l 0\n"; print "graph_scale yes\n"; print "graph_vlabel bytes\n"; print "graph_category compilation\n"; print "graph_order size max\n"; print 'graph_info Plugin available at http://rodolphe.quiedeville.org/hack/munin/'."\n"; print "max.label max cache size\n"; print "size.label cache size\n"; print "size.draw AREA\n"; print "size.warning $size_warn\n"; print "size.critical $size_crit\n"; exit 0; } open(CCH, "$cache|") or exit 4; while () { my ($k, $v, $multi) = (/([\w|\s]+\w)\s+(\d+\.?\d*)\s([K|M|G])bytes$/); next unless ($k); print("$WANTED{$k}.value ".($v*$MULTIS{$multi})."\n") if (exists $WANTED{$k}); } close(CCH);