Maintenance
Logrotate cacti.log
Requirements
By default, cacti uses the file <cacti_dir>/log/cacti.log for logging purpose. There's no automatic cleanup of this file. So, without further intervention, there's a good chance, that this file reaches a file size limit of your filesystem. This will stop any further polling process. For *NIX type systems, logrotate is a widely known utility that solves exactly this problem. The following descriptions assumes you've set up a standard logrotate environment. The examples are based on a Fedora 6 environment. I assume, that Red Hat type installations will work the same way. I hope, but am not sure, that this howto is easily portable for Debian/Ubuntu and stuff and hopefully even for *BSD.
The logrotate Configuration File
The logrotate function is well described in the man pages. My setup is as follows:
# logrotate cacti.log
/var/www/html/cacti/log/cacti.log {
# keep 7 versions online
rotate 7
# rotate each day
daily
# don't compress, but
# if disk space is an issue, change to
# compress
nocompress
# create new file with <mode> <user> <group> attributes
create 644 cactiuser cactiuser
# add a YYYYMMDD extension instead of a number
dateext
}
Descriptions are given inline. Copy those statements from above into /etc/logrotate.d/cacti. This is the recommended file for application-specific logrotate files.
Test
logrotate configuration files are tested by running
logrotate -fd /etc/logrotate.d/cacti reading config file /etc/logrotate.d/cacti reading config info for /var/www/html/cacti/log/cacti.log Handling 1 logs rotating pattern: /var/www/html/cacti/log/cacti.log forced from command line (7 rotations) empty log files are rotated, old logs are removed considering log /var/www/html/cacti/log/cacti.log log needs rotating rotating log /var/www/html/cacti/log/cacti.log, log->rotateCount is 7 glob finding old rotated logs failed renaming /var/www/html/cacti/log/cacti.log to /var/www/html/cacti/log/cacti.log-20071004 creating new log mode = 0644 uid = 502 gid = 502
This is a dry run, no rotation is actually performed. Option -f forces log rotation even if the rotate criterium is not fulfilled. Option -d issues debug output but will suppress any real log rotation. Verify by listing the log directory: nothing has changed at all!
Now we will request log rotation using
logrotate -fd /etc/logrotate.d/cacti
No output is produced, but you will see the effect
ls -l /var/www/html/cacti/log -rw-r--r-- 1 cactiuser cactiuser 0 4. Okt 21:35 cacti.log -rw-r--r-- 1 cactiuser cactiuser 228735 4. Okt 21:35 cacti.log-20071004
Of course, the date extension on the file will change accordingly. Please notice, that a new cacti.log file was created. If you issue the command again, nothing will happen:
logrotate -fv /etc/logrotate.d/cacti reading config file /etc/logrotate.d/cacti reading config info for /var/www/html/cacti/log/cacti.log Handling 1 logs rotating pattern: /var/www/html/cacti/log/cacti.log forced from command line (7 rotations) empty log files are rotated, old logs are removed considering log /var/www/html/cacti/log/cacti.log log needs rotating rotating log /var/www/html/cacti/log/cacti.log, log->rotateCount is 7 destination /var/www/html/cacti/log/cacti.log-20071004 already exists, skipping rotation
If you want to see all those 7 rotations on one single day, remove the dateext directive temporarily from the configuration file.
Daily MySQL Dump of the Cacti SQL Database using logrotate
Requirements
By default, cacti uses the MySQL database named cacti. You may want to consider dumping this database on regular intervals for failsafe reason. For a single dump, you will usually enter this dump command directly into crontab. It is possible, to mis-use logrotate to create daily dumps, append dateext-like timestamps to each dump and keep a distinct number of generations online. For a basic setup, see Logrotate cacti.log, The following descriptions assumes you've set up a standard logrotate environment. The examples are based on a Fedora 6 environment. I assume, that Red Hat type installations will work the same way. I hope, but am not sure, that this howto is easily portable for Debian/Ubuntu and stuff and hopefully even for *BSD.
The logrotate Configuration File for MySQL Dumping the Cacti Database
It is absolutely necessary for this example, that a single dump file already exists. Else, logrotate will skip any execution due to a missing “log” file. My setup is as follows:
# logrotate sql dump file
/var/www/html/cacti/log/cacti_dump.sql {
# keep 31 generations online
rotate 31
# create a daily dump
daily
# don't compress the dump
nocompress
# create using this <mode> <user> <group>
create 644 cactiuser cactiuser
# append a nice date to the file
dateext
# delete all generations older than 31 days
maxage 31
# run this script AFTER rotating the previous cacti_dump.sql file
# make sure to use the correct database, user and password, see ./include/config.php
prerotate
/usr/bin/mysqldump --user=cactiuser --password=cactiuser --lock-tables --add-drop-database --add-drop-table cacti > /var/www/html/cacti/log/cacti_dump.sql
endscript
}
You may add this configuration to /etc/logrotate.d/cacti, even if the logrotate of cacti.log is already given there. Prior to testing this configuration, don't forget to
touch /var/www/html/cacti/log/cacti_dump.sql
Now run the test as follows
logrotate -fv /etc/logrotate.d/cacti reading config file /etc/logrotate.d/cacti reading config info for /var/www/html/cacti/log/cacti_dump.sql Handling 1 log rotating pattern: /var/www/html/cacti/log/cacti_dump.sql forced from command line (31 rotations) empty log files are rotated, old logs are removed considering log /var/www/html/cacti/log/cacti_dump.sql log needs rotating rotating log /var/www/html/cacti/log/cacti_dump.sql, log->rotateCount is 31 glob finding old rotated logs failed running prerotate script renaming /var/www/html/cacti/log/cacti_dump.sql to /var/www/html/cacti/log/cacti_dump.sql-20071004 creating new log mode = 0644 uid = 502 gid = 502
Now list the results
ls -l /var/www/html/log/cacti_dump* -rw-r--r-- 1 cactiuser cactiuser 0 4. Okt 22:10 cacti_dump.sql -rw-r--r-- 1 cactiuser cactiuser 318441 4. Okt 22:10 cacti_dump.sql-20071004
Migrating RRD Files between Architectures
- Run this Script on source-host.
#/bin/csh # This scripts dumps all rrd in the working dir # into xml files. set files=`echo *.rrd` foreach file ( $files ) set base = `basename $file .rrd` /bin/rrdtool dump $file > /tmp/new1/$base.xml end
- `tar-gzip` the xmls and transfer them to the target system.
- uncompress and untar the file to an empty directory.
- Run this script on target-host in the choosen directory
#/bin/csh # restores rrds from xml-dumps. set files=`echo *.xml` foreach file ($files) set base = `basename $file .xml` /opt/local/bin/rrdtool restore $file /opt/local/htdocs/cacti/rra/$base.rrd end








