Friday, May 7, 2010

Asterisk call recording using Ramdisk

Asterisk 1.4.22 / Freepbx 2.5 - Call recording using Ramdisk


Ramdisk is a portion of the computer's physical memory which
you can use to store files temporarily. Since memory is faster
than hard disk, ramdisk increases computer performance during
file operations.

We can set up asterisk to store ongoing call recordings in
ramdisk and then move these files to a permanent storage once
recording has finished.

In freepbx's general settings, you can assign a directory
for saving call recordings, "Recording Location:". We'll define
ramdisk as the destination folder.

Since ramdisk is a temporary storage, any files located in it
will be removed when the computer restarts. This is where the
"Run After Record" comes in handy. We can define a script to
move the recordings once asterisk has finished writing them.
Freepbx allows us to push asterisk arguments to the script,
which we can use to specify recording file names.

In this example, we set /temp_rec as our recording location.
This is our ramdisk. Do the following to create our
temporary storage.


;Specify how big is our ramdisk going to be.
;Do this in /etc/grub.conf
;ramdisk_size is in KB
;Here we are configured for 2GB
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/VolGroup00/LogVol00 ramdisk_size=2000000
initrd /initrd-2.6.18-128.el5.img


;Put this in rc.local to create ramdisk during bootup
/sbin/mke2fs -m 0 /dev/ram0
/bin/mount /dev/ram0 /temp_rec
/bin/mkdir /temp_rec/monitor
/bin/mkdir /temp_rec/system
/bin/mkdir /temp_rec/tmp
/bin/chown -R asterisk.asterisk /temp_rec
;For more infor on ramdisk:
;http://www.vanemery.com/Linux/Ramdisk/ramdisk.html


;Link asterisk's default folders to our ramdisk
/bin/ln -s /temp_rec/system /var/spool/asterisk
/bin/ln -s /temp_rec/tmp /var/spool/asterisk
/bin/ln -s /temp_rec/monitor /var/spool/asterisk


;Create script move_recordings.sh
;nfs_disk is a nfs server
#! /bin/bash
# ARGUMENT INPUT ORDER ^{MIXMON_DIR} ^{CALLFILENAME} ^{MIXMON_FORMAT}
# MOVE EXTENSION RECORDINGS
/bin/mv $1/$2.$3 /nfs_disk


;Now the general settings should look like this:
Recording location:
/var/spool/asterisk/monitor/

Run after record:
/var/spool/asterisk/scripts/move_recordings.sh ^{MIXMON_DIR} ^{CALLFILENAME} ^{MIXMON_FORMAT}


;create nfs entries in fstab
;192.168.0.2 is our nfs server
192.168.0.2:/data/rec /nfs_disk nfs rw,soft,intr,bg,nolock,rsize=8192,wsize=8192,udp 0 0


Below are the figures and specifications I used to
test everything we've discussed.

Asterisk server:
Quad Xeon 2.40GHz
4GB RAM

Pjsip / Pjsua server - for emulating (multiple calls) 60 extensions
logged into asterisk's queue. You can set them to auto-answer,
automatically play audio and disconnect after 10 minutes.

Vicidial server - for conducting 60 simultaneous calls to asterisk
(with audio playing) and redialing each time pjsip extensions
disconnect (10 minutes). Vicidial made 500 calls during the test.

Asterisk with 60 simultaneous incoming calls being recorded for 10
minutes at any given time. Finishing off with 500 calls in total.

I used sync in crontab to clear the memory cache from
time to time. But it is best to put in additional physical
RAM if recording eats up more memory.

*/30 * * * * /bin/sync; echo 3 > /proc/sys/vm/drop_caches

No comments:

Post a Comment