View previous topic :: View next topic |
Author |
Message |
karlis Guest
|
Posted: Thu Nov 10, 2005 7:40 am Post subject: icecast + mrtg stuff |
|
|
Hey, just wanted to post this in case anyone's looking for it. Using this little perl script with mrtg you can create a graph of your ices listeners.
-------------------------
#!/usr/bin/perl
use strict;
#get the number of listeners on a icecast stream
#(find out total bytes later)
my $staturl = qq~http://www.yourdomain.com:8000/admin/stats~;
my $user = 'admin';
my $pass = 'pass';
my $stream = "saunasessions";
my $uptime = '420 days';
my $listeners = 0;
my $sources = 0;
#get listeners
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $staturl);
$req->authorization_basic($user, $pass);
my $stats = $ua->request($req)->as_string;
$stats =~ /<listeners>(\d+)<\/listeners>/;
$listeners = $1;
$stats =~ /<sources>(\d+)<\/sources>/;
$sources = $1;
if (!$listeners) {$listeners = 0;}
if (!$sources) {$sources = 0;}
#get uptime
use Date::Manip;
my $stuff = `ps --no-headers -C icecast -o pid,fname,lstart --sort lstart`;
my @stuff = split(/\n/,$stuff);
$stuff[0] =~ /icecast\s+(.*?)$/gi;
my $start = ParseDate($1);
my $now = ParseDate("Now");
my $delta = DateCalc($start,$now);
$uptime = Delta_Format($delta,0,"%dh days %hv hours");
print qq~$listeners\n$sources\n$uptime\n$stream\n~;
exit;
-----------------------------
here's the mrtg config I use:
-----------------------------
WorkDir: /home/chocolate/saunasessions/mrtg
WriteExpires: Yes
WithPeak[_]: dwmy
XSize[_]: 600
YSize[_]: 200
Title[^]: Graphs:
Target[saunasessions-listeners]:`/home/chocolate/localbin/bin/listeners.pl`
Options[saunasessions-listeners]: nopercent, integer, gauge
MaxBytes[saunasessions-listeners]: 10
AbsMax[saunasessions-listeners]: 10
Title[saunasessions-listeners]: Saunasessions Listeners
PageTop[saunasessions-listeners]: <H1>Saunasessions Listeners</H1>
YLegend[saunasessions-listeners]: # of connections
ShortLegend[saunasessions-listeners]: L/s
Legend1[saunasessions-listeners]: # of listeners
Legend2[saunasessions-listeners]: # of sources
Legend3[saunasessions-listeners]: Maximal # of listeners
Legend4[saunasessions-listeners]: Maximal # of sources
LegendI[saunasessions-listeners]: # of listeners:
LegendO[saunasessions-listeners]: # of sources:
-----------------------------------
happy icecast graphing! |
|
Back to top |
|
|
Guest
|
Posted: Fri Feb 17, 2006 11:11 pm Post subject: |
|
|
I'm using FreeBSD-5.4 and get some 'ps' errors when I run your script: 'perl /usr/local/etc/mrtg/icecastgraph.pl'
ps: illegal option -- -
usage: ps [-aCcefHhjlmrSTuvwXxZ] [-O fmt | -o fmt] [-G gid[,gid...]]
[-M core] [-N system]
[-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
ps [-L]
0
1
saunasessions |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Thu Apr 20, 2006 6:58 pm Post subject: MRTG |
|
|
hello everybody
i did the next steps for create the mrtg.cfg
i create a directory named mrtg in /httpdocs/
i copy the mrtg config code and change
WorkDir: /my/path/to/mrtg
Target[mrtg]:`/my/path/to/mrtg/listeners.pl`
i create the listeners.pl and paste in the mrtg directory
and paste the perl script.
and change the:
my $staturl = qq~http://www.mydomain.com:porticecast/admin/stats~;
my $pass = 'pass';
my $stream = "anyname";<- i donīt know what i have to put here
Change the permissions 705
Add a cron job to have mrtg run and updated every 5 minutes.
type this command to start mrtg: /usr/bin/mrtg /path/to/vhosts/mydomain/httpdocs/mrtg/mrtg.cfg first i had a few warnings, now i do the same start mrtg command line and donīt have warnings.
but when i try to visit the url http://www.mydomain/mrtg/mrtg.html
allways i received a message that "You do not have permission to access this document." but i change permissions to 777 and have the same message and the file have the 777 permissions and i dont understand because i canīt view all files in /mrtg directory.
if any know how i can fix this problem write a post please |
|
Back to top |
|
|
shalako
Joined: 27 Jul 2006 Posts: 4
|
Posted: Fri Oct 20, 2006 8:47 pm Post subject: |
|
|
I set this up successfully and the graph of listeners over time is cute.
But what I really need is a way to monitor bandwidth usage by mountpoint. We offer mountpoints to our clients and need to know how much traffic each mountpoint is getting, so we can charge them.
Thank you! |
|
Back to top |
|
|
Anonymous Guest
|
Posted: Wed Apr 25, 2007 9:59 pm Post subject: |
|
|
Thanks for the script.
I run two streams, one hi-fi, that stays inside the house, and another, lo-fi that goes outside to the 'net.
As such, I needed to tweak your script to collect listeners from more than one spot. The following did the trick nicely:
Code: |
#!/usr/bin/perl
use strict;
#get the number of listeners on a icecast stream
#(find out total bytes later)
my $staturl = qq~http://www.yourdomain.com:8000/admin/stats~;
my $user = 'admin';
my $pass = 'pass';
my $stream = "saunasessions";
my $uptime = '0 days';
my $listeners = 0;
my $sources = 0;
#get listeners
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $staturl);
$req->authorization_basic($user, $pass);
my $stats = $ua->request($req)->as_string;
while ($stats =~ /<listeners>(\d+)<\/listeners>/g) {
$listeners += int($1);
}
$stats =~ /<sources>(\d+)<\/sources>/;
$sources = $1;
if (!$listeners) {$listeners = 0;}
if (!$sources) {$sources = 0;}
#get uptime
use Date::Manip;
my $stuff = `ps --no-headers -C icecast -o pid,fname,lstart --sort lstart`;
my @stuff = split(/\n/,$stuff);
$stuff[0] =~ /icecast\s+(.*?)$/gi;
my $start = ParseDate($1);
my $now = ParseDate("Now");
my $delta = DateCalc($start,$now);
$uptime = Delta_Format($delta,0,"%dh days %hv hours");
print qq~$listeners\n$sources\n$uptime\n$stream\n~;
exit;
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group subRebel style by ktauber
|