From a7c2b63dbe21ccd1961073cbbdbaff99671b7bdf Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sun, 1 Feb 2015 22:17:10 +0100 Subject: [PATCH 1/2] use $rrdfile everywhere --- add | 8 ++++---- import | 10 +++++----- index | 2 +- lib/readold | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/add b/add index b6c6c07..0ec4325 100755 --- a/add +++ b/add @@ -64,13 +64,13 @@ do ds="${ds//ds[/}" ds="${ds//]*/}" datasets+=("$ds") -done < <(rrdtool info ingress.rrd |grep index) +done < <(rrdtool info "$rrdfile" |grep index) for ds in ${dsnames[@]} do if [[ ! ${datasets[@]} =~ $ds ]] then - cp -f ingress.rrd ingress.rrd.bak_add_$ds - ./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN + cp -f "$rrdfile" "$rrdfile".bak_add_$ds + ./dsaddtor.pl "$rrdfile" $ds GAUGE $((48*60*60)) 0 NaN fi done data=N @@ -82,7 +82,7 @@ do done echo ${POST["innovator"]} > .innovator -rrdtool update ingress.rrd -t $template "$data" +rrdtool update "$rrdfile" -t $template "$data" if [ -n "$CACHE_DIR" ] then diff --git a/import b/import index 237f222..209b126 100755 --- a/import +++ b/import @@ -66,20 +66,20 @@ then ds="${ds//ds[/}" ds="${ds//]*/}" datasets+=("$ds") - done < <(rrdtool info ingress.rrd |grep index) + done < <(rrdtool info "$rrdfile" |grep index) for ds in ${dsnames[@]} do if [[ ! ${datasets[@]} =~ $ds ]] then - cp -f ingress.rrd ingress.rrd.bak_add_$ds - ./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN + cp -f "$rrdfile" "$rrdfile".bak_add_$ds + ./dsaddtor.pl "$rrdfile" $ds GAUGE $((48*60*60)) 0 NaN fi done while read date hour data do data=$(date -d "$date $hour" +%s):${data// /:} - rrdtool update ingress.rrd -t $template "$data" 2>&1 + rrdtool update "$rrdfile" -t $template "$data" 2>&1 done <<<"${POST["data"]}" if [ -n "$CACHE_DIR" ] @@ -106,7 +106,7 @@ else EOHTML if ! [ -w "$rrdfile" ] then - rrdtool create ingress.rrd -s $((60*60)) \ + rrdtool create "$rrdfile" -s $((60*60)) \ DS:AP:GAUGE:$((2*24*60*60)):0:NaN \ DS:Explorer:GAUGE:$((48*60*60)):0:NaN \ DS:Seer:GAUGE:$((48*60*60)):0:NaN \ diff --git a/index b/index index 97b8e2b..6569ee5 100755 --- a/index +++ b/index @@ -376,7 +376,7 @@ then
- First + First -Y -M -W diff --git a/lib/readold b/lib/readold index af8f41e..9bdb849 100644 --- a/lib/readold +++ b/lib/readold @@ -18,6 +18,6 @@ readold() { done ) } < <( - rrdtool fetch -s "$when" ingress.rrd AVERAGE | sed '/: nan/d' + rrdtool fetch -s "$when" "$rrdfile" AVERAGE | sed '/: nan/d' ) } From b969488ac6f787bf30020473bdce409d66607a43 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sun, 1 Feb 2015 22:19:48 +0100 Subject: [PATCH 2/2] Implement 304 Not Modified --- add.html | 7 +++---- import | 8 ++++---- index | 25 ++++++++----------------- lib/send_headers | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 lib/send_headers diff --git a/add.html b/add.html index 43e80b9..b9aa549 100755 --- a/add.html +++ b/add.html @@ -24,11 +24,10 @@ do done read_query_string +send_headers <<-EOHead + content-type: text/xml +EOHead cat <<-EOHTML -content-type: text/xml -Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') -Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') - diff --git a/import b/import index 209b126..8d498f8 100755 --- a/import +++ b/import @@ -88,11 +88,11 @@ then echo $'\nCache cleared!' fi else - cat <<-EOHTML - content-type: text/xml - Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') - Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') + send_headers <<-EOHead + content-type: text/xml + EOHead + cat <<-EOHTML diff --git a/index b/index index 6569ee5..7a40db2 100755 --- a/index +++ b/index @@ -39,6 +39,11 @@ read_query_string if [ -z "$graph" ] then + send_headers <<-EOHead + content-type: application/xhtml+xml + refresh: 300 + EOHead + readlast medals get_current_level @@ -54,14 +59,6 @@ then title="IngRRD - $webuser [L$curlevel] - Overview" fi cat <<-EOHTML - content-type: application/xhtml+xml - Last-Modified: $( - LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' \ - -d @$(rrdtool last ingress.rrd) - ) - Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '1 hour') - refresh: 10 - @@ -479,17 +476,11 @@ then EOHTML else - now=$(date +%s) - cat <<-EOHEAD + send_headers <<-EOHead content-type: image/png - Last-Modified: $( - LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' \ - -d @$(rrdtool last ingress.rrd) - ) - Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '1 hour') - - EOHEAD + EOHead + now=$(date +%s) if [[ $graph == AP ]] then thresholds=( diff --git a/lib/send_headers b/lib/send_headers new file mode 100644 index 0000000..e092b71 --- /dev/null +++ b/lib/send_headers @@ -0,0 +1,22 @@ +#!/bin/bash + +send_headers() { + local timestamp do_exit header thisdate expiredate + read timestamp < <(stat -c %Y $0 "$rrdfile" lib/* |sort -r) + thisdate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d @$timestamp) + expiredate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '+1 minute') + if [[ $thisdate == $HTTP_IF_MODIFIED_SINCE ]] + then + echo "Status: 304 Not Modified" + do_exit=1 + fi + echo "Last-Modified: $thisdate" + echo "Expires: $expiredate" + echo "Cache-Control: must-revalidate, max-age=60" + while read header + do + echo "$header" + done + echo + (( do_exit )) && exit +}