2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

asterisk: replace the remaining two Asterisk plugins.

The fourth graph (asterisk_codecs) replaces both asterisk_sipchannels
and asterisk_codecs, as the latter already included the data from the
first. If we want to get more details we could have sub-multigraphs
for a breakdown of the codecs per channel type, but right now it feels
unneeded.
This commit is contained in:
Diego Elio Pettenò 2012-12-30 14:02:17 -08:00
parent 608c1a90ef
commit cd4dd57e24

View File

@ -17,7 +17,10 @@ This plugin will produce multiple graphs showing:
asterisk_voicemail);
- the number of active MeetMe conferences and users connected to them
(replace asterisk_meetme and asterisk_meetmeusers, respectively).
(replace asterisk_meetme and asterisk_meetmeusers, respectively);
- the number of active channels for a given codec, for both SIP and
IAX2 channels (replaces asterisk_sipchannels and asterisk_codecs).
=head1 CONFIGURATION
@ -29,6 +32,8 @@ The following configuration parameters are used by this plugin
env.username - username used for authentication
env.secret - secret used for authentication
env.channels - The channel types to look for
env.codecsx - List of codec IDs (hexadecimal values)
env.codecs - List of codecs names, matching codecsx order
The "username" and "secret" parameters are mandatory, and have no
defaults.
@ -39,6 +44,8 @@ defaults.
env.host 127.0.0.1
env.port 5038
env.channels Zap IAX2 SIP
env.codecsx 0x2 0x4 0x8
env.codecs gsm ulaw alaw
=head2 WILDCARD CONFIGURATION
@ -52,7 +59,7 @@ underscore:
=head1 AUTHOR
Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
Copyright (C) 2005-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
Copyright (C) 2012 Diego Elio Pettenò <flameeyes@flameeyes.eu>
=head1 LICENSE
@ -107,6 +114,8 @@ my $username = $ENV{'username'};
my $secret = $ENV{'secret'};
my @CHANNELS = exists $ENV{'channels'} ? split ' ',$ENV{'channels'} : qw(Zap IAX2 SIP);
my @CODECS = exists $ENV{'codecs'} ? split ' ',$ENV{'codecs'} : qw(gsm ulaw alaw);
my @CODECSX = exists $ENV{'codecsx'} ? split ' ',$ENV{'codecsx'} : qw(0x2 0x4 0x8);
my $line, my $error;
my $socket = new IO::Socket::INET(PeerAddr => $peeraddr,
@ -176,6 +185,29 @@ graph_args --base 1000 -l 0
graph_category asterisk
users.label Connected users
conferences.label Active conferences
END
print <<END;
multigraph asterisk_codecs
graphs_title Asterisk channels per codec
graph_args --base 1000 -l 0
graph_vlabel channels
graph_category asterisk
END
foreach my $codec (@CODECS) {
print <<END;
$codec.draw AREASTACK
$codec.label $codec channels
END
}
print <<END;
other.draw AREASTACK
other.label Other known codecs
unknwon.draw AREASTACK
unknown.label Unknown codec
END
unless ( ($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1 ) {
@ -204,6 +236,16 @@ my $meetme_response = asterisk_command($socket, "meetme list");
#5500 0001 N/A 00:00:03 Static
#* Total number of MeetMe users: 1
my $sipchannels_response = asterisk_command($socket, "sip show channels");
#Peer User/ANR Call ID Seq (Tx/Rx) Format
#192.168.1.135 yann 6902112b3e0 00101/00002 g729
#1 active SIP channel(s)
my $iaxchannels_response = asterisk_command($socket, "iax2 show channels");
#Channel Peer Username ID (Lo/Rem) Seq (Tx/Rx) Lag Jitter JitBuf Format
#IAX2/rodolphe@rodolp 10.8.53.6 rodolphe 00003/01287 00006/00004 00000ms 0148ms 0000ms gsm
#1 active IAX channel(s)
# After all the data is fetched we can proceed to process it, the
# connection can be closed as we don't need any more data.
$socket->close();
@ -259,3 +301,78 @@ END
print "conferences.value " . (scalar(@meetme_list)-1) . "\n";
}
}
print "\nmultigraph asterisk_codecs\n";
if ( !$sipchannels_response and !$iaxchannels_response ) {
foreach my $codec (@CODECS) {
print "$codec.value U\n";
}
print <<END;
other.value U
unknown.valeu U
END
} else {
my @results;
my ($i, $start, $unknown, $other)=(0,0,0,0);
foreach my $codec (@CODECS) {
$results[$i] = 0;
$i++;
}
# split the channels' listing and drop header and footnotes
my @sipchannels = $sipchannels_response ? split(/\r\n/, $sipchannels_response) : ();
pop(@sipchannels); shift(@sipchannels);
my @iaxchannels = $iaxchannels_response ? split(/\r\n/, $iaxchannels_response) : ();
pop(@iaxchannels); shift(@iaxchannels);
foreach my $sipchan (@sipchannels) {
my $found = 0;
my @fields = split ' ', $sipchan;
if ($fields[4] eq '0x0') {
$unknown += 1;
next;
}
foreach my $codec (@CODECSX) {
if ($fields[4] eq "$codec") {
$results[$i] = $results[$i] + 1;
$found = 1;
last;
}
$i++;
}
if (! $found) {
$other += 1;
print STDERR "CODEC: SIP other format $fields[4]\n" if $Munin::Plugin::DEBUG;
}
}
foreach my $iaxchan (@iaxchannels) {
my $found = 0;
my @fields = split ' ', $iaxchan;
if ($fields[8] eq '0x0') {
$unknown += 1;
next;
}
foreach my $codec (@CODECSX) {
if ($fields[8] eq "$codec") {
$results[$i] = $results[$i] + 1;
$found = 1;
last;
}
$i++;
}
if (! $found) {
$other += 1;
print STDERR "CODEC: IAX2 other format: $fields[8]\n" if $Munin::Plugin::DEBUG;
}
}
$i = 0;
foreach my $codec (@CODECS) {
print "$codec.value $results[$i]\n";
$i++;
}
print "other.value $other\n";
print "unknown.value $unknown\n";
}