Merge remote-tracking branch 'origin/master' into prod

* origin/master:
  Implement 304 Not Modified
  use $rrdfile everywhere

Conflicts:
	import
	index
This commit is contained in:
Vincent Riquer 2015-02-01 22:28:52 +01:00
commit 1d04dec062
6 changed files with 48 additions and 37 deletions

8
add
View File

@ -64,13 +64,13 @@ do
ds="${ds//ds[/}" ds="${ds//ds[/}"
ds="${ds//]*/}" ds="${ds//]*/}"
datasets+=("$ds") datasets+=("$ds")
done < <(rrdtool info ingress.rrd |grep index) done < <(rrdtool info "$rrdfile" |grep index)
for ds in ${dsnames[@]} for ds in ${dsnames[@]}
do do
if [[ ! ${datasets[@]} =~ $ds ]] if [[ ! ${datasets[@]} =~ $ds ]]
then then
cp -f ingress.rrd ingress.rrd.bak_add_$ds cp -f "$rrdfile" "$rrdfile".bak_add_$ds
./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN ./dsaddtor.pl "$rrdfile" $ds GAUGE $((48*60*60)) 0 NaN
fi fi
done done
data=N data=N
@ -82,7 +82,7 @@ do
done done
echo ${POST["innovator"]} > .innovator echo ${POST["innovator"]} > .innovator
rrdtool update ingress.rrd -t $template "$data" rrdtool update "$rrdfile" -t $template "$data"
if [ -n "$CACHE_DIR" ] if [ -n "$CACHE_DIR" ]
then then

View File

@ -24,11 +24,10 @@ do
done done
read_query_string read_query_string
send_headers <<-EOHead
content-type: text/xml
EOHead
cat <<-EOHTML 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')
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

17
import
View File

@ -66,21 +66,20 @@ then
ds="${ds//ds[/}" ds="${ds//ds[/}"
ds="${ds//]*/}" ds="${ds//]*/}"
datasets+=("$ds") datasets+=("$ds")
done < <(rrdtool info ingress.rrd |grep index) done < <(rrdtool info "$rrdfile" |grep index)
for ds in ${dsnames[@]} for ds in ${dsnames[@]}
do do
if [[ ! ${datasets[@]} =~ $ds ]] if [[ ! ${datasets[@]} =~ $ds ]]
then then
[[ -f ingress.rrd.bak ]] && mv ingress.rrd.bak ingress.rrd.bak_before_add_$ds cp -f "$rrdfile" "$rrdfile".bak_add_$ds
cp -f ingress.rrd ingress.rrd.bak_add_$ds ./dsaddtor.pl "$rrdfile" $ds GAUGE $((48*60*60)) 0 NaN
./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN 2>&1
fi fi
done done
while read date hour data while read date hour data
do do
data=$(date -d "$date $hour" +%s):${data// /:} 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"]}" done <<<"${POST["data"]}"
if [ -n "$CACHE_DIR" ] if [ -n "$CACHE_DIR" ]
@ -89,11 +88,11 @@ then
echo $'\nCache cleared!' echo $'\nCache cleared!'
fi fi
else else
cat <<-EOHTML send_headers <<-EOHead
content-type: text/xml content-type: text/xml
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') EOHead
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
cat <<-EOHTML
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@ -107,7 +106,7 @@ else
EOHTML EOHTML
if ! [ -w "$rrdfile" ] if ! [ -w "$rrdfile" ]
then then
rrdtool create ingress.rrd -s $((60*60)) \ rrdtool create "$rrdfile" -s $((60*60)) \
DS:AP:GAUGE:$((2*24*60*60)):0:NaN \ DS:AP:GAUGE:$((2*24*60*60)):0:NaN \
DS:Explorer:GAUGE:$((48*60*60)):0:NaN \ DS:Explorer:GAUGE:$((48*60*60)):0:NaN \
DS:Seer:GAUGE:$((48*60*60)):0:NaN \ DS:Seer:GAUGE:$((48*60*60)):0:NaN \

27
index
View File

@ -39,6 +39,11 @@ read_query_string
if [ -z "$graph" ] if [ -z "$graph" ]
then then
send_headers <<-EOHead
content-type: application/xhtml+xml
refresh: 300
EOHead
readlast readlast
medals medals
get_current_level get_current_level
@ -54,14 +59,6 @@ then
title="IngRRD - $webuser [L$curlevel] - Overview" title="IngRRD - $webuser [L$curlevel] - Overview"
fi fi
cat <<-EOHTML 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: 300
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@ -376,7 +373,7 @@ then
<table style="width:$(( graph_width + 97 ))px"> <table style="width:$(( graph_width + 97 ))px">
<tr> <tr>
<td> <td>
<a href="?hist&amp;start=$(rrdtool first ingress.rrd)&amp;end=$end">First</a> <a href="?hist&amp;start=$(rrdtool first "$rrdfile")&amp;end=$end">First</a>
<a href="?hist&amp;start=$(( start - 365 * 86400 ))&amp;end=$end">-Y</a> <a href="?hist&amp;start=$(( start - 365 * 86400 ))&amp;end=$end">-Y</a>
<a href="?hist&amp;start=$(( start - 30 * 86400 ))&amp;end=$end">-M</a> <a href="?hist&amp;start=$(( start - 30 * 86400 ))&amp;end=$end">-M</a>
<a href="?hist&amp;start=$(( start - 604800 ))&amp;end=$end">-W</a> <a href="?hist&amp;start=$(( start - 604800 ))&amp;end=$end">-W</a>
@ -479,17 +476,11 @@ then
</body></html> </body></html>
EOHTML EOHTML
else else
now=$(date +%s) send_headers <<-EOHead
cat <<-EOHEAD
content-type: image/png content-type: image/png
Last-Modified: $( EOHead
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
now=$(date +%s)
if [[ $graph == AP ]] if [[ $graph == AP ]]
then then
thresholds=( thresholds=(

View File

@ -18,6 +18,6 @@ readold() {
done done
) )
} < <( } < <(
rrdtool fetch -s "$when" ingress.rrd AVERAGE | sed '/: nan/d' rrdtool fetch -s "$when" "$rrdfile" AVERAGE | sed '/: nan/d'
) )
} }

22
lib/send_headers Normal file
View File

@ -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
}