Skip to content

Commit d911d52

Browse files
committed
Fixed Memory Use Display Bug
Major - Corrected memory use bug that sometimes caused a negative value to be displayed (Issue #9) - Turned off the cursor display Minor - Added PID file output
1 parent fda9bce commit d911d52

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

chronometer2.sh

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Addresses Issue 5: https://github.com/jpmck/chronometer2/issues/5 ... I think...
77
export LC_ALL=C.UTF-8
88

9-
chronometer2Version="1.2.1"
9+
chronometer2Version="1.2.2"
1010

1111
# COLORS
1212
blueColor=$(tput setaf 6)
@@ -87,7 +87,9 @@ GetSystemInformation() {
8787
cpuPercent=$(printf %.1f "$(echo "scale=4; (${cpuLoad1}/${numProc})*100" | bc)")
8888

8989
# Memory use
90-
memoryUsedPercent=$(free | awk '/Mem/ {printf "%.1f",($2-$4-$6-$7)/$2 * 100}')
90+
# Corrects Issue #9 https://github.com/jpmck/chronometer2/issues/9
91+
# Thanks, Twiggy159 and WaLLy3K!
92+
memoryUsedPercent=$(awk '/MemTotal:/{total=$2} /MemFree:/{free=$2} /Buffers:/{buffers=$2} /^Cached:/{cached=$2} END {printf "%.1f", (total-free-buffers-cached)*100/total}' '/proc/meminfo')
9193

9294
# CPU temperature heatmap
9395
if [ ${cpu} -gt 60000 ]; then
@@ -365,6 +367,7 @@ normalChrono() {
365367
GetNetworkInformation
366368
GetVersionInformation
367369

370+
368371
sleep 5
369372
done
370373
}
@@ -384,6 +387,12 @@ EOM
384387
}
385388

386389
if [[ $# = 0 ]]; then
390+
391+
# Turns off the cursor
392+
# (From Pull request #8 https://github.com/jpmck/chronometer2/pull/8)
393+
setterm -cursor off
394+
trap "{ setterm -cursor on ; echo "" ; exit 0 ; }" SIGINT SIGTERM EXIT
395+
387396
clear
388397

389398
# Nice logo
@@ -395,7 +404,14 @@ if [[ $# = 0 ]]; then
395404
# Get Our Config Values
396405
. /etc/pihole/setupVars.conf
397406

398-
echo "START UP===================================================="
407+
echo "START UP ==================================================="
408+
409+
# Get PID of Chronometer2
410+
pid=$(echo $$)
411+
echo "- Writing PID (${pid}) to file..."
412+
echo ${pid} > ./chronometer2.pid
413+
414+
# Check for updates
399415
echo "- Checking for Chronometer2 version file..."
400416
if [ -e "piHoleVersion" ]; then
401417
echo " - Chronometer2 version file found... deleting."

0 commit comments

Comments
 (0)