-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_historical_graph.sh
executable file
·65 lines (52 loc) · 1.78 KB
/
create_historical_graph.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Create a graph for 2014's ccc dark data
# Example rrd commands
# rrdtool create --start 1417069500 --step 86400 n_orphans.rrd DS:n_orphans:GAUGE:432000:U:U RRA:LAST:0.5:1:30
# rrdtool update n_orphans.rrd 1417415108:16785761
# rrdtool graph n_orphans.png --start 1417069500 --end `date +%s` DEF:n_orphans=n_orphans.rrd:n_orphans:LAST LINE2:n_orphans#FF0000
set -e
if [ "$#" -ne 3 ]; then
echo "Usage: $0 dir name datatype"
echo "See parse_from_ccc.sh for datatypes"
exit
fi
DATATYPE=$3
NAME=$2
PAGEDIR=$1
GRAPHNAME=./output/graphs/$NAME.rrd
PNGNAME=./output/graphs/$NAME.png
TITLE="CCC - $DATATYPE ($NAME)"
VERTLABEL="# of dq2 orphans"
HORIZLABEL=""
# Get the start and end times
oldest=$(ls -t $PAGEDIR/ccc-*html | tail -1)
STARTTIME=`expr $(./parse_from_ccc.sh $oldest time) - 1`
newest=$(ls -t $PAGEDIR/ccc-*html | head -1)
ENDTIME=`expr $(./parse_from_ccc.sh $newest time) + 1`
echo "Start time: $STARTTIME | End time: $ENDTIME"
# Remove the old graph
[ -e $GRAPHNAME ] && rm $GRAPHNAME
# Create the graph
rrdtool create $GRAPHNAME --start $STARTTIME --step 86400 DS:n_orphans:GAUGE:432000:0:U RRA:AVERAGE:.5:1:365
# Update the graph with each page's information
for file in $(ls $PAGEDIR/ccc-*.html)
do
time=`./parse_from_ccc.sh $file time`
echo $file $DATATYPE
data=`./parse_from_ccc.sh $file $DATATYPE`
[ -z $data ] && data="U" # If there's no data, set it to be unknown
# Update the graph
rrdtool update $GRAPHNAME $time:$data
echo "Updated graph $GRAPHNAME with $data at $time"
done
# Create the png
rrdtool graph $PNGNAME \
--start $STARTTIME \
--end $ENDTIME \
--title $TITLE \
--width 500 \
--height 120 \
--alt-autoscale-max \
--vertical-label $VERTLABEL \
--horizontal-label $HORIZLABEL \
DEF:n_orphans=$GRAPHNAME:n_orphans:AVERAGE \
LINE:n_orphans#FF0000