Thursday, August 25, 2011

Housekeep Asterisk Log Files

Asterisk log files can grow very large unawared, eventually leading to disk space problems. 
We can take a few measures to maintain log history and housekeep old ones automatically.
1.    Review the /etc/asterisk/logger.conf
This file specifies the logging level of asterisk.  In a production system, it is sufficient to turn on message log only while keeping the others disabled. 
;debug => debug
console => notice,warning,error,debug
messages => notice,warning,error
;full => notice,warning,error,debug,verbose
The modified logging level is made effective by:
asterisk –rx 'logger reload'
2.    Use logrotate to rotate and remove historical files
This utility is helpful in housekeeping outdated log files.  The logrotate is usually invoked from /etc/cron.daily and it looks for how and what to process in the /etc/logrotate.conf.
As illustrated in the logrotate.conf below, we rotate log files on weekly basis and keep 4 weeks.  Rotated log would have a timestamp as suffix.  Older files would be deleted automatically.  Note that we can compress rotated files to further reduce disk usage.  Individual rotation information are put in /etc/logrotate.d.
# see "man logrotate" for details
# rotate log files weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
# use date as a suffix of the rotated file
# uncomment this if you want your log files compressed
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
In /etc/logrotate.d/, we can create a file (eg, named as 'asterisk') to specify which asterisk log files we want to housekeep.  We need to run 'logger reload'.  Otherwise, Asterisk still writes to the old file.
/var/log/asterisk/messages  {
    /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null

Thursday, August 18, 2011

Asterisk Native Bridge vs SIP External Native Bridge

The difference can be illustrated by below scenario:
  1. Dial creates an outbound PBX channel and asks one of the channel drivers to create a call
  2. When the call is answered, Asterisk bridges the media streams so the caller on the first channel can speak with the callee on the second, outbound channel
  3. In some cases where we have the same technology on both channels and compatible codecs, a native bridge is used. In a native bridge, the channel driver handles forwarding of incoming audio to the outbound stream internally, without sending audio frames through the PBX.
  4. In SIP, theres an "external native bridge" where Asterisk redirects the endpoint, so audio flows directly between the caller's phone and the callee's phone. Signalling stays in Asterisk in order to be able to provide a proper CDR record for the call.

The above information is taken from