Limit loggers report to top 5
[khome.git] / home / lib / login_functions.sh
index 6646365..8057711 100644 (file)
@@ -375,10 +375,14 @@ run() {
 bar_gauge() {
     awk "$@" '
         BEGIN {
+            # CLI options
+            width    = width    ? width    : 80
             ch_left  = ch_left  ? ch_left  : "["
             ch_right = ch_right ? ch_right : "]"
             ch_blank = ch_blank ? ch_blank : "-"
             ch_used  = ch_used  ? ch_used  : "|"
+            num      = num      ? 1        : 0
+            pct      = pct      ? 1        : 0
         }
 
         {
@@ -443,7 +447,6 @@ indent() {
 }
 
 motd() {
-    local -r bar_width='60'
     local -r indent_unit='    '
 
     uname -srvmo
@@ -464,7 +467,7 @@ motd() {
         df ~ | awk 'NR == 2 {print $3, $3 + $4, "disk"}'
         motd_batt
     ) \
-    | bar_gauge -v width="$bar_width" -v pct=1 \
+    | bar_gauge -v width=60 -v pct=1 \
     | column -t \
     | indent "$indent_unit"
 
@@ -546,7 +549,27 @@ motd() {
 
     echo
 
-    echo 'Loggers'
+    echo 'Process owners'
+    ps -eo user \
+    | awk '
+        NR > 1 {
+            count_by_user[$1]++
+            total++
+        }
+
+        END {
+            for (user in count_by_user)
+                print count_by_user[user], total, user
+        }
+        ' \
+    | sort -n -k 1 -r \
+    | bar_gauge -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \
+    | column -t \
+    | indent "${indent_unit}"
+
+    echo
+
+    echo 'Loggers (top 5)'
     awk '
         {
             split($5, prog, "[")
@@ -566,6 +589,7 @@ motd() {
                 print count[prog], total, prog
         }' \
     | sort -n -k 1 -r \
+    | head -5 \
     | bar_gauge -v width=30 -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \
     | column -t \
     | indent "${indent_unit}"
This page took 0.027055 seconds and 4 git commands to generate.