[HOWTO] Availability Reporting
Moderators: Developers, Moderators
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
[HOWTO] Availability Reporting
Cacti is nice in that it calculates availability for you, but my management is interested in availability by month. The technical guys are more interested in the availability of the previous day. To accomplish both of these, I wrote a reporting script, attached to this post.
**** UPDATE ****
9/2/2008
Version 1.3 of the script has been uploaded. By popular demand, this version adds a weekly report.
Version 1.2 of the script has been uploaded. This version adds a $filter variable that lets you select which devices are shown in the report. Essentially, the $filter variable is inserted into the WHERE clause of the SQL statement when pulling the hosts. This version also has a fix for a minor issue that affected my system (and probably other very large installs) where the stats of seemingly random devices were not cleared every month. (I suspect this was a record locking issue)
****************
Unzip these files into a directory like /usr/local/cacti_scripts and give them appropriate permissions.
In your cron, set it to run one minute after midnight:
1 0 * * * php /usr/local/cacti_scripts/availabilityReport.php
Edit the availabilityReport.php:
1. Set your MySQL server settings (default is for CactiEZ)
2. Set your smtpServer and the "from Address" for emails
3. Set your daily and monthly recipients. (Each are arrays, so you can send the daily/monthly reports to two different sets of people)
4. Set a good temporary directory that will survive a reboot
5. Set the "topX" or "AvailPercent" sections appropriately. The TopX allows you to get a list of the top X worst availability devices. The AvailPercent shows you all devices with less than the availability percentage you specify. (Only one per report can be active.) 0 disables these features, resulting in a complete list of all devices.
**** UPDATE ****
9/2/2008
Version 1.3 of the script has been uploaded. By popular demand, this version adds a weekly report.
Version 1.2 of the script has been uploaded. This version adds a $filter variable that lets you select which devices are shown in the report. Essentially, the $filter variable is inserted into the WHERE clause of the SQL statement when pulling the hosts. This version also has a fix for a minor issue that affected my system (and probably other very large installs) where the stats of seemingly random devices were not cleared every month. (I suspect this was a record locking issue)
****************
Unzip these files into a directory like /usr/local/cacti_scripts and give them appropriate permissions.
In your cron, set it to run one minute after midnight:
1 0 * * * php /usr/local/cacti_scripts/availabilityReport.php
Edit the availabilityReport.php:
1. Set your MySQL server settings (default is for CactiEZ)
2. Set your smtpServer and the "from Address" for emails
3. Set your daily and monthly recipients. (Each are arrays, so you can send the daily/monthly reports to two different sets of people)
4. Set a good temporary directory that will survive a reboot
5. Set the "topX" or "AvailPercent" sections appropriately. The TopX allows you to get a list of the top X worst availability devices. The AvailPercent shows you all devices with less than the availability percentage you specify. (Only one per report can be active.) 0 disables these features, resulting in a complete list of all devices.
- Attachments
-
- Screenshot
- Screenshot.png (15.46 KiB) Viewed 64585 times
-
- availabilityReport.zip
- availabilityReport.php and smtp.class.php. Place both in the same directory.
- (9.22 KiB) Downloaded 6656 times
Last edited by ptaylor874 on Tue Sep 02, 2008 11:47 am, edited 7 times in total.
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
-
- Cacti User
- Posts: 367
- Joined: Tue Apr 05, 2005 9:52 am
- Location: Munich, Germany
Hi,
here is our script for getting avail-report: the script is used for more than one cacti location so I must devide between the cities (bamberg....).
After reading the counters they will be reseted so the next time (every month) I get a new, clean statistic.
Torsten
here is our script for getting avail-report: the script is used for more than one cacti location so I must devide between the cities (bamberg....).
After reading the counters they will be reseted so the next time (every month) I get a new, clean statistic.
Code: Select all
#!/bin/bash
mailto="ADMIN-EMAIL"
if [ $# -lt 1 ]; then
echo Das Script erwartet als Parameter eine/mehrere Email-Adressen
echo z.b. avail-report.sh "test@de.com,l@l.com"
exit 1
fi
mailto=$1
if test -f /tmp/avail-report.txt ; then
rm -f /tmp/avail-report.txt
fi
hostn=`hostname`
echo \"Location\",\"Device\",\"Availability \(%\)\",\"Uptime \(d\)\" > /tmp/avail-report.txt
case "$hostn" in
mgtm)
host="Muenchen"
;;
*mgtd*)
host="Duesseldorf"
;;
*mgtb*)
host="Bielefeld"
esac
m="/usr/mysql/bin/mysql -u cacti --password=cacti"
echo "SELECT host.description,host.availability, uptime.uptime FROM host left join uptime on uptime.id=host.i
d ORDER by host.availability,host.description; UPDATE host SET total_polls = '0',failed_polls = '0';" |$m cacti | grep -v desc | awk '{h="'$host'" ;print "\""h
"\",\""$1"\",\""$2"\",\""$3/8640000"\"";}' >> /tmp/avail-report.txt
mail -s "Availability-Report Monitored Device from ${HOSTNAME}" ${mailto} < /tmp/avail-report.txt
if test -f /tmp/avail-report.txt ; then
rm -f /tmp/avail-report.txt
fi
Availabilty report
Hi, I am using this function and think it is great however it reports the first server each day as Total Polls = Zero and Failed Polls = Zero. All the other are fine.
Devices with Availability Less Than 99.5%
Report Duration: March 10, 2008, 12:01 am - March 11, 2008, 12:01 am
Device Availability Total Polls Failed Polls
Server 1 0.00000 0 0
Server 2 93.33333 285 19
Server 3 99.30556 288 2
Any ideas?
Devices with Availability Less Than 99.5%
Report Duration: March 10, 2008, 12:01 am - March 11, 2008, 12:01 am
Device Availability Total Polls Failed Polls
Server 1 0.00000 0 0
Server 2 93.33333 285 19
Server 3 99.30556 288 2
Any ideas?
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
Hello, I am working on similar issue but using a script that fetch remote host status(value 3 for up and 1 for down) from table host, and graph every host's status...then I can simply use reportit plugin to generate availability status report by using average((status-1)/2)*100%. but my problem is that if the remote device is down, it's impossible to write rrd file and update the graph. so for these device, they only have value when they are up, and as the result the value is 3. this makes the availability still equals 100%. (but if manually run in command line, it returns 1 which means device down)
I am now thinking of using cron to update those rrd file, but have no idea whether this way is possible or not..
can help me??
Thanks a lot!!!
saya
I am now thinking of using cron to update those rrd file, but have no idea whether this way is possible or not..
can help me??
Thanks a lot!!!
saya
Hey,
I realized that there must be a bug in it.
The daily availability is calculated by total polls vs failed polls, the problem is that the counters should be reset on a daily basis however (at least for me, 0.87b) the total seems to accumulate day by day so that the last daily report = monthly report.
First day you have 576 total polls, then you have 1152 total polls and so on. So for me the daily reports are actually 1st day to x day reports.
Otherwise its great!
I realized that there must be a bug in it.
The daily availability is calculated by total polls vs failed polls, the problem is that the counters should be reset on a daily basis however (at least for me, 0.87b) the total seems to accumulate day by day so that the last daily report = monthly report.
First day you have 576 total polls, then you have 1152 total polls and so on. So for me the daily reports are actually 1st day to x day reports.
Otherwise its great!
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
That is not how it is designed. The script writes temp files out each night when it runs. These temp files contain the information for the previous day. The next time it runs, it reads these temp files and subtracts the previous days totals out of the new total so you end up with just the total polls and failed polls per day.sveno wrote:Hey,
I realized that there must be a bug in it.
The daily availability is calculated by total polls vs failed polls, the problem is that the counters should be reset on a daily basis however (at least for me, 0.87b) the total seems to accumulate day by day so that the last daily report = monthly report.
First day you have 576 total polls, then you have 1152 total polls and so on. So for me the daily reports are actually 1st day to x day reports.
Otherwise its great!
Since it sounds like your temp files are the issue, make sure you've set the $tmpDir variable to a good directory that exists on your system. You may need to ensure that the user the daily report runs under is able to write to that location. If you have any job that cleans up that directory on a regular basis, you should disable that job.
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
Helped sveno out via PMs. In his case, he kept the $tmpDir to the default of "/tmp/", having a /tmp directory on the root of his drive on his Windows system. In the case of Windows, you must specify the drive letter and full path, like C:/tmp/.
At any rate, he's working now! Just thought I would post this tip in case anyone else with a Windows system had this problem.
At any rate, he's working now! Just thought I would post this tip in case anyone else with a Windows system had this problem.
-
- Posts: 45
- Joined: Fri Jan 04, 2008 11:45 am
Who is online
Users browsing this forum: No registered users and 0 guests