aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMatt Rude <[email protected]>2011-06-26 03:47:58 -0500
committerMatt Rude <[email protected]>2011-06-26 03:47:58 -0500
commit61a6fa20f59f4befd7b1d6f426084e41eaa3c5bf (patch)
tree0283d23cd37d04e54b5cd3307c132298007134a8 /scripts
parent611bee7dfb28ce68044ba062fa3e012ba1b19829 (diff)
downloadtime.mattrude.com-61a6fa20f59f4befd7b1d6f426084e41eaa3c5bf.tar.gz
time.mattrude.com-61a6fa20f59f4befd7b1d6f426084e41eaa3c5bf.tar.bz2
time.mattrude.com-61a6fa20f59f4befd7b1d6f426084e41eaa3c5bf.zip
rewrite for cgi config
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-site.sh11
-rwxr-xr-xscripts/do-rrd-update6
-rwxr-xr-xscripts/do-xntp151
-rwxr-xr-xscripts/templates/graphs.cgi352
-rw-r--r--scripts/templates/template2
-rw-r--r--scripts/templates/template-by-type8
-rw-r--r--scripts/templates/template-host14
7 files changed, 377 insertions, 167 deletions
diff --git a/scripts/build-site.sh b/scripts/build-site.sh
index b4710f0..00feddb 100755
--- a/scripts/build-site.sh
+++ b/scripts/build-site.sh
@@ -19,6 +19,15 @@ echo " <div id="title">
cat $ROOT/readme.tmp $TEMPLATESDIR/tail >> $DOCUMENTSDIR/readme.html
rm -f $ROOT/readme.tmp
+### Building per host cgi files ###
+
+mkdir -p $ROOT/bin $ROOT/tmp
+for X in `cat $ROOT/rrd/list-of-systems`
+do
+ rm -f $ROOT/bin/graphs-$X.cgi
+ sed -e s/POOL/$X/g $TEMPLATESDIR/graphs.cgi > $ROOT/bin/graphs-$X.cgi
+ chmod 755 $ROOT/bin/graphs-$X.cgi
+done
### Building the Status Pages ###
mkdir -p $POOLPAGE
@@ -27,7 +36,7 @@ cat /dev/null > out.template
echo "<h2>Time Server Hosts</h2>
<ul>" >> out.template
-for X in `cat /var/www/time.mattrude.com/rrd/list-of-systems`
+for X in `cat $ROOT/rrd/list-of-systems`
do
echo "<li><a href=/status/$X/>$X</a>" >> out.template
done
diff --git a/scripts/do-rrd-update b/scripts/do-rrd-update
index 5926fc0..e75b946 100755
--- a/scripts/do-rrd-update
+++ b/scripts/do-rrd-update
@@ -14,10 +14,10 @@ if [ ! -f ntpclients.sqlite ]; then
echo "CREATE TABLE clientss (date datetime NOT NULL, host varchar(255) NOT NULL, value blob);" |sqlite3 ntpclients.sqlite
fi
-if [ $1 == "localhost" ]; then
+if [ $1 == `hostname` ]; then
CLIENTS=`${SCRIPTS}/do-ntp-client-update`
else
- CLIENTS='0:0'
+ CLIENTS=`ssh ${1} ${SCRIPTS}/do-ntp-client-update`
fi
/usr/sbin/ntpq -4 -c rv $1 | awk 'BEGIN{ RS=","}{ print }' >> /tmp/ntp-rrdstats.$$
@@ -34,6 +34,6 @@ rm /tmp/ntp-rrdstats.$$
# keep this in the same order as do-newntpstat creates them, please.
/usr/bin/rrdtool update $1.rrd N:${NOFFSET}:${NSJIT}:${NCJIT}:${NWANDER}:${NFREQ}:${NDISPER}:${CLIENTS}
-#echo "N:${NOFFSET}:${NSJIT}:${NCJIT}:${NWANDER}:${NFREQ}:${NDISPER}:${CLIENTS}"
+echo "N:${NOFFSET}:${NSJIT}:${NCJIT}:${NWANDER}:${NFREQ}:${NDISPER}:${CLIENTS}"
echo "INSERT INTO status (date, host, offset, freq, sjit, cjit, wander, disp) VALUES ('${DATE}', '${1}', '${NOFFSET}', '${NSJIT}', '${NCJIT}', '${NWANDER}', '${NFREQ}', '${NDISPER}');" |sqlite3 ntpstatus.sqlite
diff --git a/scripts/do-xntp b/scripts/do-xntp
index 66a8951..8c07b57 100755
--- a/scripts/do-xntp
+++ b/scripts/do-xntp
@@ -3,7 +3,6 @@
RRD_BIN=/usr/bin
RRDPAGE=/var/www/time.mattrude.com/rrd
SCRIPTS=/var/www/time.mattrude.com/scripts
-STATUS=/var/www/time.mattrude.com/status
cd ${RRDPAGE}
if [ ! $? ]; then exit 1; fi
@@ -12,154 +11,4 @@ for X in `cat list-of-systems`
do
sh ${SCRIPTS}/do-rrd-update ${X}
if [ ! $? ]; then exit 1; fi
-
- ${RRD_BIN}/rrdtool graph --imgformat=PNG ${STATUS}/${X}/daily-ntp-clients-small.png \
- --width=296 --height=111 --start=-86400 --end=-300 --lower-limit=0 -r \
- --title="${X}" \
- --vertical-label='Active Clients' \
- DEF:a="${RRDPAGE}/${X}.rrd":clients:LAST \
- AREA:a#002A97FF:"" \
- GPRINT:a:LAST:"Now\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Avg\:%8.2lf %s" \
- GPRINT:a:MAX:"Max\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/daily-ntp-clients.png \
- --width=650 --height=200 --start=-86400 --end=-300 \
- --title="${X} - Number of Active Clients" \
- --vertical-label='Number of Clients' \
- DEF:a="${RRDPAGE}/${X}.rrd":clients:LAST \
- DEF:b="${RRDPAGE}/${X}.rrd":abusive:LAST \
- AREA:a#002A97FF:"Clients:" \
- GPRINT:a:LAST:"Current\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:a:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" \
- AREA:b#F51D30FF:"Abusive:" \
- GPRINT:b:LAST:" Current\:%8.2lf %s" \
- GPRINT:b:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:b:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/weekly-ntp-clients.png \
- --width=650 --height=200 --start=-691200 --end=-300 \
- --title="${X} - Number of Active Clients" \
- --vertical-label='Number of Clients' \
- DEF:a="${RRDPAGE}/${X}.rrd":clients:LAST \
- DEF:b="${RRDPAGE}/${X}.rrd":abusive:LAST \
- AREA:a#002A97FF:"Clients:" \
- GPRINT:a:LAST:"Current\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:a:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" \
- AREA:b#F51D30FF:"Abusive:" \
- GPRINT:b:LAST:" Current\:%8.2lf %s" \
- GPRINT:b:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:b:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/monthly-ntp-clients.png \
- --width=650 --height=200 --start=-2629744 --end=-300 \
- --title="${X} - Number of Active Clients" \
- --vertical-label='Number of Clients' \
- DEF:a="${RRDPAGE}/${X}.rrd":clients:LAST \
- DEF:b="${RRDPAGE}/${X}.rrd":abusive:LAST \
- AREA:a#002A97FF:"Clients:" \
- GPRINT:a:LAST:"Current\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:a:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" \
- AREA:b#F51D30FF:"Abusive:" \
- GPRINT:b:LAST:" Current\:%8.2lf %s" \
- GPRINT:b:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:b:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/yearly-ntp-clients.png \
- --width=650 --height=200 --start=-31556926 --end=-300 \
- --title="${X} - Number of Active Clients" \
- --vertical-label='Number of Clients' \
- DEF:a="${RRDPAGE}/${X}.rrd":clients:LAST \
- DEF:b="${RRDPAGE}/${X}.rrd":abusive:LAST \
- AREA:a#002A97FF:"Clients:" \
- GPRINT:a:LAST:"Current\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:a:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" \
- AREA:b#F51D30FF:"Abusive:" \
- GPRINT:b:LAST:" Current\:%8.2lf %s" \
- GPRINT:b:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:b:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- for a in offset sjit cjit wander freq disp
- do
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/daily-ntp-${a}.png \
- --width 650 --height 200 --start -86400 --end=-300 \
- --title "${X} - ${a} - Daily - `date`" \
- --vertical-label "${X}" \
- DEF:a="${RRDPAGE}/${X}.rrd":${a}:LAST \
- AREA:a#002A97FF:"${a}:" \
- GPRINT:a:LAST:" Current\:%8.2lf %s" \
- GPRINT:a:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:a:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/weekly-ntp-${a}.png \
- --width 650 --height 200 --start -691200 --end=-300 \
- --title "`TZ=UTC date`" \
- --vertical-label "${X}" \
- DEF:${a}=${RRDPAGE}/${X}.rrd:${a}:LAST \
- CDEF:n${a}=${a},1000,/ \
- AREA:n${a}#002A97FF:"${a}:" \
- GPRINT:n${a}:LAST:"Current\:%le" \
- GPRINT:n${a}:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:n${a}:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:n${a}:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/monthly-ntp-${a}.png \
- --width 650 --height 200 --start -2629744 --end=-300 \
- --title "`TZ=UTC date`" \
- --vertical-label "${X}" \
- DEF:${a}=${RRDPAGE}/${X}.rrd:${a}:LAST \
- CDEF:n${a}=${a},1000,/ \
- AREA:n${a}#002A97FF:"${a}:" \
- GPRINT:n${a}:LAST:"Current\:%le" \
- GPRINT:n${a}:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:n${a}:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:n${a}:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- ${RRD_BIN}/rrdtool graph --imgformat PNG ${STATUS}/${X}/yearly-ntp-${a}.png \
- --width 650 --height 200 --start -31556926 --end=-300 \
- --title "`TZ=UTC date`" \
- --vertical-label "${X}" \
- DEF:${a}=${RRDPAGE}/${X}.rrd:${a}:LAST \
- CDEF:n${a}=${a},1000,/ \
- AREA:n${a}#002A97FF:"${a}:" \
- GPRINT:n${a}:LAST:"Current\:%le" \
- GPRINT:n${a}:AVERAGE:"Average\:%8.2lf %s" \
- GPRINT:n${a}:MIN:"Minimum\:%8.2lf %s" \
- GPRINT:n${a}:MAX:"Maximum\:%8.2lf %s\n" > /dev/null
-
- done
done
-
-# ${RRD_BIN}/rrdtool graph --imgformat=PNG ${STATUS}/all-clients.png \
-# --width=296 --height=83 --start=-86400 --end=-300 --lower-limit=0 -r \
-# --title='Active Clients on All Servers' \
-# --vertical-label='Active Clients' \
-# DEF:a="/var/www/time.mattrude.com/rrd/kirby.mattrude.com.rrd":clients:AVERAGE \
-# DEF:b="/var/www/time.mattrude.com/rrd/twyla.mattrude.com.rrd":clients:AVERAGE \
-# DEF:c="/var/www/time.mattrude.com/rrd/samantha.mattrude.com.rrd":clients:AVERAGE \
-# LINE1:a#002A97FF:"Kirby:" \
-# GPRINT:a:LAST:"Now\:%6.2lf %s" \
-# GPRINT:a:AVERAGE:"Avg\:%6.2lf %s" \
-# GPRINT:a:MAX:"Max\:%6.2lf %s\n" \
-# LINE1:b#000000FF:"Twyla:" \
-# GPRINT:b:LAST:"Now\:%6.2lf %s" \
-# GPRINT:b:AVERAGE:"Avg\:%6.2lf %s" \
-# GPRINT:b:MAX:"Max\:%6.2lf %s\n" \
-# LINE1:c#990000FF:"Saman:" \
-# GPRINT:c:LAST:"Now\:%6.2lf %s" \
-# GPRINT:c:AVERAGE:"Avg\:%6.2lf %s" \
-# GPRINT:c:MAX:"Max\:%6.2lf %s\n" > /dev/null
-
diff --git a/scripts/templates/graphs.cgi b/scripts/templates/graphs.cgi
new file mode 100755
index 0000000..46de70b
--- /dev/null
+++ b/scripts/templates/graphs.cgi
@@ -0,0 +1,352 @@
+#!/usr/bin/perl -w
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# ntpgraphs -- a simple ntp graphing script
+# mailgraph -- postfix mail traffic statistics
+# copyright (c) 2011 Matt Rude <[email protected]>
+# copyright (c) 2000-2007 ETH Zurich
+# copyright (c) 2000-2007 David Schweikert <[email protected]>
+# released under the GNU General Public License
+
+use RRDs;
+use POSIX qw(uname);
+
+my $VERSION = "2.1";
+
+my $host = 'POOL';
+my $site = 'time.mattrude.com';
+my $scriptname = 'graphs-POOL.cgi';
+my $points_per_sample = 3;
+my $xpoints = 650;
+my $ypoints = 200;
+my $ypoints_small = 111;
+my $xpoints_small = 296;
+my $rrd = '/var/www/time.mattrude.com/rrd/POOL.rrd'; # path to where the RRD database is
+my $tmp_dir = '/var/www/time.mattrude.com/tmp'; # temporary directory where to store the images
+
+my @graphs = (
+ { title => 'Last Day', seconds => 3600*24, },
+ { title => 'Last Week', seconds => 3600*24*7, },
+ { title => 'Last Month', seconds => 3600*24*31, },
+ { title => 'Last Year', seconds => 3600*24*365, },
+);
+
+my %color = (
+ sent => '000099', # rrggbb in hex
+ received => '009900',
+ rejected => 'AA0000',
+ bounced => '000000',
+ virus => 'DDBB00',
+ spam => '999999',
+);
+
+sub rrd_graph(@) {
+ my ($range, $file, $ypoints, @rrdargs) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ # choose carefully the end otherwise rrd will maybe pick the wrong RRA:
+ my $end = time; $end -= $end % $step;
+ my $date = localtime(time);
+ $date =~ s|:|\\:|g unless $RRDs::VERSION < 1.199908;
+
+ my ($graphret,$xs,$ys) = RRDs::graph($file,
+ '--imgformat', 'PNG',
+ '--width', $xpoints,
+ '--height', $ypoints,
+ '--start', "-$range",
+ '--end', $end,
+ '--vertical-label', 'milliseconds',
+ '--lower-limit', 0,
+ '--units-exponent', 0, # don't show milli-messages/s
+ '--lazy',
+ '--color', 'SHADEA#ffffff',
+ '--color', 'SHADEB#ffffff',
+ '--color', 'BACK#ffffff',
+
+ $RRDs::VERSION < 1.2002 ? () : ( '--slope-mode'),
+
+ @rrdargs,
+
+ 'COMMENT:['.$date.']\r',
+ );
+
+ my $ERR=RRDs::error;
+ die "ERROR: $ERR\n" if $ERR;
+}
+
+sub rrd_graph_small(@) {
+ my ($range, $file, $ypoints_small, @rrdargs) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ # choose carefully the end otherwise rrd will maybe pick the wrong RRA:
+ my $end = time; $end -= $end % $step;
+ my $date = localtime(time);
+ $date =~ s|:|\\:|g unless $RRDs::VERSION < 1.199908;
+
+ my ($graphret,$xs,$ys) = RRDs::graph($file,
+ '--title', 'POOL',
+ '--imgformat', 'PNG',
+ '--width', $xpoints_small,
+ '--height', $ypoints_small,
+ '--start', "-$range",
+ '--end', $end,
+ '--vertical-label', 'Server Offset',
+ '--lower-limit', 0,
+ '--units-exponent', 0, # don't show milli-messages/s
+ '--lazy',
+ '--color', 'SHADEA#ffffff',
+ '--color', 'SHADEB#ffffff',
+ '--color', 'BACK#ffffff',
+
+ $RRDs::VERSION < 1.2002 ? () : ( '--slope-mode'),
+
+ @rrdargs,
+ );
+
+ my $ERR=RRDs::error;
+ die "ERROR: $ERR\n" if $ERR;
+}
+
+sub graph_clients($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:clients=$rrd:clients:LAST",
+ "DEF:abusive=$rrd:abusive:LAST",
+ 'AREA:clients#002A97FF:Clients:',
+ 'GPRINT:clients:LAST:Current\:%8.2lf %s',
+ 'GPRINT:clients:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:clients:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:clients:MAX:Maximum\:%8.2lf %s\n',
+ 'AREA:abusive#F51D30FF:Abusive:',
+ 'GPRINT:abusive:LAST:Current\:%8.2lf %s',
+ 'GPRINT:abusive:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:abusive:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:abusive:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_clients_small($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints_small;
+ rrd_graph_small($range, $file, $ypoints_small,
+ "DEF:clients=$rrd:offset:LAST",
+ 'AREA:clients#002A97FF: :',
+ 'GPRINT:clients:LAST:Now\:%8.2lf %s',
+ 'GPRINT:clients:AVERAGE:Avg\:%8.2lf %s',
+ 'GPRINT:clients:MAX:Max\:%8.2lf %s\n',
+ );
+}
+
+sub graph_offset($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:offset=$rrd:offset:LAST",
+ 'AREA:offset#002A97FF:Offset:',
+ 'GPRINT:offset:LAST:Current\:%8.2lf %s',
+ 'GPRINT:offset:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:offset:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:offset:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_sjit($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:sjit=$rrd:sjit:LAST",
+ 'AREA:sjit#002A97FF:sJit:',
+ 'GPRINT:sjit:LAST:Current\:%8.2lf %s',
+ 'GPRINT:sjit:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:sjit:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:sjit:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_cjit($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:cjit=$rrd:cjit:LAST",
+ 'AREA:cjit#002A97FF:cJit:',
+ 'GPRINT:cjit:LAST:Current\:%8.2lf %s',
+ 'GPRINT:cjit:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:cjit:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:cjit:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_wander($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:wander=$rrd:wander:LAST",
+ 'AREA:wander#002A97FF:Wander:',
+ 'GPRINT:wander:LAST:Current\:%8.2lf %s',
+ 'GPRINT:wander:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:wander:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:wander:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_freq($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:freq=$rrd:freq:LAST",
+ 'AREA:freq#002A97FF:Freq:',
+ 'GPRINT:freq:LAST:Current\:%8.2lf %s',
+ 'GPRINT:freq:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:freq:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:freq:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub graph_disp($$) {
+ my ($range, $file) = @_;
+ my $step = $range*$points_per_sample/$xpoints;
+ rrd_graph($range, $file, $ypoints,
+ "DEF:disp=$rrd:disp:LAST",
+ 'AREA:disp#002A97FF:Disp:',
+ 'GPRINT:disp:LAST:Current\:%8.2lf %s',
+ 'GPRINT:disp:AVERAGE:Average\:%8.2lf %s',
+ 'GPRINT:disp:MIN:Minimum\:%8.2lf %s',
+ 'GPRINT:disp:MAX:Maximum\:%8.2lf %s\n',
+ );
+}
+
+sub print_html()
+{
+ print "Content-Type: text/html\n\n";
+
+ print <<HEADER;
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>$site :: $host Time Server Status Page</title>
+<meta http-equiv="Refresh" content="300" />
+<meta http-equiv="Pragma" content="no-cache" />
+<link rel="stylesheet" type="text/css" href="/style.css" />
+</head>
+<body>
+<div id="content">
+ <div id="primary" class="main">
+HEADER
+
+ print "<div id='title'><h1>$site <i>&mdash; $host Server Status</i></h1></div>\n";
+
+ print "<ul id=\"jump\">\n";
+ for my $n (0..$#graphs) {
+ print " <li><a href=\"#G$n\">$graphs[$n]{title}</a>&nbsp;</li>\n";
+ }
+ print "</ul>\n";
+
+ for my $n (0..$#graphs) {
+ print "<h2 id=\"G$n\">$graphs[$n]{title}</h2>\n";
+ print "<div class='center'><p><img src=\"$scriptname?${n}-clients\" alt=\"NTP Graph, Clients\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-offset\" alt=\"NTP Graph, Offset\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-freq\" alt=\"NTP Graph, Freq\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-sjit\" alt=\"NTP Graph, sJit\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-cjit\" alt=\"NTP Graph, cJit\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-wander\" alt=\"NTP Graph, Wander\"/><br/>\n";
+ print "<img src=\"$scriptname?${n}-disp\" alt=\"NTP Graph, Disp\"/></p></div>\n";
+ }
+
+ print <<FOOTER;
+</div>
+ <div id="footer">
+ <div class="footer-left">
+ <p><a href='http://time.mattrude.com'>Home</a> | <a href='/status/'>Status</a> | <a href='/documentation/'>Documentation</a> | <a href='https://github.com/mattrude/time.mattrude.com'>Source</a></p>
+ </div>
+ <div class="footer-right">
+ <p>Copyright &copy; 2009 &mdash; 2011 by <a href='http://mattrude.com'>Matt Rude</a></p>
+ </div>
+ </div>
+</div>
+</body></html>
+FOOTER
+}
+
+sub send_image($)
+{
+ my ($file)= @_;
+
+ -r $file or do {
+ print "Content-type: text/plain\n\nERROR: can't find $file\n";
+ exit 1;
+ };
+
+ print "Content-type: image/png\n";
+ print "Content-length: ".((stat($file))[7])."\n";
+ print "\n";
+ open(IMG, $file) or die;
+ my $data;
+ print $data while read(IMG, $data, 16384)>0;
+}
+
+sub main()
+{
+ mkdir $tmp_dir, 0777 unless -d $tmp_dir;
+ mkdir "$tmp_dir", 0777 unless -d "$tmp_dir";
+ mkdir "$tmp_dir/$host", 0777 unless -d "$tmp_dir/$host";
+
+ my $img = $ENV{QUERY_STRING};
+ if(defined $img and $img =~ /\S/) {
+ if($img =~ /^(\d+)-clients$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_clients.png";
+ graph_clients($graphs[$1]{seconds}, $file);
+ send_image($file);
+ } elsif($img =~ /^(\d+)-clients-small$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_clients-small.png";
+ graph_clients_small($graphs[$1]{seconds}, $file);
+ send_image($file);
+ } elsif($img =~ /^(\d+)-offset$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_offset.png";
+ graph_offset($graphs[$1]{seconds}, $file);
+ send_image($file);
+ }
+ elsif($img =~ /^(\d+)-sjit$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_sjit.png";
+ graph_sjit($graphs[$1]{seconds}, $file);
+ send_image($file);
+ }
+ elsif($img =~ /^(\d+)-cjit$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_cjit.png";
+ graph_cjit($graphs[$1]{seconds}, $file);
+ send_image($file);
+ }
+ elsif($img =~ /^(\d+)-wander$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_wander.png";
+ graph_wander($graphs[$1]{seconds}, $file);
+ send_image($file);
+ }
+ elsif($img =~ /^(\d+)-freq$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_freq.png";
+ graph_freq($graphs[$1]{seconds}, $file);
+ send_image($file);
+ } elsif($img =~ /^(\d+)-disp$/) {
+ my $file = "$tmp_dir/$host/ntpgraph_$1_disp.png";
+ graph_disp($graphs[$1]{seconds}, $file);
+ send_image($file);
+ } else {
+ die "ERROR: invalid argument\n";
+ }
+ }
+ else {
+ print_html;
+ }
+}
+
+main;
diff --git a/scripts/templates/template b/scripts/templates/template
index 4bcef99..1f9c5ca 100644
--- a/scripts/templates/template
+++ b/scripts/templates/template
@@ -1,4 +1,4 @@
<h2>Time Server: POOL</h2>
<div id="graphs" class="center">
- <p><center><a href="/status/POOL/"><img src="/status/POOL/daily-ntp-clients.png"></a></center></p>
+ <p><center><a href="/status/POOL/"><img src="/bin/graphs-POOL.cgi?0-offset"></a></center></p>
</div>
diff --git a/scripts/templates/template-by-type b/scripts/templates/template-by-type
index 5e4dcab..a247234 100644
--- a/scripts/templates/template-by-type
+++ b/scripts/templates/template-by-type
@@ -14,21 +14,21 @@
<h2>Host POOL, TYPE Daily Status</h2>
<div class="center">
- <p><img src="/status/POOL/daily-ntp-TYPE.png"></p>
+ <p><img src="/bin/graphs-POOL.cgi?0-TYPE"></p>
</div>
<h2>Host POOL, TYPE Weekly Status</h2>
<div class="center">
- <p><img src="/status/POOL/weekly-ntp-TYPE.png"></p>
+ <p><img src="/bin/graphs-POOL.cgi?1-TYPE"></p>
</div>
<h2>Host POOL, TYPE Monthly Status</h2>
<div class="center">
- <p><img src="/status/POOL/monthly-ntp-TYPE.png"></p>
+ <p><img src="/bin/graphs-POOL.cgi?2-TYPE"></p>
</div>
<h2>Host POOL, TYPE Yearly Status</h2>
<div class="center">
- <p><img src="/status/POOL/yearly-ntp-TYPE.png"></p>
+ <p><img src="/bin/graphs-POOL.cgi?3-TYPE"></p>
</div>
<br />
diff --git a/scripts/templates/template-host b/scripts/templates/template-host
index 68aa513..4feedcd 100644
--- a/scripts/templates/template-host
+++ b/scripts/templates/template-host
@@ -25,11 +25,11 @@ disp total dispersion to the primary reference clock
<h2>Host POOL, Daily Status</h2>
<div id="graphs" class="center">
- <p><a href="/status/POOL/clients/"><img src="/status/POOL/daily-ntp-clients.png"></a></p>
- <p><a href="/status/POOL/offset/"><img src="/status/POOL/daily-ntp-offset.png"></a></p>
- <p><a href="/status/POOL/freq/"><img src="/status/POOL/daily-ntp-freq.png"></a></p>
- <p><a href="/status/POOL/sjit/"><img src="/status/POOL/daily-ntp-sjit.png"></a></p>
- <p><a href="/status/POOL/cjit/"><img src="/status/POOL/daily-ntp-cjit.png"></a></p>
- <p><a href="/status/POOL/wander/"><img src="/status/POOL/daily-ntp-wander.png"></a></p>
- <p><a href="/status/POOL/disp/"><img src="/status/POOL/daily-ntp-disp.png"></a></p>
+ <p><a href="/status/POOL/clients/"><img src="/bin/graphs-POOL.cgi?0-clients"></a></p>
+ <p><a href="/status/POOL/offset/"><img src="/bin/graphs-POOL.cgi?0-offset"></a></p>
+ <p><a href="/status/POOL/freq/"><img src="/bin/graphs-POOL.cgi?0-freq"></a></p>
+ <p><a href="/status/POOL/sjit/"><img src="/bin/graphs-POOL.cgi?0-sjit"></a></p>
+ <p><a href="/status/POOL/cjit/"><img src="/bin/graphs-POOL.cgi?0-cjit"></a></p>
+ <p><a href="/status/POOL/wander/"><img src="/bin/graphs-POOL.cgi?0-wander"></a></p>
+ <p><a href="/status/POOL/disp/"><img src="/bin/graphs-POOL.cgi?0-disp"></a></p>
</div>