Add memory sensor
authorSiraaj Khandkar <siraaj@khandkar.net>
Fri, 22 Mar 2019 18:48:00 +0000 (14:48 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Fri, 22 Mar 2019 18:48:00 +0000 (14:48 -0400)
x4/bin/khatus_x4_sensor_memory [new file with mode: 0755]
x4/sanity_check

diff --git a/x4/bin/khatus_x4_sensor_memory b/x4/bin/khatus_x4_sensor_memory
new file mode 100755 (executable)
index 0000000..0bf6f0b
--- /dev/null
@@ -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
index af68cf6..a01a0c1 100755 (executable)
@@ -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
 }
This page took 0.02633 seconds and 4 git commands to generate.