-
Notifications
You must be signed in to change notification settings - Fork 43
/
scatter.sh
executable file
·58 lines (39 loc) · 1.86 KB
/
scatter.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
#!/bin/bash
DB=/var/lib/collectd/rrd
# settings in /etc/default/graphs1090 will overwrite the DB directory
source /etc/default/graphs1090
if [[ -z "$enable_scatter" ]] || [[ "$enable_scatter" == "no" ]]; then
exit 0
fi
# Fetch a day worth of data from the rrds
data_dir=/var/lib/graphs1090/scatter
tmp=/run/graphs1090/scatter
mkdir -p ${tmp}
date=$(date -I --date=yesterday)
endtime="midnight today"
if ! [ -z $1 ]; then
date=$(date -I --date=-${1}days)
endtime="midnight tomorrow -${1}days"
fi
rrdtool fetch ${DB}/localhost/dump1090-localhost/dump1090_messages-local_accepted.rrd AVERAGE -s end-1439m -e "$endtime" -r 3m -a > ${tmp}/messages_l
rrdtool fetch ${DB}/localhost/dump1090-localhost/dump1090_messages-remote_accepted.rrd AVERAGE -s end-1439m -e "$endtime" -r 3m -a > ${tmp}/messages_r
rrdtool fetch ${DB}/localhost/dump1090-localhost/dump1090_range-max_range.rrd MAX -s end-1439m -e "$endtime" -r 3m -a > ${tmp}/range
rrdtool fetch ${DB}/localhost/dump1090-localhost/dump1090_aircraft-recent.rrd AVERAGE -s end-1439m -e "$endtime" -r 3m -a > ${tmp}/aircraft
# Remove headers and extraneous :
sed -i -e 's/://' -e 's/\,/\./g' ${tmp}/messages_l
sed -i -e 's/://' -e 's/\,/\./g' ${tmp}/messages_r
sed -i -e 's/://' -e 's/\,/\./g' ${tmp}/range
sed -i -e 's/://' -e 's/\,/\./g' ${tmp}/aircraft
sed -i -e '1d;2d' ${tmp}/messages_l
sed -i -e '1d;2d' ${tmp}/messages_r
sed -i -e '1d;2d' ${tmp}/range
sed -i -e '1d;2d' ${tmp}/aircraft
# Combine files to create space separated data file for use by gnuplot
join -o 1.1 1.2 2.2 ${tmp}/range ${tmp}/messages_l > ${tmp}/tmp
join -o 1.1 1.2 1.3 2.2 ${tmp}/tmp ${tmp}/messages_r > ${tmp}/tmp1
join -o 1.2 1.3 1.4 2.2 ${tmp}/tmp1 ${tmp}/aircraft > $data_dir/$date
# get rid of nan values to simplify usage in gnuplot
sed -i 's/nan/0/g' $data_dir/$date
# some cleanup
rm -f $(find $data_dir -type f | sort | head -n-450)
rm -rf "${tmp}"