Get active calls overtime

  • I need to track the active calls over time on an Asterisk based system.

    I know that i can get the information from the asterisk command core show channelse4f3bb28-e729-4953-b638-b06fac82c7de-image.png

    I know I can manually monitor it per second with watch -n 1 "asterisk -x 'core show channels' | grep 'active calls'"


    How can I get this logged to a file with the timestamp?

    Setup a cron to run every second and append a file? something else?

  • Something like this?

    ActiveCallDateTime=`date "+%Y%m%d_%H%M%S"`
    asterisk -x 'core show channels' | grep 'active calls' > activecalls-$ActiveCallDateTime.log

  • I can't think of a way aside from cron every X seconds. I'd dump it into a csv file with just the timestamp and the number of calls. E.g.

    if [ ! -f /var/log/activecalls.csv ]; then 
       echo "Timestamp,Calls" > /var/log/activecalls.csv
    DateTime=`date "+%Y%m%d %H:%M:%S"`
    echo -ne "\n$DateTime,"  >> /var/log/activecalls.csv
    asterisk -x 'core show channels' | grep 'active calls' | cut -d " " -f1

    Which SHOULD create a nice csv for you...