From 8c587a0277216e4af9865dedfca249044c1ed875 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 22 Mar 2019 16:06:07 -0400 Subject: [PATCH] Add disk sensor --- x4/bin/khatus_x4_sensor_disk | 37 ++++++++++++++++++++++++++++++++++++ x4/sanity_check | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 x4/bin/khatus_x4_sensor_disk diff --git a/x4/bin/khatus_x4_sensor_disk b/x4/bin/khatus_x4_sensor_disk new file mode 100755 index 0000000..7beebd3 --- /dev/null +++ b/x4/bin/khatus_x4_sensor_disk @@ -0,0 +1,37 @@ +#! /bin/sh + +set -e + +bin_dir="$(dirname $(realpath $0))" + +. "$bin_dir/khatus_x4_lib_common_sensor.sh" + +while : +do + case "$1" + in '') + break + ;; -f|--file) + case "$2" + in '') + printf "Option $1 requires and argument\n" >&2 + exit 1 + ;; *) + file="$2" + shift 2 + esac + ;; *) + shift 1 + esac +done + +sensor() { + df --output=pcent "$file" | awk ' + NR == 2 { + sub("%$", "", $1) + print("disk_usage_percentage", $1) + } + ' +} + +run_as_poller diff --git a/x4/sanity_check b/x4/sanity_check index 125369a..749a3ea 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -23,6 +23,7 @@ sensors_fork_all() { ./bin/khatus_x4_sensor_memory & ./bin/khatus_x4_sensor_loadavg & ./bin/khatus_x4_sensor_temp -i 1 -- -z 0 & + ./bin/khatus_x4_sensor_disk -- -f / & } sensor_read_one() { @@ -46,7 +47,8 @@ sensors_read_all() { mem="$(sensor_read_one ${dir}/khatus_x4_sensor_memory/out/percent_used)" load="$(sensor_read_one ${dir}/khatus_x4_sensor_loadavg/out/load_avg_1min)" temp="$(sensor_read_one ${dir}/khatus_x4_sensor_temp/out/thermal_zone0)" - echo "E[${battery_state} ${battery_percentage}] M:${mem}% L:${load} T:${temp}°C [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}" + disk="$(sensor_read_one ${dir}/khatus_x4_sensor_disk/out/disk_usage_percentage)" + echo "E[${battery_state} ${battery_percentage}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}" sleep 1 done } -- 2.20.1