Re: [asterisk-users] Peak number of calls?

2008-01-28 Thread Steven
I use mrtg,

I call this from MRTG: `/usr/local/groundwork/nagios/libexec/asterisk-mrtg.pl 
-1 Zap -2 SIP`

Here is my asterisk-mrtg.pl: (note, I have tweaked this, but I do not know 
where I had gotten my original reference)
---
#!/usr/bin/perl -w

use strict;
use IO::Socket;
use Getopt::Long;
$|=1;

my $host = 172.16.200.5;
my $username = changeduser;
my $password = changespass;

my (
 $version, $response, $message, $line, $chan1, $chan2,
 $verbose, $help, $command,
 $warning, $critical, 
 %warnval, %critval,
 %channels,
 $sock,
 $key,
 $s,
 $i,
);
my $stop = 0;
my $port = 5038;
my $exitcode = 0;
my $cause = ;

sub warning {
 $s = shift;
 $s =~ s/[\r\n]//g;
 print WARNING: $s\n if ($verbose);
 exit(1);
}

sub error {
 $s = shift;
 $s =~ s/[\r\n]//g;
 print ERROR: $s\n if ($verbose);
 exit(2);
}

sub unknown {
 $s = shift;
 $s =~ s/[\r\n]//g;
 print UNKNOWN: $s\n if ($verbose);
 exit(3);
}

sub syntax {
 $s = shift;
 unless ($s =~ m/Help:/) {
  $s = Error: (.$s.) or $s = 'Unknown';
 }
 print $s\n unless ($help);
 print Syntax: $0 -h host -u username -p password [-cwv]\n;
 print * --username -u   Username\n;
 print * --password -p   Password\n;
 print * --host -h   Host\n;
 print   --port -P n Port (if not using $port)\n;
 print   --chan1 -1 xxx  Display channel xxx as 1.\n;
 print   --chan2 -2 xxx  Display channel xxx as 2.\n;
 print   --verbose -vVerbose\n;
 print   --help -H   This help\n;
 exit(3);
}

Getopt::Long::Configure('bundling');
GetOptions
 (p=s= \$password, password=s = \$password,
  u=s= \$username, username=s = \$username,
  h=s= \$host, host=s = \$host,
  P=s= \$port, port=s = \$port,
  H  = \$help, help   = \$help,
  v  = \$verbose,  verbose= \$verbose,
  chan1=s= \$chan1,1=s= \$chan1,
  chan2=s= \$chan2,2=s= \$chan2);

syntax(Help:) if ($help);
syntax(Missing username) unless (defined($username));
syntax(Missing password) unless (defined($password));
syntax(Missing host) unless (defined($host));
syntax(Missing channels) if (!defined($chan1) or !defined($chan2));
if (defined($warning)) {
 foreach $s (split(/,/, $warning)) {
  syntax(Warning value given, $s, is invalid)
   unless ($s =~ /^(\w+)=(\d+)$/);
  $warnval{$1} = $2;
  print Clear to give WARNING after $2 connections on $1\n if ($verbose);
 }
}
if (defined($critical)) {
 foreach $s (split(/,/, $critical)) {
  syntax(Critical value given, $s, is invalid)
   unless ($s =~ /^(\w+)=(\d+)$/);
  $critval{$1} = $2;
  print Clear to give CRITICAL after $2 connections on $1\n if ($verbose);
 }
}

unless ($sock = IO::Socket::INET-new(PeerAddr = $host, PeerPort = $port, 
Proto = 'tcp')) {
 print(Could not connect to asterisk server .$host.:.$port.\n) if 
($verbose);
 exit(2);
}
$version = $sock;
print $version if ($verbose);

print $sock Action: Login\r\nUsername: $username\r\nSecret: 
$password\r\nEvents: off\r\n\r\n;
print Action: Login\r\nUsername: $username\r\nSecret: $password\r\n\r\n if 
($verbose);
$response = $sock;
$message = $sock;
$s = $sock;
print $response.$message if ($verbose);
print $s if ($verbose);

