-
Notifications
You must be signed in to change notification settings - Fork 38
/
telegraf_input_readsb_protoc_range.sh
executable file
·49 lines (37 loc) · 1.24 KB
/
telegraf_input_readsb_protoc_range.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
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# Get stats from protoc
# Write to file so we don't have to run protoc many times
protoc --proto_path="$READSB_PROTO_PATH" --decode Statistics readsb.proto < "$READSB_STATS_PB_FILE" > /tmp/.protoc_readsb_range_out
# Turn stats we care about (last_1min) into array
mapfile -t stats_from_protoc < <( \
grep -A 999 'polar_range {' /tmp/.protoc_readsb_range_out | \
grep -B 999 '}' | \
grep -v '{' | \
grep -v '}' | \
tr -d " ")
declare -A range
bearing=0
for stat in "${stats_from_protoc[@]}"; do
key=$(echo "$stat" | cut -d ':' -f 1)
value=$(echo "$stat" | cut -d ':' -f 2)
if [[ "$key" == "key" ]]; then
bearing="$value"
range[$bearing]=0
elif [[ "$key" == "value" ]]; then
range[$bearing]="$value"
else
continue
fi
done
# Prepare timestamp - add timestamp
# ms μs ns
timestamp="$(($(date +%s)*1000*1000*1000))"
# Prepare output - add ranges in reverse (see issue #19 - https://github.com/mikenye/docker-readsb-protobuf/issues/19)
bearing=0
for key in {71..0}; do
# Prepare output - add measurement
output="polar_range,bearing=$(printf "%.2d " "$bearing") range=${range[$key]} $timestamp"
echo "$output"
bearing=$((bearing+1))
done