SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Asterisk(IP-PBX)
CDR log rotation
(with Linux Cron)
William.L
wiliwe@gmail.com
2014-03-17
Outline
Asterisk CDR
Crond
Logrotate
Put All Together
Reference
CDR - Call Detail Records
CDR contains information about calls that have
passed through Asterisk system
Asterisk assumes that you want to store CDR
information
CDR is store in CSV (Comma-Separated Value)
format
Asterisk CDR (1/4)
By default, Asterisk creates a CDR file named
Master.csv in the folder
/var/log/asterisk/cdr-csv
and call information is stored in this file
To the naked eye, Master.csv file’s content
looks like a bit of a mess. If, however, you
separate each line according to the commas,
you will find that each line contains information
about a particular call.
Asterisk CDR (2/4)
A Comma-Separated Values (CSV) file is a
common method of formatting database-type
information in a text file
You can open CSV files with a text editor, but
most spreadsheet(likes Microsoft Excel) and
database programs will also read them and
properly parse them into rows and columns
Asterisk CDR (3/4)
By default, Asterisk will simply add to the files
until the storage (hard drive or other non-valotile
storage) is full
In Asterisk 1.4
Basic call (2-way) generates 245 ~ 247 bytes of CDR
content
Conference call (3-way) generates around 494 bytes
of CDR content
Asterisk CDR (4/4)
Linux provides utilities to handle the rotation of
log files
So that no single file becomes too large
Also, the deletion of older logfiles (which will prevent
the system from getting clogged with log files)
logrotate is a tool to do “log rotation” :
Regular (daily, weekly, monthly, etc) moving of an
existing log file to some other file name and starting
fresh with an empty log file
After a period the old log files get thrown away
Logrotate (1/2)
logrotate tool is often run on a cron job, which
has the effect of fully automatic log rotation
One of downloadable site for source :
https://fedorahosted.org/logrotate/
Logrotate (2/2)
cron is a job scheduling facility in Linux/Unix
system.
The cron system is managed by cron daemone,
crond
It gets information about which program and when
they should run
At system startup cron daemon is invoked
Cron (1/7)
cron daemone searches following target every
minute
/etc/cron.d folder
/etc/crontab file(cron table)
/var/spool/cron folder
Under /etc/cron.d and /var/spool/cron folder
there have shell script files named after accounts in
/etc/passpwd file and
are executed by cron daemone when it is time to do
scheduled job
Cron (2/7)
On system using Vixie cron, jobs that occure
hourly, daily, weekly and monthly are kept in
separate directories in /etc:
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/etc/cron.monthly
/etc/crontab stores these folders as table
entries
Cron (3/7)
Vixie cron uses the program run-parts
to run shell scripts in each folder listed in
/etc/crontab
Cron (4/7)
On CentOS 6, Vixie cron uses the program
run-parts to run shell scripts in each folder listed
in /etc/anacrontab
Cron (5/7)
cron command explanation
Cron (6/7)
http://linuxblog.pansapiens.com/wp-content/uploads/2008/06/cron.png
Note:
In MS-Windows environment, there has a built-in tool
functioning as Cron named
Windows Task Scheduler
http://en.wikipedia.org/wiki/Windows_Task_Scheduler
Cron (7/7)
To do Asterisk CDR log rotation, it needs to
configure cron job using lograte tool
Create a folder named logrotate.d in /etc
Create a logrotate configuration file named asterisk
in /etc/logrotate.d and place following content in this
file (here setting maximum size of CDR file to 70K
bytes for example)
Put All Together (1/3)
/var/log/asterisk/cdr-csv/Master.csv {
daily
missingok
size 70k
rotate 2
copytruncate
}
Create a shell script named logrotate in
/etc/cron.daily and its content is as below (assume
logrotate could be invoked from directory
/usr/sbin):
Put All Together (2/3)
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.d/asterisk
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with
[$EXITVALUE]"
fi
exit 0
To see the status of execution of logrotate
/var/lib/ logrotate.status
How often does system do CDR log rotation?
Depening on call traffic volume, e.g the speed of
size increasing of Master.csv
Put All Together (3/3)
Asterisk CDR log rotation
http://www.voip-info.org/wiki/view/logrotate
http://www.voip-info.org/wiki/view/logrotate+Chinese
More information about the usage of logrotate
configuration file
http://www.thegeekstuff.com/2010/07/logrotate-
examples/
http://linuxconfig.org/logrotate
http://www-
uxsup.csx.cam.ac.uk/~jw35/courses/apache/html/x167
0.htm
Reference