exit(1) unless ($response =~ m/^Response:\s+(.*)$/i);
exit(1) unless ($1 =~ m/Success/i);

print $sock Action: Status\r\n\r\n;
print Action: Status\r\n\r\n if ($verbose);

$response = $sock;
$message = $sock;
print $response.$message if ($verbose);

unknown(Unknown answer $response (wanted Response: something)) unless 
($response =~ m/^Response:\s+(.*)$/i);
unknown($response didn't say Success) unless ($1 =~ m/Success/i);
unknown(Unknown answer $response (wanted Message: something)) unless 
($message =~ m/^Message:\s+(.*)$/i);
unknown(didn't understand message $message) unless ($1 =~ m/Channel status 
will follow/i);

$stop=0;
while (($stop == 0)  ($line = $sock)) {
 print $line if ($verbose);
 if ($line =~ m/Channel:\s+(\w+)\//) {
  $channels{$1}++;
  print Found $1 channel\n if ($verbose);
 }
 if ($line =~ m/Event:\s*StatusComplete/i) {
  $stop++;
 }
}

# Log out
print $sock Action: Logoff\r\n\r\n;

undef($s);

for ($i=0;$i2;$i++) {
 if (defined($channels{$chan1})) {
  print $channels{$chan1} . \n;
 } else {
  print 0\n;
 }
 if (defined($channels{$chan2})) {
  print $channels{$chan2} . \n;
 } else {
  print 0\n;
 }
}

---

my $username should be a user in the asterisk management file.
my $password should be the password for that account.

This gives me this output:
`Daily' Graph (5 Minute Average)




 Max
 Average
 Current
 
  Zap channels
 5 Zap channels in use
 1 Zap channels in use 
 0 Zap channels in use 
 
  SIP channels
 6 SIP channels in use 
 1 SIP channels in use 
 0 SIP channels in use 
 




-- 
-- 
Steven

http://www.connectech.org/



Gordon Henderson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 
 Is there any way to find-out the peak number of calls that an asterisk 
 system has 

Re: [asterisk-users] Peak number of calls?

2008-01-28 Thread Gordon Henderson
On Thu, 24 Jan 2008, Steven wrote:

 I use mrtg,

 I call this from MRTG: `/usr/local/groundwork/nagios/libexec/asterisk-mrtg.pl 
 -1 Zap -2 SIP`

 Here is my asterisk-mrtg.pl: (note, I have tweaked this, but I do not 
 know where I had gotten my original reference)

Hi Steven,

The original location of this is:

   http://karlsbakk.net/asterisk/scripts/asterisk-mrtg

The down-side is that mrtg only samples every 5 minutes, and as there is 
no running total, just an instantaneous count in gauge mode, it has the 
opportunity to miss calls made when it's not sampling. So this is OK for 
busy sites where a few calls either way won't be noticed, but I'm dealing 
with relatively low call volumes of 1-2 a minute, with very occasional 
bursts to (maybe, I don't know yet!) 4-6 simultaneous calls.

(I have a customer who has 4 ISDN2e ports; 8 channels) and they want to 
know if they can lose one port and save some money)

I'm working on something slightly better that will poll it more often, but 
still provide an mrtg interface. I'll post details here, but it's not that 
high a priority right now.

Cheers,

Gordon

 `Daily' Graph (5 Minute Average)




 Max
 Average
 Current

  Zap channels
 5 Zap channels in use
 1 Zap channels in use
 0 Zap channels in use

  SIP channels
 6 SIP channels in use
 1 SIP channels in use
 0 SIP channels in use





 -- 
 -- 
 Steven

 http://www.connectech.org/



 Gordon Henderson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]

 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.

 I know I can porobably go through the CDR logs and look for calls which
 have overlapped in time, but I'm wondering if there's some counter
 somewhere I could access...

 (I'm looking for evidence for an ISDN client who wants to know if he's
 spent too much on the number of ISDN lines he has installed!)

 Cheers,

 Gordon

 ___
 -- Bandwidth and Colocation Provided by http://www.api-digital.com --

 asterisk-users mailing list
 To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-24 Thread Gordon Henderson
