mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-25 10:28:36 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
56aa139205
63 changed files with 3233 additions and 380 deletions
54
plugins/network/arp_bsd_
Normal file
54
plugins/network/arp_bsd_
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Wildcard-plugin to monitor arp on interfaces. To monitor an
|
||||
# interface, link arp_bsd_<interface> to this file. E.g.
|
||||
#
|
||||
# ln -s /usr/local/share/munin/plugins/arp_bsd_ /usr/local/etc/munin/plugins/arp_bsd_vlanX
|
||||
#
|
||||
# ...will monitor arp on interface vlanX.
|
||||
#
|
||||
# Any device found in /sbin/ifconfig can be monitored.
|
||||
#
|
||||
# Bugs : This plugins has been tested extensively on FreeBSD only
|
||||
#
|
||||
# Author : Luc Duchosal <luc.duchosal (at) arcantel (dot) ch>
|
||||
#
|
||||
# Magic markers (optional - used by munin-config and some installation
|
||||
# scripts):
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
|
||||
INTERFACE=`basename $0 | sed 's/^arp_bsd_//g'`
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -x /sbin/ifconfig ]; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo "no (/sbin/ifconfig not found)"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "suggest" ]; then
|
||||
if [ -x /sbin/ifconfig ]; then
|
||||
/sbin/ifconfig -a | /usr/bin/grep -E '^[a-z]' | /usr/bin/awk -F\: '{print $1;}'
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
echo "graph_title $INTERFACE arp"
|
||||
echo 'graph_args --base 1000'
|
||||
echo 'graph_vlabel arp per ${graph_period}'
|
||||
echo 'graph_category network'
|
||||
echo 'arp.label arp'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
/usr/sbin/arp -an | /usr/bin/grep $INTERFACE | /usr/bin/wc -l | /usr/bin/awk '{ print "arp.value", $1;}'
|
|
@ -1,15 +1,11 @@
|
|||
#! /bin/sh
|
||||
# Currently the plugin does *not* autostart
|
||||
#
|
||||
# It has to be launched via rc.d :
|
||||
# munin-run if1sec_eth0 acquire
|
||||
|
||||
pluginfull="$0" # full name of plugin
|
||||
plugin="${0##*/}" # name of plugin
|
||||
pluginfull="$0" # full name of plugin
|
||||
plugin="${0##*/}" # name of plugin
|
||||
pidfile="$MUNIN_PLUGSTATE/munin.$plugin.pid"
|
||||
cache="$MUNIN_PLUGSTATE/munin.$plugin.value"
|
||||
|
||||
IFACE="${0##*/if1sec_}" # interface
|
||||
IFACE="${0##*/if1sec_}" # interface
|
||||
|
||||
if [ ! -r "/sys/class/net/$IFACE/statistics/tx_bytes" ]
|
||||
then
|
||||
|
@ -19,44 +15,86 @@ fi
|
|||
|
||||
if [ "$1" = "acquire" ]
|
||||
then
|
||||
(
|
||||
while sleep 1
|
||||
do
|
||||
echo $(
|
||||
date +%s
|
||||
cat /sys/class/net/$IFACE/statistics/tx_bytes
|
||||
cat /sys/class/net/$IFACE/statistics/rx_bytes
|
||||
)
|
||||
done | awk "{
|
||||
print \"${IFACE}_tx.value \" \$1 \":\" \$2;
|
||||
print \"${IFACE}_rx.value \" \$1 \":\" \$3;
|
||||
system(\"\");
|
||||
}" >> $cache
|
||||
) &
|
||||
echo $! > $pidfile
|
||||
exit 0
|
||||
(
|
||||
exec <&- >&- 2>&-
|
||||
while sleep 1
|
||||
do
|
||||
read tx < /sys/class/net/$IFACE/statistics/tx_bytes
|
||||
read rx < /sys/class/net/$IFACE/statistics/rx_bytes
|
||||
echo "$tx $rx"
|
||||
done | awk "{
|
||||
now = systime()
|
||||
print \"${IFACE}_tx.value \" now \":\" \$1
|
||||
print \"${IFACE}_rx.value \" now \":\" \$2
|
||||
system(\"\")
|
||||
}" >> $cache
|
||||
) &
|
||||
echo $! > $pidfile
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ "$1" = "config" ]
|
||||
then
|
||||
cat <<EOF
|
||||
cat <<EOF
|
||||
graph_title Interface 1sec stats for ${IFACE}
|
||||
graph_category 1sec::network
|
||||
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y
|
||||
graph_vlabel Bytes
|
||||
graph_category network
|
||||
graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 450d
|
||||
graph_vlabel bits/sec
|
||||
update_rate 1
|
||||
${IFACE}_tx.label ${IFACE} TX bytes
|
||||
${IFACE}_tx.label ${IFACE} TX bits
|
||||
${IFACE}_tx.cdef ${IFACE}_tx,8,*
|
||||
${IFACE}_tx.type DERIVE
|
||||
${IFACE}_tx.min 0
|
||||
${IFACE}_rx.label ${IFACE} RX bytes
|
||||
${IFACE}_rx.label ${IFACE} RX bits
|
||||
${IFACE}_rx.cdef ${IFACE}_rx,8,*
|
||||
${IFACE}_rx.type DERIVE
|
||||
${IFACE}_rx.min 0
|
||||
EOF
|
||||
exit 0
|
||||
# If max speed is easily available, report it. More complex
|
||||
# code could be copied from "if_".
|
||||
if [ -r /sys/class/net/$IFACE/speed ]
|
||||
then
|
||||
SPEED=$(cat /sys/class/net/$IFACE/speed)
|
||||
echo "${IFACE}_rx.max" $((SPEED / 8 * 1000000))
|
||||
echo "${IFACE}_tx.max" $((SPEED / 8 * 1000000))
|
||||
echo "${IFACE}_rx.info Received traffic on the $IFACE interface. Maximum speed is ${SPEED} Mbps."
|
||||
echo "${IFACE}_tx.info Transmitted traffic on the $IFACE interface. Maximum speed ${SPEED} Mbps."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# values
|
||||
# Autorun logic
|
||||
running=true
|
||||
if [ ! -e ${cache} ]
|
||||
then
|
||||
# no cache file
|
||||
running=false
|
||||
elif [ ! -s ${cache} ]
|
||||
then
|
||||
# empty cache file
|
||||
if [ -s ${pidfile} ]
|
||||
then
|
||||
# kill -0 will return success if this user is allowed to send
|
||||
# a signal to the process. This means the PID exists and
|
||||
# belongs to the plugin user, which should have few false
|
||||
# positives.
|
||||
if ! kill -0 $(cat ${pidfile})
|
||||
then
|
||||
running=false
|
||||
fi
|
||||
else
|
||||
running=false
|
||||
fi
|
||||
fi
|
||||
if ! $running
|
||||
then
|
||||
$0 acquire &
|
||||
# wait a little so we have some data to report
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
# Finally: Print collected values, truncate to mark spot.
|
||||
cat ${cache}
|
||||
> ${cache}
|
||||
|
||||
|
|
252
plugins/network/pf_tables_
Normal file
252
plugins/network/pf_tables_
Normal file
|
@ -0,0 +1,252 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
pf_tables : Munin plugin to monitor pf tables.
|
||||
Inout: bandwidth usage for table
|
||||
Addresses: number of entries in table
|
||||
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Should work on any BSD that has pf(4).
|
||||
|
||||
Examples:
|
||||
|
||||
=over
|
||||
|
||||
=item pf_tables_inout_tablename
|
||||
|
||||
=item pf_tables_addresses_authenticated
|
||||
|
||||
=item pf_tables_addresses_badboys
|
||||
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
[pf_tables_*]
|
||||
user root
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin simply runs the pfctl -sTables -vvv command and counts the number of
|
||||
Addresses and InBytes/OutBytes in each table.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
Only tested extensively on FreeBSD.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
$Id$
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Copyright (C) 2015.
|
||||
|
||||
Original version by Luc Duchosal (at) arcantel (dot) ch.
|
||||
Created by Luc Duchosal, 2015
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
BSD
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
use strict;
|
||||
use Munin::Plugin;
|
||||
|
||||
$0 =~ /pf_tables_(addresses|inout)_(.+)$/;
|
||||
my $name = $2;
|
||||
my $operation = $1;
|
||||
|
||||
if ( defined($ARGV[0])) {
|
||||
if ($ARGV[0] eq 'autoconf') {
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($ARGV[0] eq "config") {
|
||||
|
||||
if (!defined($name)) {
|
||||
print "Unknown table\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if (!defined($operation)) {
|
||||
print "Unknown operation\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($operation =~ m/addresses/) {
|
||||
|
||||
print "graph_title Connected users ($name)\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel Users\n";
|
||||
print "graph_scale no\n";
|
||||
print "graph_category pf\n";
|
||||
print "graph_printf %3.0lf\n";
|
||||
|
||||
print "users.label users\n";
|
||||
print "users.draw AREASTACK\n";
|
||||
print "users.colour 00C000\n";
|
||||
foreach my $field (qw(users)) {
|
||||
print_thresholds($field);
|
||||
}
|
||||
}
|
||||
|
||||
if ($operation =~ m/inout/) {
|
||||
|
||||
print "graph_title Network bandwidth ($name)\n";
|
||||
print "graph_args --base 1024 -l 0\n";
|
||||
print "graph_vlabel Bandwidth\n";
|
||||
print "graph_scale yes\n";
|
||||
print "graph_category pf\n";
|
||||
# print "graph_printf %3.0lf\n";
|
||||
|
||||
print "in.label in\n";
|
||||
print "in.type DERIVE\n";
|
||||
print "in.draw AREASTACK\n";
|
||||
print "in.colour C00000\n";
|
||||
print "in.cdef in,8,*\n";
|
||||
print "in.min 0\n";
|
||||
print "in.graph no\n";
|
||||
print "out.label out\n";
|
||||
print "out.type DERIVE\n";
|
||||
print "out.negative in\n";
|
||||
print "out.draw AREASTACK\n";
|
||||
print "out.colour 0000C0\n";
|
||||
print "out.cdef out,8,*\n";
|
||||
print "out.min 0\n";
|
||||
print "out.graph no\n";
|
||||
|
||||
foreach my $field (qw(in out)) {
|
||||
print_thresholds($field);
|
||||
}
|
||||
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($ARGV[0] eq "suggest") {
|
||||
my %tables = &tables();
|
||||
foreach my $key (keys(%tables)) {
|
||||
print "addresses_$key\n";
|
||||
print "inout_$key\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!defined($name)) {
|
||||
print "Usage: pf_tables_addresses_tablename or pf_tables_inout_tablename\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
my %tables = &tables();
|
||||
if (!exists $tables{$name}) {
|
||||
print "Unknown table name $name\n";
|
||||
exit 2;
|
||||
}
|
||||
|
||||
if ($operation =~ m/addresses/) {
|
||||
my $users = $tables{$name}->{"addresses"};
|
||||
print "users.value $users\n";
|
||||
}
|
||||
|
||||
if ($operation =~ m/inout/) {
|
||||
my $in = $tables{$name}->{"inpassbytes"};
|
||||
my $out = $tables{$name}->{"outpassbytes"};
|
||||
print "in.value $in\n";
|
||||
print "out.value $out\n";
|
||||
}
|
||||
|
||||
|
||||
sub tables {
|
||||
|
||||
# # pfctl -s Tables -vv
|
||||
# -pa-r-- auth
|
||||
# Addresses: 0
|
||||
# Cleared: Fri Sep 18 17:34:42 2015
|
||||
# References: [ Anchors: 0 Rules: 14 ]
|
||||
# Evaluations: [ NoMatch: 43624 Match: 788 ]
|
||||
# In/Block: [ Packets: 0 Bytes: 0 ]
|
||||
# In/Pass: [ Packets: 30908 Bytes: 2704516 ]
|
||||
# In/XPass: [ Packets: 124 Bytes: 7897 ]
|
||||
# Out/Block: [ Packets: 0 Bytes: 0 ]
|
||||
# Out/Pass: [ Packets: 30288 Bytes: 26313114 ]
|
||||
# Out/XPass: [ Packets: 89 Bytes: 21166 ]
|
||||
|
||||
my $output = `/sbin/pfctl -s Tables -vv 2> /dev/null`;
|
||||
my %tables;
|
||||
my $name;
|
||||
|
||||
foreach (split(/\n/, $output)) {
|
||||
|
||||
if (m|^[cpairhC\-]{7}\s+(\w+)$|) {
|
||||
$name = $1;
|
||||
$tables{$name}->{"name"} = $1;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|Addresses:\s+([0-9]+)$|) {
|
||||
$tables{$name}->{"addresses"} = $1;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|Cleared:\s+(.+)$|) {
|
||||
$tables{$name}->{"cleared"} = $1;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|In/Block:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"inblockpackets"} = $1;
|
||||
$tables{$name}->{"inblockbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|In/Pass:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"inpasspackets"} = $1;
|
||||
$tables{$name}->{"inpassbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|In/XPass:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"inxpasspackets"} = $1;
|
||||
$tables{$name}->{"inxpassbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|Out/Block:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"outblockpackets"} = $1;
|
||||
$tables{$name}->{"outblockbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|Out/Pass:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"outpasspackets"} = $1;
|
||||
$tables{$name}->{"outpassbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
if (m|Out/XPass:\s+\[\s+Packets:\s+([0-9]+)\s+Bytes:\s+([0-9]+)\s+\]$|) {
|
||||
$tables{$name}->{"outxpasspackets"} = $1;
|
||||
$tables{$name}->{"outxpassbytes"} = $2;
|
||||
next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return %tables;
|
||||
|
||||
}
|
||||
|
||||
# vim:syntax=perl
|
|
@ -1,155 +1,140 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
Plugin: radio
|
||||
Author: Philipp Giebel (spam@stimpyrama.org)
|
||||
Version: 0.1
|
||||
|
||||
Munin (http://munin.projects.linpro.no/) Plugin for counting
|
||||
listeners to both shout- and icecast streams.
|
||||
|
||||
Requirements: * PHP (jap, I know that sucks.. ;) )
|
||||
Plugin: radio
|
||||
Author: Philipp Giebel (spam@stimpyrama.org)
|
||||
Version: 0.2
|
||||
Munin (http://munin-monitoring.org/) Plugin for counting
|
||||
listeners to both shout- and icecast streams.
|
||||
Get the latest version at:
|
||||
http://munin-monitoring.org/log/munin-contrib/plugins/network/radio
|
||||
Requirements: * PHP (jap, I know that sucks.. ;) )
|
||||
CHANGELOG
|
||||
v0.1 - Quick & Dirty proof of concept
|
||||
v0.2 - Updated to match output of current versions of ice- and shoutcast.
|
||||
*/
|
||||
|
||||
// -------------- CONFIGURATION START ---------------------------------------------------------------
|
||||
|
||||
$cfg = array(
|
||||
// SERVER #1
|
||||
array( "type" => "ice", // server-type (ice/shout)
|
||||
"host" => "192.168.1.5", // server hostname or ip
|
||||
"port" => 8000, // server port
|
||||
"mountpoint" => "eclectix.mp3", // mountpoint to check (icecast only)
|
||||
"name" => "IceCast" // name for use in munin graphs
|
||||
),
|
||||
// SERVER #2
|
||||
array( "type" => "shout", // server-type
|
||||
"host" => "radio.eclectix.de", // server hostname or ip
|
||||
"port" => 8000, // server port
|
||||
"name" => "ShoutCast" // name for use in munin graphs
|
||||
)
|
||||
);
|
||||
|
||||
// -------------- CONFIGURATION END ----------------------------------------------------------------
|
||||
|
||||
function getIce( $host, $port, $mount, $name ) {
|
||||
$error = false;
|
||||
$fp = fsockopen( $host, $port, $errno, $errstr, 10 );
|
||||
if ( !$fp ) {
|
||||
$error = $errstr ."(". $errno .")";
|
||||
} else {
|
||||
fputs( $fp, "GET /status HTTP/1.1\r\n" );
|
||||
fputs( $fp, "Host: ". $host ."\r\n" );
|
||||
fputs($fp, "User-Agent: Mozilla\r\n");
|
||||
fputs( $fp, "Connection: close\r\n\r\n" );
|
||||
|
||||
$xml = "";
|
||||
|
||||
while ( !feof( $fp ) ) {
|
||||
$xml .= fgets( $fp, 512 );
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
|
||||
if ( stristr( $xml, "HTTP/1.0 200 OK" ) == true ) {
|
||||
$xml = trim( substr( $xml, 42 ) );
|
||||
} else {
|
||||
$error = "Bad login";
|
||||
}
|
||||
if ( !$error ) {
|
||||
$res = array( "found" => true );
|
||||
|
||||
$mount = str_replace( ".", "\.", $mount );
|
||||
preg_match_all( "/Mount Point : \(\/(". $mount .")\).*?\<tr\>\<td\>Current Listeners:\<\/td\>\<td class=\"streamdata\"\>(\d*?)\<\/td\>\<\/tr\><tr>\<td\>Peak Listeners:\<\/td\>\<td class=\"streamdata\"\>(\d*?)\<\/td\>\<\/tr\>/s", $xml, $parser );
|
||||
|
||||
$res["mount"] = $parser[1][0];
|
||||
$res["listeners"] = $parser[2][0];
|
||||
$res["listeners_peak"] = $parser[3][0];
|
||||
$res["name"] = $name;
|
||||
} else {
|
||||
$res = $error;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getShout( $host, $port, $name ) {
|
||||
$error = false;
|
||||
$fp = fsockopen( $host, $port, $errno, $errstr, 10 );
|
||||
if ( !$fp ) {
|
||||
$error = $errstr ."(". $errno .")";
|
||||
} else {
|
||||
fputs( $fp, "GET / HTTP/1.0\r\n" );
|
||||
fputs($fp, "User-Agent: Mozilla\r\n");
|
||||
fputs( $fp, "Connection: close\r\n\r\n" );
|
||||
|
||||
$xml = "";
|
||||
|
||||
while ( !feof( $fp ) ) {
|
||||
$xml .= fgets($fp, 512);
|
||||
}
|
||||
fclose( $fp );
|
||||
|
||||
if ( stristr( $xml, "HTTP/1.0 200 OK" ) == true ) {
|
||||
$xml = trim( substr( $xml, 42 ) );
|
||||
} else {
|
||||
$error = "Bad login";
|
||||
}
|
||||
if ( !$error ) {
|
||||
$res = array( "found" => true );
|
||||
|
||||
preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td\>\<font class=default\>\<b\>Stream is up at \d*? kbps with \<B\>(\d*?) of \d*? listeners \(\d*? unique\)\<\/b\>\<\/b\>/s", $xml, $parser );
|
||||
|
||||
$res["listeners"] = $parser[1][0];
|
||||
$res["name"] = $name;
|
||||
|
||||
} else {
|
||||
$res = $error;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
// -------------- CONFIGURATION START ---------------------------------------
|
||||
$cfg = array(
|
||||
// SERVER #1
|
||||
array( "name" => "IceCast", // name for munin
|
||||
"type" => "ice", // server-type (ice/shout)
|
||||
"host" => "ice.example.com", // server hostname or ip
|
||||
"port" => 8000, // server port
|
||||
"mountpoint" => "live" // mountpoint to check
|
||||
// (icecast only)
|
||||
),
|
||||
// SERVER #2
|
||||
array( "name" => "ShoutCast", // name for munin
|
||||
"type" => "shout", // server-type
|
||||
"host" => "127.0.0.1", // server hostname or ip
|
||||
"port" => 8000 // server port
|
||||
)
|
||||
);
|
||||
// -------------- CONFIGURATION END -----------------------------------------
|
||||
error_reporting(E_ERROR);
|
||||
function getIce( $host, $port, $mount, $name ) {
|
||||
$error = false;
|
||||
if ( !$fp = fsockopen( $host, $port, $errno, $errstr, 10 ) ) {
|
||||
$error = $errstr ."(". $errno .")";
|
||||
} else {
|
||||
fputs( $fp, "GET /status.xsl HTTP/1.1\r\n" );
|
||||
fputs( $fp, "Host: ". $host ."\r\n" );
|
||||
fputs( $fp, "User-Agent: Mozilla\r\n" );
|
||||
fputs( $fp, "Connection: close\r\n\r\n" );
|
||||
$xml = "";
|
||||
while ( !feof( $fp ) ) {
|
||||
$xml .= fgets( $fp, 512 );
|
||||
}
|
||||
fclose( $fp );
|
||||
if ( stristr( $xml, "HTTP/1.0 200 OK" ) == true ) {
|
||||
$xml = trim( substr( $xml, 42 ) );
|
||||
} else {
|
||||
$error = "Bad login";
|
||||
}
|
||||
if ( !$error ) {
|
||||
$res = array( "found" => true );
|
||||
$mount = str_replace( ".", "\.", $mount );
|
||||
preg_match_all( "/Mount Point \/(". $mount .").*?\<tr\>\<td\>Current Listeners:\<\/td\>\<td class=\"streamdata\"\>(\d*?)\<\/td\>\<\/tr\><tr>\<td\>Peak Listeners:\<\/td\>\<td class=\"streamdata\"\>(\d*?)\<\/td\>\<\/tr\>/s", $xml, $parser );
|
||||
$res["mount"] = $parser[1][0];
|
||||
$res["listeners"] = intval( $parser[2][0] );
|
||||
$res["listeners_peak"] = intval( $parser[3][0] );
|
||||
$res["name"] = $name;
|
||||
} else {
|
||||
$res = $error;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
function getShout( $host, $port, $name ) {
|
||||
$error = false;
|
||||
if ( !$fp = fsockopen( $host, $port, $errno, $errstr, 10 ) ) {
|
||||
$error = $errstr ."(". $errno .")";
|
||||
} else {
|
||||
fputs( $fp, "GET /index.html?sid=1 HTTP/1.0\r\n" );
|
||||
fputs( $fp, "User-Agent: Mozilla\r\n" );
|
||||
fputs( $fp, "Connection: close\r\n\r\n" );
|
||||
$xml = "";
|
||||
while ( !feof( $fp ) ) {
|
||||
$xml .= fgets( $fp, 512 );
|
||||
}
|
||||
fclose( $fp );
|
||||
if ( stristr( $xml, "HTTP/1.1 200 OK" ) == true ) {
|
||||
$xml = trim( substr( $xml, 42 ) );
|
||||
} else {
|
||||
$error = "Bad login";
|
||||
}
|
||||
if ( !$error ) {
|
||||
$res = array( "found" => true );
|
||||
preg_match_all( "/.*?Stream Status: <\/td\>\<td\><b\>Stream is up at \d*? kbps with (\d*?) of \d*? listeners/s", $xml, $parser );
|
||||
$res["listeners"] = intval( $parser[1][0] );
|
||||
$res["name"] = $name;
|
||||
} else {
|
||||
$res = $error;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
if ( !isset( $argv[1] ) ) $argv[1] = '';
|
||||
switch( $argv[1] ) {
|
||||
case "config":
|
||||
echo "graph_title Stream Listeners\n";
|
||||
echo "graph_category Network\n";
|
||||
echo "graph_vlabel listeners\n";
|
||||
echo "graph_hlabel listeners\n";
|
||||
echo "graph_args --base 1000 -l 0\n";
|
||||
echo "graph_scale no\n";
|
||||
echo "graph_info Number of listeners to shout- and / or icecast streams\n";
|
||||
echo "complete.info Complete listeners\n";
|
||||
echo "complete.label complete\n";
|
||||
echo "graph_order";
|
||||
foreach ( $cfg as $c ) {
|
||||
echo " ". strtolower( $c["name"] );
|
||||
}
|
||||
echo " complete\n";
|
||||
foreach ( $cfg as $c ) {
|
||||
echo strtolower( $c["name"] ) .".info ". $c["name"] ." listeners\n";
|
||||
echo strtolower( $c["name"] ) .".label ". strtolower( $c["name"] ) ."\n";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$complete = 0;
|
||||
foreach ( $cfg as $c ) {
|
||||
switch ( $c["type"] ) {
|
||||
case "ice":
|
||||
$res = getIce( $c["host"], $c["port"], $c["mountpoint"], $c["name"] );
|
||||
break;
|
||||
case "shout":
|
||||
$res = getShout( $c["host"], $c["port"], $c["name"] );
|
||||
break;
|
||||
}
|
||||
|
||||
switch( $argv[1] ) {
|
||||
case "config":
|
||||
echo "graph_title Stream Listeners\n";
|
||||
echo "graph_category Network\n";
|
||||
echo "graph_vlabel listeners\n";
|
||||
echo "graph_hlabel listeners\n";
|
||||
echo "graph_args --base 1000 -l 0\n";
|
||||
echo "graph_scale no\n";
|
||||
echo "graph_order";
|
||||
foreach ( $cfg as $c ) {
|
||||
echo " ". strtolower( $c["name"] );
|
||||
}
|
||||
echo " complete\n";
|
||||
// echo "\n";
|
||||
echo "graph_info Number of listeners to shout- and / or icecast streams\n";
|
||||
foreach ( $cfg as $c ) {
|
||||
echo strtolower( $c["name"] ) .".info ". $c["name"] ." listeners\n";
|
||||
echo strtolower( $c["name"] ) .".label ". strtolower( $c["name"] ) ."\n";
|
||||
}
|
||||
echo "complete.info Complete listeners\n";
|
||||
echo "complete.label complete\n";
|
||||
break;
|
||||
default:
|
||||
$complete = 0;
|
||||
|
||||
foreach ( $cfg as $c ) {
|
||||
switch ( $c["type"] ) {
|
||||
case "ice":
|
||||
$res = getIce( $c["host"], $c["port"], $c["mountpoint"], $c["name"] );
|
||||
$complete += $res["listeners"];
|
||||
break;
|
||||
case "shout":
|
||||
$res = getShout( $c["host"], $c["port"], $c["name"] );
|
||||
$complete += $res["listeners"];
|
||||
break;
|
||||
}
|
||||
echo strtolower($c["name"]) .".value ". $res["listeners"] ."\n";
|
||||
}
|
||||
|
||||
echo "complete.value ". $complete ."\n";
|
||||
break;
|
||||
}
|
||||
if ( is_array( $res ) ) {
|
||||
echo strtolower($c["name"]) .".value ". $res["listeners"] ."\n";
|
||||
$complete += $res["listeners"];
|
||||
} else {
|
||||
echo strtolower($c["name"]) .".value 0\n";
|
||||
}
|
||||
}
|
||||
echo "complete.value ". $complete ."\n";
|
||||
break;
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue