1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#! @@PERL@@
# -*- cperl -*-
#
# Copyright (C) 2010 Steve Schnepp
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use Sys::Hostname;
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;
use Munin::Node::SpoolReader;
use Munin::Node::SpoolWriter;
# Disable buffering
$| = 1;
my $SPOOLDIR = "@@SPOOLDIR@@";
my $hostname;
my $overridehost;
my $spoolfetch;
my $vectorfetch;
my $cleanup;
my $cleanupandexit;
my $verbose;
my $debug;
my $help;
GetOptions(
"spooldir|s=s" => \$SPOOLDIR,
"hostname=s" => \$overridehost,
"cleanup" => \$cleanup,
"cleanupandexit" => \$cleanupandexit,
"spoolfetch" => \$spoolfetch,
"vectorfetch" => \$vectorfetch,
"help|h" => \$help,
"verbose|v" => \$verbose,
"debug" => \$debug,
) or pod2usage(1);
if ($help) {
pod2usage(1);
}
if ($cleanupandexit) {
cleanup();
exit;
}
# Use STDIN/STDOUT, in order to be :
# 1. secure over internet (SSH), munin-node needs only
# to listen on localhost:4949
# 2. very simple to launch
my $spoolreader = Munin::Node::SpoolReader->new(
spooldir => $SPOOLDIR,
);
$hostname = $spoolreader->get_metadata("hostname") || hostname();
$hostname = $overridehost if $overridehost;
chomp($hostname);
die "spooldir [$SPOOLDIR] not found" unless -d $SPOOLDIR;
print "# munin node at $hostname\n";
while (my $line = <>) {
if ($line =~ m/^list/) {
print $spoolreader->list();
} elsif ($line =~ m/^config (\w+)/) {
# XXX - Vector-fetching is disabled for now
print ".\n";
} elsif ($vectorfetch && $line =~ m/^fetch (\w+)/) {
# Fetching all values since last time
# XXX - Vector-fetching is disabled for now
print ".\n";
} elsif ($line =~ m/^spoolfetch (\d+)/) {
my $last_epoch = $1;
$spoolreader->fetch($1, sub { print shift(); });
print ".\n";
} elsif ($spoolfetch && $line =~ m/^cap/) {
print "cap spool\n";
} elsif ($line =~ m/^quit/) {
last;
} else {
print "# Unknown command.\n";
}
}
cleanup() if $cleanup;
exit;
sub cleanup {
my $spoolwriter = Munin::Node::SpoolWriter->new(
spooldir => $SPOOLDIR,
);
$spoolwriter->cleanup();
}
sub cat_file {
my $filename = shift;
return if ! -r $filename;
open(FILE, "$filename");
while(<FILE>) {
# remove line starting with .
next if m/^\./;
print $_;
}
close(FILE);
}
__END__
=head1 NAME
munin-async - A program to replay spooled munin-node calls
=head1 SYNOPSIS
munin-async [options]
Options:
-s --spooldir <spooldir> Directory for spooled data [@@SPOOLDIR@@]
--hostname <hostname> Overrides the hostname [`hostname`]
--cleanup Clean up the spooldir after interactive session completes
--cleanupandexit Clean up the spooldir and exit (non-interactive)
--spoolfetch Enables the "spool" capability [no]
--vectorfetch Enables the "vectorized" fetching capability [no]
Note that without this flag, the "fetch"
command is disabled.
-v --verbose Be verbose
-h --help View this message
|