The number of active calls\channels in Asterisk - output to file

Sometimes it is necessary to determine whether there are enough channels of ground telephone lines, in case if the operator is connected to Asterisk. To collect such statistics in our company, we decided to record every minute (ideally, of course, more often) the number of active calls\channels in Asterisk to file, then plot if required.

There are two steps in the task:

  1. Output needed data to file in manual mode.
  2. Put the script into cron.

Command to get the number of active calls\channels in Asterisk (there is also time):

root@ast:~# echo `date +"%d/%m/%y %H:%M:%S"` - `/usr/sbin/asterisk -rx "core show channels" | grep "call\|channel"`
11/12/15 12:02:11 - 2 active channels 1 active call 230 calls processed

Save this command to .sh file:

root@astspb:~# cat active-calls.sh
#!/bin/bash

echo `date +"%d/%m/%y %H:%M:%S"` - `/usr/sbin/asterisk -rx "core show channels" | grep "call\|channel"` >> /home/user/active-calls.log
root@astspb:~#

Set the file as executable:

chmod +x active-calls.sh

Now we need to schedule this file. Run crontab (under root) and create a task:

sudo crontab -e

If you need some your favourite text editor, do this:

sudo EDITOR=vim crontab -e

Add our script to file and do not forget to add empty string at the end of file:

* * * * * /home/user/active-calls.sh

Check that task was added:

root@ast:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

* * * * * /home/user/active-calls.sh

Thats it.

Tags: linux (en), asterisk (en)

PrintEmail

Add comment


Security code
Refresh