On Wed, 23 Jan 2008, Tilghman Lesher wrote:

 On Wednesday 23 January 2008 23:23:23 Anthony Francis wrote:
 Tilghman Lesher wrote:
 On Wednesday 23 January 2008 12:23:24 Gordon Henderson wrote:
 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.

 I know I can porobably go through the CDR logs and look for calls which
 have overlapped in time, but I'm wondering if there's some counter
 somewhere I could access...

 No, the CDRs would be where that information is stored, if anywhere.

 This is actually sort of easy. You simply have every call pass through a
 context in which you assign the call to a group, then either do a NoOp
 echoing the group count or a user event doing the same, then either
 programatically or grep search your logs for the output or have a script
 monitoring the AMI watch for the user event and write the number in a
 data base.

 Of these two I personally do the second option because then I can just
 do a max() function on that database field to get the maximum calls for
 any time range I specify.

 Oh and just a note, never just say no because you don't know, in this
 instance you would say, I think your best bet is the CDR's. Just a tip.

 The key phrase in the original post was has had, indicating past behavior,
 not future behavior.  Yes, you can do all sorts of things in the dialplan to
 get that information into a logfile, but you cannot retroactively do those
 things.  The only place that information can be had are the CDRs, so I will
 stick with my original assessment.

Yes, nice to know what happened in the past, but also nice to know what 
happens in the future, so I'm not overly hung up about how. (And the CDRs 
aren't in a database either - just flat file on my devices)

I did actually think of adding in some diaplan stuff to keep counts, but 
I've now got a skeleton and a good idea if something that'll keep me 
happy. Basically 2 parts - one which polls the system via the manager 
inteface every few seconds to count calls, and another which interfaces to 
mrtg. I didn't really think of this initially as for a long time my units 
did have perl, (which mrtg needs) but I've managed to squeeze in enough 
perl to run other things now, so off I go.

Thanks,

Gordon

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Tilghman Lesher
On Wednesday 23 January 2008 12:23:24 Gordon Henderson wrote:
 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.

 I know I can porobably go through the CDR logs and look for calls which
 have overlapped in time, but I'm wondering if there's some counter
 somewhere I could access...

No, the CDRs would be where that information is stored, if anywhere.

-- 
Tilghman

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Drew Gibson
Gordon Henderson wrote:
 Is there any way to find-out the peak number of calls that an asterisk 
 system has had? Not the total number of calls, but the maximum number of 
 simultaneous calls.

 I know I can porobably go through the CDR logs and look for calls which 
 have overlapped in time, but I'm wondering if there's some counter 
 somewhere I could access...

 (I'm looking for evidence for an ISDN client who wants to know if he's 
 spent too much on the number of ISDN lines he has installed!)

 Cheers,

 Gordon
   

We use Asterisk-stat from Areski (GPL). It will show peak number of 
calls by the hour. Select Daily Load, scroll down and choose the hour 
you want and Fluctuation Graph. Lots of other goodies too.

http://areski.net/areski/index.php?option=com_contenttask=viewid=22Itemid=54

regards,

Drew

-- 
Drew Gibson

Systems Administrator
OANDA Corporation
www.oanda.com


___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Steve Edwards
On Wed, 23 Jan 2008, Drew Gibson wrote:

 Gordon Henderson wrote:
 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.

 We use Asterisk-stat from Areski (GPL). It will show peak number of
 calls by the hour. Select Daily Load, scroll down and choose the hour
 you want and Fluctuation Graph. Lots of other goodies too.

 http://areski.net/areski/index.php?option=com_contenttask=viewid=22Itemid=54

Or, as a quick  dirty...

 DATE=$(date +%F-%H-%M-%S)
 COUNT=$(sudo /usr/sbin/asterisk -r -x sip show channels | wc -l)
 echo $DATE $COUNT /tmp/channel-counts

in a shell script executed every second in cron.

Thanks in advance,

Steve Edwards  [EMAIL PROTECTED]  Voice: +1-760-468-3867 PST
Newline Fax: +1-760-731-3000

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Andres

