mrtg-rrd.cgi's tight
coupling with mrtg.) Please be aware that my script
does not work with default mrtg.cfg files.rrd.cgi supports on-the-fly HTML output and
graph images.rrd.cgi which only creates the graphs if someone
requests them via their web browser and only if they are out of date
(stale). Yes, this is a front-end only..rrd files and
the file size. Archival mode helps in that respect./www/htdocs/rrd/scripts/changelog.sh \ old_release_tag new_release_tag \ > /www/htdocs/rrd/scripts/cl.xml xsltproc -o cl.html cl2html.xsl cl.xml
rrd.cgi (near the top)
# EDIT THIS to reflect all your RRD config files
BEGIN { @config_files = qw(
/etc/rrd/rrd.cfg
/etc/rrd/rrd-mysql.cfg
/etc/rrd/rrd-tomcat.cfg
/etc/rrd/rrd-network.cfg
/etc/rrd/rrd-weather.cfg
/etc/rrd/rrd-sar.cfg
); }
imagedir
is the same as ImAgEdIr.
| Directive | Explanation | Example(s) | Comment |
|---|---|---|---|
Imagedir |
Filesystem path to the directory where images will be stored | /www/htdocs/rrd/images |
Needs to be writable by the process running the web server. |
Logdir |
Filesystem path to the directory where .rrd files (logs) will be stored | /www/htdocs/rrd/logs |
Needs to be writable by the process updating the .rrd files (via crontab, for example). |
Resourcedir |
Web path to the URL for some resources | /rrd/resources |
My resources directory contains rrdtool.gif and
some other relic mrtg-*.png files. In addition, to
that I now also have a CalendarPopup.js file for
easy display of calendar dates. I also have my
css file (style.css) in that directory. |
Archivedir |
Filesystem path to the directory where archived images are stored | /www/htdocs/rrd/archives |
Needs to be writable by the process running the crontab
entry for archiving of images. Also needs to be web viewable via
the Archiveurl directive. |
Archiveurl |
Web path to the URL where archived images are stored | /rrd/archives |
|
Archivecgi |
Base url for CGI for retrieving images from the front-end | http://localhost/perl/rrd.cgi |
You can specify a fully qualified domain name if
localhost doesn't work for you. |
Interval |
Time interval in minutes (for refresh purposes) | 5 |
pagetop[title] is the same as PaGeToP[tItLe].
| Directive | Explanation | Example(s) | Comment |
|---|---|---|---|
Title |
Title of the statistic | Privoxy filtering proxy |
|
PageTop |
HTML heading of the statistic | <h1>Privoxy filtering proxy</h1> |
Note, you can use line continuation by starting a new line with a whitespace. |
Directory |
Subdirectory path where the stats and the images will be
stored respectively in Imagedir and
Logdir |
localhost_stats |
All of my localhost related stats use the Directory
directive of localhost_stats. |
RelPercent |
RRDs::graph returns a pointer to an ARRAY
containing the
x-size and y-size of the created gif and results of the
PRINT arguments.
($av,$x,$y) = RRDs::graph ...
print "Gifsize: ${x}x${y}\n",
"Averages: ", (join ", ", @$av);
This directive will be used as the preceding text to display for
the relative percentages between two (2) CDEFs or (DEFs) which are
the output of PRINT statements found in the
Graph directive.
|
Blocked versus Total requests percentage |
(Directive is optional). For my privoxy stats, I get the
following text output underneath the graph:
Blocked versus Total requests percentage Cur:
4.5% Avg: 15.1% Max: 27.0%
Buggy feature removed in release 1.5.5.
|
Graph |
Perhaps the most important section of
this configuration file.
The syntax for this directive mostly comes straight from
man rrdgraph. However, some rules about how the CGI
parses the syntax should be explained.
I use GPRINT:a:LAST:"\ \ \ \ \ \ \ \ \ Cur\:%3.0lf%"(note the use of backslashes for consecutive spaces). A full example of a Graph directive is:
Graph[uptime]: -v Days --rigid -l 0 DEF:a=/path/to/uptime.rrd:uptime:AVERAGE AREA:a#7aafff:Uptime GPRINT:a:LAST:"Cur\:%6.1lf" GPRINT:a:AVERAGE:"Ave\:%6.1lf" GPRINT:a:MAX:"MAX\:%6.1lf" LINE1:a#000001:By the time this is submitted to RRDs::graph, the arguments will have been converted
to:-v Days --rigid -l 0 DEF:a=/path/to/uptime.rrd:uptime:AVERAGE AREA:a#7aafff:Uptime GPRINT:a:LAST:Cur\:%6.1lf GPRINT:a:AVERAGE:Ave\:%6.1lf GPRINT:a:MAX:MAX\:%6.1lf LINE1:a#000001: |
||
|
Note: Starting from release
1.4.4 onwards, you can now specify just the relative
path in the DEF directives. E.g.,
Graph[uptime]: DEF:uptime.rrd:uptime:AVERAGEwill be submitted to RRDs::graph as:
DEF:/www/logs/stats/uptime.rrd:uptime:AVERAGEassuming that you have the following local directives: Directory[uptime]: statsand the following global directive: Logdir: /www/logsIf the path specified in the DEF directive is an absolute path to begin with, then it will be passed as-is to RRDs::graph.
Please do not name CDEFs that start with
numbers when using rrdtool 1.2.x. With a CDEF named like
25PL, rrdtool 1.2.9 will simply assign the value
25 to that CDEF.
Later versions may correct this behavior.
rrdtool 1.2.10+ fixes this problem.
|
|||
Suppress |
You can use this directive to suppress certain detailed
graphs.
|
phdw |
I use the line: Suppress[uptime]: phdw for my Uptime
graph to suppress preview, hourly, daily and weekly graphs. |
IgnoreTimestamps |
You can use this directive to ignore the timestamp displayed on the detailed page. | yes |
Use this if you do not care about creating symbolic links which
facilitate the display of the "last updated time" of the target
by translating the target name to the real .rrd
name. See
Symbolic Links Gotcha #1.
|
Imagedir for that stat
would do the trick.LANG environment variable to be passed along to the
script or pango would complain as follows in the
error_log whenever it was writing special characters
like ©:
(process:11070): Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()
LANG environment variable is set to
en_US. When running under mod_cgi, I used
the following snippet in httpd.conf:
<IfModule env_module>
PassEnv LANG
</IfModule>
When running under mod_perl, I used the following
snippet in httpd.conf:
PerlPassEnv LANG
CalendarPopup.js inside the Resourcedir.prompt> uname -rsmpio Linux 2.6.27-gentoo-r2 i686 Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz GenuineIntel GNU/Linux prompt> ./httpd -v Server version: Apache/2.2.13 (Unix) Server built: Sep 21 2009 13:40:40 prompt> perl -v This is perl, v5.8.8 built for i686-linux prompt> gcc --version gcc (Gentoo 4.4.1 p1.0) 4.4.1 prompt> rrdtool --version RRDtool 1.3.8 Copyright 1997-2009 by Tobias Oetiker <tobi@oetiker.ch> prompt> perl -MRRDs -le 'print RRDs->VERSION' 1.3008 prompt> perl -Mmod_perl2 -le 'print mod_perl->VERSION' 2.000004 prompt> perl -MCGI -le 'print CGI->VERSION' 3.45 prompt> perl -MDate::Manip -le 'print Date::Manip->VERSION' 5.54 prompt> perl -MLWP::UserAgent -le 'print LWP::UserAgent->VERSION' 5.829 prompt> perl -MText::ParseWords -le 'print Text::ParseWords->VERSION' 3.24 prompt> perl -MImage::Size -le 'print Image::Size->VERSION' 3.2
Imagedir, Logdir and
Archivedir
global directives exist. In addition, make sure all the directories
specified in the per-stat Directory sections exist. Here are my
directories (pay attention to the permissions):
/www/htdocs/rrd/images: total 16 drwxrwsr-x 6 apache apache 86 Sep 27 11:58 . drwxrwxr-x 8 apache apache 92 Nov 28 2003 .. drwxrwsr-x 2 apache apache 4096 Jul 14 13:35 localhost_stats drwxrwsr-x 2 apache apache 4096 Sep 27 14:19 network_stats drwxrwsr-x 2 apache apache 4096 Aug 19 10:57 tomcat_stats drwxrwsr-x 2 apache apache 4096 Aug 3 11:03 weather_stats /www/htdocs/rrd/logs: total 12 drwxrwsr-x 6 rrd rrd 110 Sep 27 11:57 . drwxrwxr-x 8 apache apache 92 Nov 28 2003 .. drwxrwsr-x 2 rrd rrd 4096 Jul 14 13:01 localhost_stats drwxrwsr-x 2 rrd rrd 54 Sep 27 11:57 network_stats drwxrwsr-x 2 rrd rrd 26 Jun 14 11:37 tomcat_stats drwxrwsr-x 2 rrd rrd 90 Aug 28 12:57 weather_stats /www/htdocs/rrd/archives: total 0 drwxrwsr-x 5 rrd rrd 67 Oct 26 10:22 . drwxrwxr-x 8 apache apache 84 Oct 25 15:56 .. drwxrwsr-x 3 rrd rrd 17 Oct 26 11:05 localhost_stats drwxrwsr-x 3 rrd rrd 17 Oct 26 11:05 network_stats drwxrwsr-x 3 rrd rrd 17 Oct 26 11:05 tomcat_stats drwxrwsr-x 3 rrd rrd 17 Jul 31 23:55 weather_statsNotice the file permissions and ownerships for the images (user
rrd which runs the crontab data gathering processes),
logs (user apache which runs my webserver process) and
archives (user rrd which runs the crontab for archival)
directories respectively.rrd files:
/www/htdocs/rrd/logs/localhost_stats: total 3708 drwxrwsr-x 2 rrd rrd 4096 Jul 14 13:01 . drwxrwsr-x 6 rrd rrd 86 Sep 30 11:09 .. -rw-r--r-- 1 rrd rrd 84 Apr 1 2003 README.txt -rw-rw-r-- 1 rrd rrd 209300 Sep 30 11:10 cpu.rrd -rw-rw-r-- 1 rrd rrd 313444 Sep 30 11:10 disk.rrd lrwxrwxrwx 1 rrd rrd 8 Jan 21 2004 disk_avail.rrd -> disk.rrd -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 disk_backup.rrd lrwxrwxrwx 1 rrd rrd 8 Jan 21 2004 disk_usage.rrd -> disk.rrd -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 eth0.rrd -rw-rw-r-- 1 rrd rrd 53084 Sep 30 11:10 fanrpm.rrd -rw-rw-r-- 1 rrd rrd 157228 Sep 30 11:10 load_avg.rrd -rw-rw-r-- 1 rrd rrd 261372 Sep 30 11:10 memory.rrd -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 privoxy.rrd -rw-rw-r-- 1 rrd rrd 53084 Sep 30 11:10 procs.rrd -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 temperature.rrd -rw-rw-r-- 1 rrd rrd 53084 Sep 30 11:10 uptime.rrd -rw-rw-r-- 1 rrd rrd 53084 Sep 30 11:10 users.rrd /www/htdocs/rrd/logs/network_stats: total 208 drwxrwsr-x 2 rrd rrd 54 Sep 27 11:57 . drwxrwsr-x 6 rrd rrd 86 Sep 30 11:09 .. -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 ping_external.rrd -rw-rw-r-- 1 rrd rrd 105156 Sep 30 11:10 ping_internal.rrd /www/htdocs/rrd/logs/tomcat_stats: total 208 drwxrwsr-x 2 rrd rrd 26 Jun 14 11:37 . drwxrwsr-x 6 rrd rrd 86 Sep 30 11:09 .. -rw-rw-r-- 1 rrd rrd 209300 Sep 30 11:10 localhost.rrd lrwxrwxrwx 1 rrd rrd 13 Sep 30 16:20 tomcat_memory.rrd -> localhost.rrd lrwxrwxrwx 1 rrd rrd 13 Sep 30 16:21 tomcat_sessionactive.rrd -> localhost.rrd lrwxrwxrwx 1 rrd rrd 13 Sep 30 16:20 tomcat_threadbusy.rrd -> localhost.rrd lrwxrwxrwx 1 rrd rrd 13 Sep 30 16:21 tomcat_threadcount.rrd -> localhost.rrd /www/htdocs/rrd/logs/weather_stats: total 408 drwxrwsr-x 2 rrd rrd 90 Aug 28 12:57 . drwxrwsr-x 8 rrd rrd 154 Jul 30 15:23 .. -rw-rw-r-- 1 rrd rrd 417592 Oct 8 21:00 cyyz.rrd lrwxrwxrwx 1 root rrd 8 Aug 28 12:57 humid.rrd -> cyyz.rrd lrwxrwxrwx 1 root rrd 8 Aug 28 12:57 press.rrd -> cyyz.rrd lrwxrwxrwx 1 root rrd 8 Jul 31 16:09 temperature.rrd -> cyyz.rrd lrwxrwxrwx 1 root rrd 8 Aug 2 18:53 wind.rrd -> cyyz.rrd
Logdir is specified
at the beginning of the file, it is also repeated inside the
DEF lines in the Graph section for each
stat. E.g., at the beginning of the file:
Logdir: /www/htdocs/rrd/logsand then later on,
DEF:a=/www/htdocs/rrd/logs/localhost_stats/privoxy.rrd:ds0:AVERAGEClearly, this violates DRY (do not repeat yourself). If you decide to change the path to
Logdir, make
sure you do it in all of the DEF lines as well. In the
future, I might look into improving this behavior.
disk_avail.rrd
and disk_usage.rrd, my main RRD file for those stats is
disk.rrd. From the reporting point of view
disk_avail and disk_usage are separate
even though their data is stored in the same RRD file.
The config section for disk availability
uses disk_avail between the square brackets, e.g.,
Title[disk_avail]: Disk Free Space. When
rrd.cgi tries to find the "last updated" time, it looks
for disk_avail.rrd. Without the symoblic link that file
would not exist and you will not see a correct "last updated time".
Instead you will see something similar to:
Wednesday, 31 December, 19:00:00 ESTIn addition, you will see something similar to the following in your web server's error_log:
Could not get status info for /www/htdocs/rrd/logs/localhost_stats/disk_avail.rrd. Missing symbolic link or incorrect permissions!If that is the case, you are indeed missing the symbolic link. See the per-stat directive IgnoreTimestamps if you want to "ignore the timestamps".
Disk_Avail.rrd,
then naturally you might have specified your directives for
that stat as, for e.g.,
Title[Disk_Avail]: Disk Availability. Since stat
names and directives are converted internally into lower-case,
rrd.cgi will look for the file
disk_avail.rrd instead of Disk_Avail.rrd.
To work around this problem, create a symbolic link as follows:
mixedcase_name.rrd -> MiXeDcAsE_NaMe.rrd
Archivedir
Archivedir contains an archive of
daily/monthly/yearly images. At the time of writing, my
directory structure (last 2 directory levels yyyy/mm, created
automatically by the script) is as follows:
/www/htdocs/rrd/archives /www/htdocs/rrd/archives/localhost_stats /www/htdocs/rrd/archives/localhost_stats/2004 /www/htdocs/rrd/archives/localhost_stats/2004/10 /www/htdocs/rrd/archives/network_stats /www/htdocs/rrd/archives/network_stats/2004 /www/htdocs/rrd/archives/network_stats/2004/10 /www/htdocs/rrd/archives/tomcat_stats /www/htdocs/rrd/archives/tomcat_stats/2004 /www/htdocs/rrd/archives/tomcat_stats/2004/10 /www/htdocs/rrd/archives/weather_stats /www/htdocs/rrd/archives/weather_stats/2004 /www/htdocs/rrd/archives/weather_stats/2004/10
bash/awk/perl/python/snmpget/grep
to gather the data and put it into .rrd files using
rrdtool update.
used=total-(free+buff+cached). Swap usage is
calculated as: swap=swaptotal-swapfree.
dnsoverall.rrd
and dnsqueries.rrd
portions of create_rrd.sh for
the revised creation commands and also
look at the modified config sections for
[dnsoverall] and
[dnsqueries] in rrd.cfg.
dnsoverall.rrd and dnsqueries.rrd
portions of create_rrd.sh where I
have added sane upper limits (instead of using U for
unlimited), so that I don't get huge spikes upon restart of dns
(or upon reboot).
named to gather the DNS statistics (bind 9.5+) every
5 minutes