#!/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_files_ to this file. E.g. # # ln -s /usr/share/munin/plugins/ccache_files_ /etc/munin/plugins/ccache_files_loic # # ...will monitor loic number of files in ccache. # # $Log$ # Revision 1.0 2006/04/29 14:12:19 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_files_(.+)*$/; 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"; (-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 # files in cache 45 # max files 30 my %WANTED = ( "max files" => "max", "files in cache" => "files", ); my %DATAS = ( "max files" => 0, "files in cache" => 0, ); my $cache = "$CCACHE -s"; open(CCH, "$cache|") or exit 4; while () { my ($k, $v) = (/(.*)\s+(\d+)$/); next unless ($k); $k =~ s/\s+$//; $DATAS{$k} = $v if (exists $WANTED{$k}); } close(CCH); my $files_warn = int($DATAS{"max files"} * 0.9); my $files_crit = int($DATAS{"max files"} * 0.95); if ($ARGV[0] and $ARGV[0] eq "config" ){ print "graph_title ccache files for $user\n"; print "graph_args --base 1000 -l 0\n"; print "graph_scale yes\n"; print "graph_vlabel files\n"; print "graph_category compilation\n"; print "graph_order files max\n"; print 'graph_info Plugin available at http://rodolphe.quiedeville.org/hack/munin/'."\n"; print "max.label max files\n"; print "max.info Unlimited\n" if ($DATAS{'max files'} == 0); print "files.label files in cache\n"; print "files.draw AREA\n"; print "files.warning $files_warn\n" if ($DATAS{'max files'} > 0); print "files.critical $files_crit\n" if ($DATAS{'max files'} > 0); exit 0; } print "max.value ".$DATAS{'max files'}."\n"; print "files.value ".$DATAS{'files in cache'}."\n";