Gordon Henderson wrote:

Is there any way to find-out the peak number of calls that an asterisk 
system has had? Not the total number of calls, but the maximum number of 
simultaneous calls.
  

MRTG is very handy for this.  We use the script found at: 
http://karlsbakk.net/asterisk/  You can plot SIP, IAX, and ZAP Channels 
over time.

Andres
http://www.neuroredes.com

I know I can porobably go through the CDR logs and look for calls which 
have overlapped in time, but I'm wondering if there's some counter 
somewhere I could access...

(I'm looking for evidence for an ISDN client who wants to know if he's 
spent too much on the number of ISDN lines he has installed!)

Cheers,

Gordon

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

  



___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Steve Totaro
On Jan 23, 2008 2:06 PM, Steve Edwards [EMAIL PROTECTED] wrote:
 On Wed, 23 Jan 2008, Drew Gibson wrote:

  Gordon Henderson wrote:
  Is there any way to find-out the peak number of calls that an asterisk
  system has had? Not the total number of calls, but the maximum number of
  simultaneous calls.
 
  We use Asterisk-stat from Areski (GPL). It will show peak number of
  calls by the hour. Select Daily Load, scroll down and choose the hour
  you want and Fluctuation Graph. Lots of other goodies too.
 
  http://areski.net/areski/index.php?option=com_contenttask=viewid=22Itemid=54

 Or, as a quick  dirty...

  DATE=$(date +%F-%H-%M-%S)
  COUNT=$(sudo /usr/sbin/asterisk -r -x sip show channels | wc -l)
  echo $DATE $COUNT /tmp/channel-counts

 in a shell script executed every second in cron.

 Thanks in advance,
 
 Steve Edwards  [EMAIL PROTECTED]  Voice: +1-760-468-3867 PST
 Newline Fax: +1-760-731-3000


I have seen Cacti used to make some *really* nice semi-realtime and
historic graphs.

Thanks,
Steve Totaro

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Gordon Henderson
On Wed, 23 Jan 2008, Andres wrote:

 Gordon Henderson wrote:

 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.


 MRTG is very handy for this.  We use the script found at:
 http://karlsbakk.net/asterisk/  You can plot SIP, IAX, and ZAP Channels
 over time.

Ah yes. Quite Intersting.

I use MRTG in a lot of applications, so this is worthy of a look. It only 
samples every 5 minutes though, so has the potential to miss things, 
although this (and the crude shell-script suggested by Steve Edwards has 
presented me with an idea to use the manager interface to sample it a bit 
more often and keep a count.

Thanks!

Gordon

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Paul Hales

On Wed, 2008-01-23 at 18:23 +, Gordon Henderson wrote:
 Is there any way to find-out the peak number of calls that an asterisk 
 system has had? Not the total number of calls, but the maximum number of 
 simultaneous calls.
 
 I know I can porobably go through the CDR logs and look for calls which 
 have overlapped in time, but I'm wondering if there's some counter 
 somewhere I could access...
 
 (I'm looking for evidence for an ISDN client who wants to know if he's 
 spent too much on the number of ISDN lines he has installed!)

Munin has a nice Asterisk plugin that works reasonably well.

PaulH



___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Mojo with Horan Company, LLC
Steve Edwards wrote:
 Or, as a quick  dirty...
  DATE=$(date +%F-%H-%M-%S)
  COUNT=$(sudo /usr/sbin/asterisk -r -x sip show channels | wc -l)
  echo $DATE $COUNT /tmp/channel-counts

 in a shell script executed every second in cron.
   
every *second* from cron?  how the heck would I you do that?  sub-minute 
accuracy from cron is something I don't know how to do.

Maybe it's a different version of cron...?

The only way I would achieve that would be to run something every minute 
that self-perpetuated for the rest of that minute... 

for x in `seq 1 58`; 
do
 ( DATE=$(date +%F-%H-%M-%S)
   COUNT=$(sudo /usr/sbin/asterisk -r -x sip show channels | wc -l)
   echo $DATE $COUNT /tmp/channel-counts
 ) 
 sleep 1s
done

which is honestly very messy.

I promise I'm not being sarcastic.  I actually *am* curious if there are 
versions of cron that will go sub-minute.

Moj



___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Steve Edwards
On Wed, 23 Jan 2008, Mojo with Horan  Company, LLC wrote:

 Steve Edwards wrote:
 Or, as a quick  dirty...
  DATE=$(date +%F-%H-%M-%S)
  COUNT=$(sudo /usr/sbin/asterisk -r -x sip show channels | wc -l)
  echo $DATE $COUNT /tmp/channel-counts

 in a shell script executed every second in cron.

 every *second* from cron?  how the heck would I you do that?  sub-minute
 accuracy from cron is something I don't know how to do.

Sheese -- that's what I get by trying to type without putting down the 
crack pipe :)

