-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneurio_no_pw_endpoint.sh
executable file
·71 lines (62 loc) · 1.79 KB
/
neurio_no_pw_endpoint.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
66
67
68
69
70
71
NEURIO_IP=
DISPLAY=:0
TEMP_DATA_FILE=$(mktemp)
TEMP_GNUPLOT_CONFIG_FILE=$(mktemp).gp
OUTPUT_TERMINAL_TYPE="${TERM_NAME:=x11}"
echo "temp data file location $TEMP_DATA_FILE"
echo "temp gnu plot config location $TEMP_GNUPLOT_CONFIG_FILE"
check_command() {
if command -v "$1" >/dev/null 2>&1; then
echo "$1 is installed"
else
echo "$1 is not installed"
fi
}
write_config() {
local file=$1
shift
while (( "$#" )); do
echo "$1" >> "$file"
shift
done
}
check_command curl
check_command jq
check_command gnuplot
: ${DISPLAY:=:0}
write_config "$TEMP_GNUPLOT_CONFIG_FILE" \
"set terminal ${OUTPUT_TERMINAL_TYPE}" \
"set datafile missing \"?\"" \
"set xdata time" \
"set timefmt \"%Y-%m-%d %H:%M:%S\"" \
"set format x \"%H:%M:%S\"" \
"set ytics font \"Times-Roman,36\"" \
"set xrange [time(0)-120:time(0)]" \
"set yrange [:]" \
"set lmargin at screen 0.1" \
"set rmargin at screen 0.9" \
"set bmargin at screen 0.1" \
"set tmargin at screen 0.9" \
"plot \""$TEMP_DATA_FILE"\" using 1:3 with lines" \
"pause 2" \
"reread"
echo "$DISPLAY"
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "$timestamp 100" >> "$TEMP_DATA_FILE"
gnuplot -p "$TEMP_GNUPLOT_CONFIG_FILE" &
fetch_and_process_data() {
local data
data=$(curl -s -X GET -H "Content-Type:application/json" "${NEURIO_IP}/current-sample" | jq '.channels[] | select(.type == "CONSUMPTION").p_W')
if [[ -n "$data" && "$data" -ne 0 ]]; then
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
echo "$timestamp $data" >> "$TEMP_DATA_FILE"
sleep 2
else
echo "$timestamp ?" >> "$TEMP_DATA_FILE"
logger "something went wrong with neurio datapoint $timestamp"
sleep 2
fi
}
while true; do
fetch_and_process_data
done