Commit 5e7b6f2e authored by moli's avatar moli
Browse files

Update rrd.sh

parent 005aec75
......@@ -78,16 +78,16 @@ case "$1" in
case "$rrd_hostname" in
'moli-beebox')
rrd_graph_starts=('-90min' '-12h' '-4d' '-32d' '-1y')
rrd_graphs=('ram' 'load' "temp-$rrd_hostname" 'humid' 'net')
rrd_graphs=('ram' 'load' "temp-$rrd_hostname" 'humid' 'torrent')
rrd_graph_legend_width=12
rrd_graph_ram_height=60
rrd_graph_ram_total=6
rrd_graph_load_height=90
rrd_graph_temp_height=200
rrd_graph_net_height=50
rrd_graph_torrent_height=150
;;
'moli-desktop')
rrd_graph_starts=('-90min' '-12h' '-4d')
rrd_graph_starts=('-2h' '-1d' '-1w')
rrd_graphs=('ram' 'load' 'windows' "temp-$rrd_hostname" 'humid' "fan-$rrd_hostname")
rrd_graph_legend_width=12
rrd_graph_ram_height=80
......@@ -295,24 +295,6 @@ case "$1" in
fi
done
;;
'net')
rrd_graph_axis_lower=98
rrd_graph_axis_upper=100
i=0
for start in "${rrd_graph_starts[@]}"
do
if [ -n "$start" ]
then
i=$((i+1))
rrdtool $1 "$rrd_sharedir/${graph}_$i.png" --start "$start" $rrd_graph_opts --width "$rrd_graph_width" --height "$rrd_graph_net_height" --rigid --lower-limit "$rrd_graph_axis_lower" --upper-limit "$rrd_graph_axis_upper" --base 1000 --units-exponent 0 --right-axis-format '%2.0lf' \
DEF:net-google="$rrd_hostname-net-google.rrd":data:AVERAGE:reduce=AVERAGE \
COMMENT:"$rrd_graph_legend_spacer\s" \
AREA:net-google#FFD700:"internet\l" \
>/dev/null
fi
done
;;
'ram')
rrd_graph_axis_lower=0
rrd_graph_axis_upper="$rrd_graph_ram_total"
......@@ -388,6 +370,36 @@ case "$1" in
fi
done
;;
'torrent')
rrd_graph_axis_upper=100
i=0
for start in "${rrd_graph_starts[@]}"
do
if [ -n "$start" ]
then
i=$((i+1))
rrdtool $1 "$rrd_sharedir/${graph}_$i.png" --start "$start" $rrd_graph_opts --width "$rrd_graph_width" --height "$rrd_graph_torrent_height" --rigid --lower-limit 0 --upper-limit "$rrd_graph_axis_upper" --base 1000 --units-exponent 0 --right-axis-format '%3.0lf' \
DEF:torrent-up="$rrd_hostname-torrent-up.rrd":data:AVERAGE:reduce=AVERAGE \
DEF:torrent-up-max="$rrd_hostname-torrent-up.rrd":data:MAX:reduce=MAX \
DEF:torrent-down="$rrd_hostname-torrent-down.rrd":data:AVERAGE:reduce=AVERAGE \
DEF:torrent-down-max="$rrd_hostname-torrent-down.rrd":data:MAX:reduce=MAX \
DEF:net-google="$rrd_hostname-net-google.rrd":data:AVERAGE:reduce=AVERAGE \
CDEF:torrent-up-mbit=torrent-up,8,*,1024,/,1024,/ \
CDEF:torrent-up-max-mbit=torrent-up-max,8,*,1024,/,1024,/ \
CDEF:torrent-down-mbit=torrent-down,8,*,1024,/,1024,/ \
CDEF:torrent-down-max-mbit=torrent-down-max,8,*,1024,/,1024,/ \
CDEF:net-google-prop=net-google,"$rrd_graph_axis_upper",0,-,*,100,/,0,+ \
COMMENT:"$rrd_graph_legend_spacer\s" \
AREA:net-google-prop#FFD70040:"google\l" \
LINE1:torrent-up-max-mbit#778899 \
AREA:torrent-up-mbit#77889980:"up\l" \
LINE1:torrent-down-max-mbit#2F4F4F \
AREA:torrent-down-mbit#2F4F4F80:"down\l" \
>/dev/null
fi
done
;;
'traffic')
rrd_graph_axis_upper=100
......@@ -467,7 +479,8 @@ case "$1" in
'moli-desktop-indoor-temp' 'moli-desktop-indoor-temp2' \
'moli-desktop-outdoor-temp' 'moli-desktop-outdoor-temp2' 'moli-desktop-outdoor-temp3' 'moli-desktop-outdoor-temp4' 'moli-desktop-outdoor-temp5' \
'moli-desktop-outdoor-humid' 'moli-desktop-outdoor-humid2' 'moli-desktop-outdoor-humid3' 'moli-desktop-outdoor-humid4' 'moli-desktop-outdoor-humid5' \
'net-digi' )
'net-digi' \
'moli-beebox-torrent-ratio' )
rrd_gauges_avgmax=( 'moli-beebox-hdd-temp' 'moli-beebox-hdd-vid-temp' \
'moli-beebox-cpu-temp' 'moli-beebox-cpu1-temp' 'moli-beebox-cpu2-temp' 'moli-beebox-cpu3-temp' 'moli-beebox-cpu4-temp' \
'moli-beebox-sys-temp1' 'moli-beebox-sys-temp2' 'moli-beebox-sys-temp3' \
......@@ -479,6 +492,7 @@ case "$1" in
'moli-desktop-gpu-rpm' 'moli-desktop-sys-rpm1' 'moli-desktop-sys-rpm2' \
'moli-desktop-ram-used' 'moli-desktop-swap-used' 'moli-desktop-cpu-load1' 'moli-desktop-cpu-used' 'moli-desktop-gpu-used' )
rrd_gauges_avgminmax=( 'moli-beebox-indoor-humid' 'moli-desktop-indoor-humid' )
rrd_derives_avgmax=( 'moli-beebox-torrent-down' 'moli-beebox-torrent-up' )
rrd_derives_avgmax0=( 'net-down' 'net-up' )
;;
esac
......@@ -517,6 +531,12 @@ case "$1" in
then rrdtool $1 "$gauge.rrd" --no-overwrite --step 1 DS:data:GAUGE:1000:U:U $rrd_defAVERAGE $rrd_defMIN $rrd_defMAX
fi
done
for gauge in "${rrd_derives_avgmax[@]}"
do
if [ -n "$gauge" -a ! -f "$gauge.rrd" ]
then rrdtool $1 "$gauge.rrd" --no-overwrite --step 1 DS:data:DERIVE:1000:U:U $rrd_defAVERAGE $rrd_defMAX
fi
done
for gauge in "${rrd_derives_avgmax0[@]}"
do
if [ -n "$gauge" -a ! -f "$gauge.rrd" ]
......@@ -761,12 +781,12 @@ HEREDOC
'idokep')
rrd_gocr_opts="-p gocr/ -a 97 -m 6"
rrd_ocr_opts="-l eng -psm 8 nobatch digits"
rrd_users=( "${rrd_idokep_users[@]}" )
rrd_checkcmd gocr
rrd_checkcmd tesseract
rrd_checkcmd convert
for key in ${!rrd_users[@]}
......@@ -813,7 +833,7 @@ HEREDOC
enc="$(echo -n "$curl" | grep -Pio 'H.+?m.+?rs.+?klet\:\s*\<strong\>\<img\s+alt\=\"Embedded\s+Image\"\s*src\=\"data\:image\/png\;base64\,\K(.+?)(?=\"\>\s*.+?C)')"
if [ -n "$enc" ]
then
temp=$(echo -n "$enc" | base64 --decode | convert - -bordercolor white -border 10 pnm:- 2>/dev/null | gocr -i - -u '?' -f ASCII -C 0-9.-- $rrd_gocr_opts 2>/dev/null)
temp=$(echo -n "$enc" | base64 --decode | convert - -resize 400% -type grayscale -bordercolor white -border 10 tif:- 2>/dev/null | tesseract --tessdata-dir /usr/share/tesseract-ocr - - $rrd_ocr_opts 2>/dev/null)
err=$?
if [ $err -gt 0 ]
then echo -e "$(date '+%Y-%m-%d %H:%M:%S')\tERROR\tocr\t$err" >> "$rrd_logfile"
......@@ -825,11 +845,18 @@ HEREDOC
|| [ $(echo "$temp >= -89.2" | bc --mathlib 2>/dev/null) -ne 1 -o $(echo "$temp <= 56.7" | bc --mathlib 2>/dev/null) -ne 1 ]
then
echo -e "$(date '+%Y-%m-%d %H:%M:%S')\tERROR\tcontent invalid\ttemp\t$user" >> "$rrd_logfile"
file="debug/rrd-$1-gocr-error-$i-$date.png"
file="debug/rrd-$1-ocr-error-$i-$date.png"
if ! test -e "$file"
then echo -n "$enc" | base64 --decode > "$file"
fi
else
if test -n "$rrd_debug"
then
file="debug/rrd-$1-ocr-debug-$i-$date.png"
if ! test -e "$file"
then echo -n "$enc" | base64 --decode > "$file"
fi
fi
file="$rrd_sharedir/rrd-update-data-outdoor-temp$i.tsv"
curr=$(echo -en "$date\t$temp")
prev=$(cat "$file" 2>/dev/null)
......@@ -845,7 +872,7 @@ HEREDOC
enc="$(echo -n "$curl" | grep -Pio 'P.+?ratartalom\:\s*\<strong\>\<img\s+alt\=\"Embedded\s+Image\"\s*src\=\"data\:image\/png\;base64\,\K(.+?)(?=\"\>\s*.+?)')"
if [ -n "$enc" ]
then
humid=$(echo -n "$enc" | base64 --decode | convert - -bordercolor white -border 10 pnm:- 2>/dev/null | gocr -i - -u '?' -f ASCII -C 0-9.-- $rrd_gocr_opts 2>/dev/null)
humid=$(echo -n "$enc" | base64 --decode | convert - -resize 400% -type grayscale -bordercolor white -border 10 tif:- 2>/dev/null | tesseract --tessdata-dir /usr/share/tesseract-ocr - - $rrd_ocr_opts 2>/dev/null)
err=$?
if [ $err -gt 0 ]
then echo -e "$(date '+%Y-%m-%d %H:%M:%S')\tERROR\tocr\t$err" >> "$rrd_logfile"
......@@ -857,11 +884,18 @@ HEREDOC
|| [ $(echo "$humid >= 0" | bc --mathlib 2>/dev/null) -ne 1 -o $(echo "$humid <= 100" | bc --mathlib 2>/dev/null) -ne 1 ]
then
echo -e "$(date '+%Y-%m-%d %H:%M:%S')\tERROR\tcontent invalid\thumid\t$user" >> "$rrd_logfile"
file="debug/rrd-$1-gocr-error-$i-$date-humid.png"
file="debug/rrd-$1-ocr-error-$i-$date-humid.png"
if ! test -e "$file"
then echo -n "$enc" | base64 --decode > "$file"
fi
else
if test -n "$rrd_debug"
then
file="debug/rrd-$1-ocr-debug-$i-$date-humid.png"
if ! test -e "$file"
then echo -n "$enc" | base64 --decode > "$file"
fi
fi
file="$rrd_sharedir/rrd-update-data-outdoor-humid$i.tsv"
curr=$(echo -en "$date\t$humid")
prev=$(cat "$file" 2>/dev/null)
......@@ -889,6 +923,11 @@ HEREDOC
rrd_hostname='net'
return="$(curl --silent --max-time 4 --user "$rrd_tplink_auth" --referer "http://$rrd_tplink_address" "http://$rrd_tplink_address/userRpm/StatusRpm.htm")"
code=$?
if [ $code -ne 0 ]
then
echo -e "$(date '+%Y-%m-%d %H:%M:%S')\tERROR\ttplink curl error $code" >> "$rrd_logfile"
fi
if input="$(echo "$return" | tr -s '[:space:]' ' ' | grep -oP '<SCRIPT language="javascript" type="text/javascript"> var statistList = new Array\( [0-9]+, [0-9]+, [0-9]+, [0-9]+, 0,0 \); </SCRIPT>' )" \
&& [ -n "$input" ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment