Monitor process states totals
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 22 Aug 2018 14:34:39 +0000 (10:34 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 22 Aug 2018 14:34:39 +0000 (10:34 -0400)
bin/khatus
bin/khatus_bar
bin/khatus_parse_ps [new file with mode: 0755]
bin/khatus_sensor_procs [new file with mode: 0755]
sanity_check

index 95bd517..747fd32 100755 (executable)
@@ -99,6 +99,7 @@ main() {
         ["--fan_path"]='/proc/acpi/ibm/fan'
         ["--pulseaudio_sink"]='0'
         ["--interval_datetime"]=1
+        ["--interval_procs"]=1
         ["--interval_brightness"]=1
         ["--interval_weather"]=$(( 30 * 60))  # 30 minutes
         ["--interval_mpd"]=1
@@ -189,6 +190,7 @@ main() {
     fork_watcher                                           "$pipe" "$bin" "khatus_sensor_energy $bin"
     fork_watcher                                           "$pipe" "$bin" "khatus_sensor_devices $bin"
     fork_poller "${opts['--interval_datetime']}"   "$perf" "$pipe" "$bin" khatus_sensor_datetime
+    fork_poller "${opts['--interval_procs']}"      "$perf" "$pipe" "$bin" "khatus_sensor_procs $bin"
     fork_poller "${opts['--interval_brightness']}" "$perf" "$pipe" "$bin" "$cmd_sens_screen_brightness"
     fork_poller "${opts['--interval_weather']}"    "$perf" "$pipe" "$bin" "$cmd_sens_weather"
     fork_poller "${opts['--interval_mpd']}"        "$perf" "$pipe" "$bin" "$cmd_sens_mpd"
index 2c7ee32..6fa05ba 100755 (executable)
@@ -102,11 +102,15 @@ function cache_gc(    src_and_key, parts, src, key, unused_for) {
         split(src_and_key, parts, SUBSEP)
         src = parts[1]
         key = parts[2]
+        val = _cache[src, key]
         unused_for = cache_get_time() - _cache_atime[src, key]
         if (unused_for > GC_Interval) {
             print_msg_info(\
                 "cache_gc",
-                sprintf("Deleting unused data SRC=%s KEY=%s", src, key) \
+                sprintf(\
+                    "Deleting unused data SRC=%s KEY=%s VAL=%s",
+                    src, key, val\
+                ) \
             )
             delete _cache[src, key]
         }
@@ -141,6 +145,7 @@ function make_status_bar(    position, bar, sep, i, j) {
     position[++i] = ""
     position[++i] = make_status_energy()
     position[++i] = make_status_mem()
+    position[++i] = make_status_procs()
     position[++i] = make_status_cpu()
     position[++i] = make_status_disk()
     position[++i] = make_status_net()
@@ -191,6 +196,17 @@ function make_status_mem(    total, used, percent, status) {
     return sprintf("M=%s", status)
 }
 
+function make_status_procs() {
+    src = "khatus_sensor_procs"
+    all = cache_get_fmt_def(src, "total_procs"            , 15, "%d")
+    r   = cache_get_fmt_def(src, "total_per_state" Kfs "R", 15, "%d", "0")
+    d   = cache_get_fmt_def(src, "total_per_state" Kfs "D", 15, "%d", "0")
+    t   = cache_get_fmt_def(src, "total_per_state" Kfs "T", 15, "%d", "0")
+    i   = cache_get_fmt_def(src, "total_per_state" Kfs "I", 15, "%d", "0")
+    z   = cache_get_fmt_def(src, "total_per_state" Kfs "Z", 15, "%d", "0")
+    return sprintf("P=[%s %sr %sd %st %si %sz]", all, r, d, t, i, z)
+}
+
 function make_status_cpu(    l, t, f) {
     l_src = "khatus_sensor_loadavg"
     t_src = "khatus_sensor_temperature"
diff --git a/bin/khatus_parse_ps b/bin/khatus_parse_ps
new file mode 100755 (executable)
index 0000000..3b8417e
--- /dev/null
@@ -0,0 +1,27 @@
+#! /usr/bin/awk -f
+
+BEGIN {
+    OFS = "|"
+    Kfs = ":"
+}
+
+{
+    pid       = $1
+    state     = $2
+    rss       = $3
+    command_i = index($0, $4)
+    command   = substr($0, command_i, length($0) - (command_i - 1))
+
+    Pids[pid] = 1
+    Total_Per_State[state]++
+    print("state"   Kfs pid, state)
+    print("rss"     Kfs pid, rss)
+    print("command" Kfs pid, command)
+}
+
+END {
+    print("total_procs", length(Pids))
+    for (state in Total_Per_State) {
+        print("total_per_state" Kfs state, Total_Per_State[state])
+    }
+}
diff --git a/bin/khatus_sensor_procs b/bin/khatus_sensor_procs
new file mode 100755 (executable)
index 0000000..7083d81
--- /dev/null
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+set -e
+
+dir_bin="$1"
+
+ps -eo pid,state,rss,command ww --no-headers | "$dir_bin"/khatus_parse_ps
index c10dcaf..fdcb394 100755 (executable)
@@ -8,7 +8,7 @@
         -v Opt_Mpd_Song_Max_Chars=10 \
         -v Opt_Net_Interfaces_To_Show=wlp3s0 \
         -v Opt_Pulseaudio_Sink=0 \
-        -v GC_Interval=5 \
+        -v GC_Interval=10 \
     ) \
     >(stdbuf -o L ./bin/khatus_monitor_energy) \
     >(stdbuf -o L ./bin/khatus_monitor_errors) \
This page took 0.041266 seconds and 4 git commands to generate.