Más contenido relacionado

La actualidad más candente

1 basic computer operations
1   basic computer operations1   basic computer operations
1 basic computer operations
missCS
 

La actualidad más candente (20)

1 basic computer operations
1   basic computer operations1   basic computer operations
1 basic computer operations
 
Lesson 3 Working with Files in Linux
Lesson 3 Working with Files in LinuxLesson 3 Working with Files in Linux
Lesson 3 Working with Files in Linux
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Unix
UnixUnix
Unix
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Unix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell ScriptUnix/Linux Basic Commands and Shell Script
Unix/Linux Basic Commands and Shell Script
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Unix slideshare
Unix slideshareUnix slideshare
Unix slideshare
 
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERSVTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
VTU 3RD SEM UNIX AND SHELL PROGRAMMING SOLVED PAPERS
 
Linux Basic Commands
Linux Basic CommandsLinux Basic Commands
Linux Basic Commands
 
Basic linux commands for bioinformatics
Basic linux commands for bioinformaticsBasic linux commands for bioinformatics
Basic linux commands for bioinformatics
 
Part 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in Linux
 
Basic Linux commands
Basic Linux commandsBasic Linux commands
Basic Linux commands
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 

Destacado

GNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in GnomeGNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in Gnome
William Lee
 
CWMP TR-069 Training (Chinese)
CWMP TR-069 Training (Chinese)CWMP TR-069 Training (Chinese)
CWMP TR-069 Training (Chinese)
William Lee
 
Introdunction To Network Management Protocols SNMP & TR-069
Introdunction To Network Management Protocols SNMP & TR-069Introdunction To Network Management Protocols SNMP & TR-069
Introdunction To Network Management Protocols SNMP & TR-069
William Lee
 
Qt Development Tools
Qt Development ToolsQt Development Tools
Qt Development Tools
William Lee
 

Destacado (20)

Re-identification of Anomized CDR datasets using Social networlk Data
Re-identification of Anomized CDR datasets using Social networlk DataRe-identification of Anomized CDR datasets using Social networlk Data
Re-identification of Anomized CDR datasets using Social networlk Data
 
MTP & PTP
MTP & PTPMTP & PTP
MTP & PTP
 
Android Services and Managers Basic
Android Services and Managers BasicAndroid Services and Managers Basic
Android Services and Managers Basic
 
GNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in GnomeGNOME GeoClue - The Geolocation Service in Gnome
GNOME GeoClue - The Geolocation Service in Gnome
 
Android Debugging (Chinese)
Android Debugging (Chinese)Android Debugging (Chinese)
Android Debugging (Chinese)
 
Moblin2 - Window Manager(Mutter) Plugin
Moblin2 - Window Manager(Mutter) PluginMoblin2 - Window Manager(Mutter) Plugin
Moblin2 - Window Manager(Mutter) Plugin
 
Android Storage - StorageManager & OBB
Android Storage - StorageManager & OBBAndroid Storage - StorageManager & OBB
Android Storage - StorageManager & OBB
 
Usage Note of Qt ODBC Database Access on Linux
Usage Note of Qt ODBC Database Access on LinuxUsage Note of Qt ODBC Database Access on Linux
Usage Note of Qt ODBC Database Access on Linux
 
CWMP TR-069 Training (Chinese)
CWMP TR-069 Training (Chinese)CWMP TR-069 Training (Chinese)
CWMP TR-069 Training (Chinese)
 
Introdunction To Network Management Protocols SNMP & TR-069
Introdunction To Network Management Protocols SNMP & TR-069Introdunction To Network Management Protocols SNMP & TR-069
Introdunction To Network Management Protocols SNMP & TR-069
 
Qt Development Tools
Qt Development ToolsQt Development Tools
Qt Development Tools
 
Android Logging System
Android Logging SystemAndroid Logging System
Android Logging System
 
Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)
 
IPv6 Overview
IPv6 OverviewIPv6 Overview
IPv6 Overview
 
Timing over packet demarcation
Timing over packet demarcationTiming over packet demarcation
Timing over packet demarcation
 
