root / plugins / other / morenin @ 7da1b039
Historique | Voir | Annoter | Télécharger (3,71 ko)
| 1 |
#!/usr/bin/perl |
|---|---|
| 2 |
# |
| 3 |
# Script by Simon Avery ( http://digdilem.org / digdilem@gmail.com ) to query munin.conf and collate various types of graphs on the same page from different machines. |
| 4 |
# Eg - show all the load daily graphs for all your machines on one page. Review ALL your machines' disk space, memory, cpu, loads for the past day, week, month or year - one click! |
| 5 |
# Reason: Makes it easier (for me!) to review a lot of machines (I have 28) for unusual patterns. |
| 6 |
# |
| 7 |
# Options - supply on the url: |
| 8 |
# period=day / week (default: day) |
| 9 |
# type = df / whatever (default:df) - which reporting type to use. |
| 10 |
# scale=pixel (How many pixels wide to scale the graphs, override default with $cellwidth below |
| 11 |
# |
| 12 |
# Installation: |
| 13 |
# 1. Copy this script to a webfolder of your choice, ensuring CGI is allowed there. |
| 14 |
# 2. Edit the four variables below to suit your configuration. |
| 15 |
# 3. Visit the script in your web browser. |
| 16 |
# |
| 17 |
# History: |
| 18 |
# v.1 - 30 August, 2010: Initial release. |
| 19 |
|
| 20 |
my $htmldir = '/internal/munin'; # What's the web address for munin's html dir? (Hint - where you normally go to see munin's overview) |
| 21 |
my $cfgfile = '/etc/munin/munin.conf'; # Where's the config file - must be readable |
| 22 |
my $numwide=5; # How many graphs to go wide per row? |
| 23 |
my $default_cellwidth=350; # How many pixels wide for the graphs? (Default) |
| 24 |
|
| 25 |
use CGI qw/:standard/; |
| 26 |
my $q = CGI->new; |
| 27 |
print $q->header() , $q->start_html('Morenin - Multiple server graphing tool');
|
| 28 |
|
| 29 |
my $type = param("type") || 'df'; # Default type
|
| 30 |
my $period = param("period") || 'day'; # Default period
|
| 31 |
my $cellwidth = param("scale") || $default_cellwidth; # Default image scale
|
| 32 |
|
| 33 |
my @list; # list of names |
| 34 |
my $imgdir; # find from munin's conf |
| 35 |
|
| 36 |
open(CFG,"<$cfgfile") or die("Can't open munin config file: $cfgfile - $!\n");
|
| 37 |
while(<CFG>) {
|
| 38 |
my $tidy = trim($_); |
| 39 |
if ($tidy =~ /htmldir/i) { # Guess where the images are, so I can test whether to try and display them or not.
|
| 40 |
$tidy =~ s/\t/ /g; |
| 41 |
($junk,$imgdir) = split(/ /,$tidy); |
| 42 |
} |
| 43 |
# search for identifier, Not very elegant, doesn't account for horribly done config files. |
| 44 |
if ($tidy =~ m/^\[(.*)\]/) {
|
| 45 |
push(@list,$1); |
| 46 |
} |
| 47 |
} |
| 48 |
close(CFG); |
| 49 |
sort(@list); # Sort it alpha-numerically |
| 50 |
|
| 51 |
print "Morenin - graphing ".scalar(@list)." <a href=\"$htmldir\">Munin</a> graphs for type $type, period <b>$period</b>:\n"; |
| 52 |
# Some default links - add more here if you want 'em |
| 53 |
print qq~ |
| 54 |
<a href="?type=$type&period=day">Daily</a> :: |
| 55 |
<a href="?type=$type&period=week">Weekly</a> :: |
| 56 |
<a href="?type=$type&period=month">Monthly</a> :: |
| 57 |
<a href="?type=$type&period=year">Yearly</a> ...::... |
| 58 |
|
| 59 |
<a href="?period=$period&type=load">Load</a> :: |
| 60 |
<a href="?period=$period&type=cpu">CPU</a> :: |
| 61 |
<a href="?period=$period&type=df">DiskUse</a> :: |
| 62 |
<a href="?period=$period&type=memory">Memory</a> :: |
| 63 |
<a href="?period=$period&type=mysql_queries">MySql</a> |
| 64 |
~; |
| 65 |
|
| 66 |
if (! defined $htmldir) { print "<br>Error: Can't find htmldir from config, this isn't going to work..."; }
|
| 67 |
|
| 68 |
# Now output the frames and links |
| 69 |
my $widcnt=1; # Temp counter |
| 70 |
print "<hr><table border=\"1\"><tr>\n"; |
| 71 |
|
| 72 |
foreach $i (@list[1..$#list]) # Step through each entry |
| 73 |
{
|
| 74 |
next if (! -e "$imgdir/$i/$i-$type-$period.png"); # First check an image is there and not a null entry; |
| 75 |
|
| 76 |
print "<td valign=\"top\">$i<br>"; |
| 77 |
print "<a href=\"$htmldir/$i/$i-$type.html\" title=\"Click to visit server's $type page\">\n"; |
| 78 |
print "<img src=\"$htmldir/$i/$i-$type-$period.png\" alt=\"$i-$type-$period.png\" width=\"$cellwidth\">"; |
| 79 |
print "</a>\n"; |
| 80 |
print "</td>\n"; |
| 81 |
|
| 82 |
if ($widcnt++ >= $numwide) { print "</tr><tr>\n"; $widcnt=1; } # wrap the cells
|
| 83 |
} |
| 84 |
|
| 85 |
print "</tr></table>\n"; |
| 86 |
|
| 87 |
$q->end_html; |
| 88 |
|
| 89 |
sub trim($) |
| 90 |
{
|
| 91 |
my $string = shift; |
| 92 |
$string =~ s/^\s+//; |
| 93 |
$string =~ s/\s+$//; |
| 94 |
return $string; |
| 95 |
} |
