From 6f89e24d338937cf8e7aeac5c854b4f442181030 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 22 Mar 2019 14:48:00 -0400 Subject: [PATCH] Add memory sensor --- x4/bin/khatus_x4_sensor_memory | 20 ++++++++++++++++++++ x4/sanity_check | 4 +++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 x4/bin/khatus_x4_sensor_memory diff --git a/x4/bin/khatus_x4_sensor_memory b/x4/bin/khatus_x4_sensor_memory new file mode 100755 index 0000000..0bf6f0b --- /dev/null +++ b/x4/bin/khatus_x4_sensor_memory @@ -0,0 +1,20 @@ +#! /bin/sh + +set -e + +bin_dir="$(dirname $(realpath $0))" + +. "$bin_dir/khatus_x4_lib_common_sensor.sh" + +sensor() { + free | awk ' + $1 == "Mem:" { + total = $2 + used = $3 + percent_used = int(((used / total) * 100) + 0.5) # Average + print("percent_used", percent_used) + } + ' +} + +run_as_poller diff --git a/x4/sanity_check b/x4/sanity_check index af68cf6..a01a0c1 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -20,6 +20,7 @@ sensors_fork_all() { ./bin/khatus_x4_sensor_bluetooth& ./bin/khatus_x4_sensor_mpd & ./bin/khatus_x4_sensor_energy & + ./bin/khatus_x4_sensor_memory & } sensor_read_one() { @@ -40,7 +41,8 @@ sensors_read_all() { bluetooth_devices="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_connected_devices)" datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" - echo "E[${battery_state} ${battery_percentage}] [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}" + mem="$(sensor_read_one ${dir}/khatus_x4_sensor_memory/out/percent_used)" + echo "E[${battery_state} ${battery_percentage}] M:${mem}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}" sleep 1 done } -- 2.20.1