Hello world在那邊?背景說明
Hello world在那邊?背景說明Hello world在那邊?背景說明
Hello world在那邊?背景說明
 
MGCP Overview
MGCP OverviewMGCP Overview
MGCP Overview
 
Android Storage - Internal and External Storages
Android Storage - Internal and External StoragesAndroid Storage - Internal and External Storages
Android Storage - Internal and External Storages
 
GNU AS簡介
GNU AS簡介GNU AS簡介
GNU AS簡介
 
from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 

Similar a Asterisk (IP-PBX) CDR Log Rotation

Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
BertrandDrouvot
 
Vista Forensics
Vista ForensicsVista Forensics
Vista Forensics
CTIN
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System i
Chuck Walker
 
Lamp1
Lamp1Lamp1
Lamp1
Reka
 
Lamp
LampLamp
Lamp
Reka
 

Similar a Asterisk (IP-PBX) CDR Log Rotation (20)

Linux filesystemhierarchy
Linux filesystemhierarchyLinux filesystemhierarchy
Linux filesystemhierarchy
 
Edubooktraining
EdubooktrainingEdubooktraining
Edubooktraining
 
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
 
4. Centos Administration
4. Centos Administration4. Centos Administration
4. Centos Administration
 
Vista Forensics
Vista ForensicsVista Forensics
Vista Forensics
 
Introduction to Operating Systems.pptx
Introduction to Operating Systems.pptxIntroduction to Operating Systems.pptx
Introduction to Operating Systems.pptx
 
Linux Survival Kit for Proof of Concept & Proof of Technology
Linux Survival Kit for Proof of Concept & Proof of TechnologyLinux Survival Kit for Proof of Concept & Proof of Technology
Linux Survival Kit for Proof of Concept & Proof of Technology
 
Linux training
Linux trainingLinux training
Linux training
 
File system discovery
File system discovery File system discovery
File system discovery
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
 
Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008Purdue CS354 Operating Systems 2008
Purdue CS354 Operating Systems 2008
 
Root file system for embedded systems
Root file system for embedded systemsRoot file system for embedded systems
Root file system for embedded systems
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Linux Basics
Linux BasicsLinux Basics
Linux Basics
 
Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux Course 102: Lecture 2: Unwrapping Linux
Course 102: Lecture 2: Unwrapping Linux
 
Working with the IFS on System i
Working with the IFS on System iWorking with the IFS on System i
Working with the IFS on System i
 
disk-operating-system.ppt
disk-operating-system.pptdisk-operating-system.ppt
disk-operating-system.ppt
 
Lamp1
Lamp1Lamp1
Lamp1
 
Lamp1
Lamp1Lamp1
Lamp1
 
Lamp
LampLamp
Lamp
 

Más de William Lee

Study of Chromium OS
Study of Chromium OSStudy of Chromium OS
Study of Chromium OS
William Lee
 
More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)
William Lee
 
Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069
William Lee
 

Más de William Lee (20)

Usage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP LanguagesUsage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP Languages
 
Usage Note of SWIG for PHP
Usage Note of SWIG for PHPUsage Note of SWIG for PHP
Usage Note of SWIG for PHP
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
 
Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3
 
Viewing Android Source Files in Eclipse (Chinese)
Viewing Android Source Files in Eclipse  (Chinese)Viewing Android Source Files in Eclipse  (Chinese)
Viewing Android Source Files in Eclipse (Chinese)
 
Usage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency WalkerUsage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency Walker
 
Usage Note of PlayCap
Usage Note of PlayCapUsage Note of PlayCap
Usage Note of PlayCap
 
Qt4 App - Sliding Window
Qt4 App - Sliding WindowQt4 App - Sliding Window
Qt4 App - Sliding Window
 
GTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App ChooserGTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App Chooser
 
GTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon ChooserGTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon Chooser
 
Note of CGI and ASP
Note of CGI and ASPNote of CGI and ASP
Note of CGI and ASP
 
L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5
 
C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)
 
Internationalization(i18n) of Web Page
Internationalization(i18n) of Web PageInternationalization(i18n) of Web Page
Internationalization(i18n) of Web Page
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 Usage
 
Study of Chromium OS
Study of Chromium OSStudy of Chromium OS
Study of Chromium OS
 