You're right -- the * in the first column of your crontab means minutes, 
not seconds.

Thanks in advance,

Steve Edwards  [EMAIL PROTECTED]  Voice: +1-760-468-3867 PST
Newline Fax: +1-760-731-3000

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Mojo with Horan Company, LLC
Steve Edwards wrote:
 in a shell script executed every second in cron.

   
 every *second* from cron?  how the heck would I you do that?  sub-minute
 accuracy from cron is something I don't know how to do.
 

 Sheese -- that's what I get by trying to type without putting down the 
 crack pipe :)

 You're right -- the * in the first column of your crontab means minutes, 
 not seconds.
   
Ok, I'm NOT on the crack pipe then ;)  I was wondering.

Sticking to the slimy hack i described!

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Anthony Francis
Tilghman Lesher wrote:
 On Wednesday 23 January 2008 12:23:24 Gordon Henderson wrote:
   
 Is there any way to find-out the peak number of calls that an asterisk
 system has had? Not the total number of calls, but the maximum number of
 simultaneous calls.

 I know I can porobably go through the CDR logs and look for calls which
 have overlapped in time, but I'm wondering if there's some counter
 somewhere I could access...
 

 No, the CDRs would be where that information is stored, if anywhere.

   

This is actually sort of easy. You simply have every call pass through a 
context in which you assign the call to a group, then either do a NoOp 
echoing the group count or a user event doing the same, then either 
programatically or grep search your logs for the output or have a script 
monitoring the AMI watch for the user event and write the number in a 
data base.

Of these two I personally do the second option because then I can just 
do a max() function on that database field to get the maximum calls for 
any time range I specify.

Oh and just a note, never just say no because you don't know, in this 
instance you would say, I think your best bet is the CDR's. Just a tip.

Anthony

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Peak number of calls?

2008-01-23 Thread Tilghman Lesher
On Wednesday 23 January 2008 23:23:23 Anthony Francis wrote:
 Tilghman Lesher wrote:
  On Wednesday 23 January 2008 12:23:24 Gordon Henderson wrote:
  Is there any way to find-out the peak number of calls that an asterisk
  system has had? Not the total number of calls, but the maximum number of
  simultaneous calls.
 
  I know I can porobably go through the CDR logs and look for calls which
  have overlapped in time, but I'm wondering if there's some counter
  somewhere I could access...
 
  No, the CDRs would be where that information is stored, if anywhere.

 This is actually sort of easy. You simply have every call pass through a
 context in which you assign the call to a group, then either do a NoOp
 echoing the group count or a user event doing the same, then either
 programatically or grep search your logs for the output or have a script
 monitoring the AMI watch for the user event and write the number in a
 data base.

 Of these two I personally do the second option because then I can just
 do a max() function on that database field to get the maximum calls for
 any time range I specify.

 Oh and just a note, never just say no because you don't know, in this
 instance you would say, I think your best bet is the CDR's. Just a tip.

The key phrase in the original post was has had, indicating past behavior,
not future behavior.  Yes, you can do all sorts of things in the dialplan to
get that information into a logfile, but you cannot retroactively do those
things.  The only place that information can be had are the CDRs, so I will
stick with my original assessment.

-- 
Tilghman

___
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users