More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)
 
Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Asterisk (IP-PBX) CDR Log Rotation

  • 1. Asterisk(IP-PBX) CDR log rotation (with Linux Cron) William.L wiliwe@gmail.com 2014-03-17
  • 3. CDR - Call Detail Records CDR contains information about calls that have passed through Asterisk system Asterisk assumes that you want to store CDR information CDR is store in CSV (Comma-Separated Value) format Asterisk CDR (1/4)
  • 4. By default, Asterisk creates a CDR file named Master.csv in the folder /var/log/asterisk/cdr-csv and call information is stored in this file To the naked eye, Master.csv file’s content looks like a bit of a mess. If, however, you separate each line according to the commas, you will find that each line contains information about a particular call. Asterisk CDR (2/4)
  • 5. A Comma-Separated Values (CSV) file is a common method of formatting database-type information in a text file You can open CSV files with a text editor, but most spreadsheet(likes Microsoft Excel) and database programs will also read them and properly parse them into rows and columns Asterisk CDR (3/4)
  • 6. By default, Asterisk will simply add to the files until the storage (hard drive or other non-valotile storage) is full In Asterisk 1.4 Basic call (2-way) generates 245 ~ 247 bytes of CDR content Conference call (3-way) generates around 494 bytes of CDR content Asterisk CDR (4/4)
  • 7. Linux provides utilities to handle the rotation of log files So that no single file becomes too large Also, the deletion of older logfiles (which will prevent the system from getting clogged with log files) logrotate is a tool to do “log rotation” : Regular (daily, weekly, monthly, etc) moving of an existing log file to some other file name and starting fresh with an empty log file After a period the old log files get thrown away Logrotate (1/2)
  • 8. logrotate tool is often run on a cron job, which has the effect of fully automatic log rotation One of downloadable site for source : https://fedorahosted.org/logrotate/ Logrotate (2/2)
  • 9. cron is a job scheduling facility in Linux/Unix system. The cron system is managed by cron daemone, crond It gets information about which program and when they should run At system startup cron daemon is invoked Cron (1/7)
  • 10. cron daemone searches following target every minute /etc/cron.d folder /etc/crontab file(cron table) /var/spool/cron folder Under /etc/cron.d and /var/spool/cron folder there have shell script files named after accounts in /etc/passpwd file and are executed by cron daemone when it is time to do scheduled job Cron (2/7)
  • 11. On system using Vixie cron, jobs that occure hourly, daily, weekly and monthly are kept in separate directories in /etc: /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly /etc/crontab stores these folders as table entries Cron (3/7)
  • 12. Vixie cron uses the program run-parts to run shell scripts in each folder listed in /etc/crontab Cron (4/7)
  • 13. On CentOS 6, Vixie cron uses the program run-parts to run shell scripts in each folder listed in /etc/anacrontab Cron (5/7)
  • 14. cron command explanation Cron (6/7) http://linuxblog.pansapiens.com/wp-content/uploads/2008/06/cron.png
  • 15. Note: In MS-Windows environment, there has a built-in tool functioning as Cron named Windows Task Scheduler http://en.wikipedia.org/wiki/Windows_Task_Scheduler Cron (7/7)
  • 16. To do Asterisk CDR log rotation, it needs to configure cron job using lograte tool Create a folder named logrotate.d in /etc Create a logrotate configuration file named asterisk in /etc/logrotate.d and place following content in this file (here setting maximum size of CDR file to 70K bytes for example) Put All Together (1/3) /var/log/asterisk/cdr-csv/Master.csv { daily missingok size 70k rotate 2 copytruncate }
  • 17. Create a shell script named logrotate in /etc/cron.daily and its content is as below (assume logrotate could be invoked from directory /usr/sbin): Put All Together (2/3) #!/bin/sh /usr/sbin/logrotate /etc/logrotate.d/asterisk EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0
  • 18. To see the status of execution of logrotate /var/lib/ logrotate.status How often does system do CDR log rotation? Depening on call traffic volume, e.g the speed of size increasing of Master.csv Put All Together (3/3)
  • 19. Asterisk CDR log rotation http://www.voip-info.org/wiki/view/logrotate http://www.voip-info.org/wiki/view/logrotate+Chinese More information about the usage of logrotate configuration file http://www.thegeekstuff.com/2010/07/logrotate- examples/ http://linuxconfig.org/logrotate http://www- uxsup.csx.cam.ac.uk/~jw35/courses/apache/html/x167 0.htm Reference