Show 1min load avg
[khatus.git] / bin / khatus_show
index d506d3a..03ad6a9 100755 (executable)
@@ -7,7 +7,7 @@ STATUS_DIR=$HOME/var/run/status
 STATUS_FILE__WIFI=$STATUS_DIR/wifi
 STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF=$STATUS_DIR/notified_energy_bellow_half
 
-#load=$(cat /proc/loadavg | awk '{printf "%4.2f %4.2f %4.2f", $1, $2, $3}')
+load=$(awk '{printf("%4.2f", $1)}' /proc/loadavg)
 
 fan=$(awk '/^speed:/ {printf "%4d", $2}' /proc/acpi/ibm/fan)
 
@@ -38,23 +38,49 @@ memory=$(
 
 temp=$(awk 'NR == 1 {print $1 / 1000}' /sys/class/thermal/thermal_zone0/temp)
 
+disk_io=$(
+    awk '
+        {
+            bytes_per_sector = 512
+            bytes_per_unit   = 1024 * 1024
+
+            curr_sectors_read  = $3
+            curr_sectors_write = $7
+
+            prev_file_prefix        = "/home/siraaj/var/run/status/disk_io"
+            prev_sectors_read_file  = prev_file_prefix "_sectors_read"
+            prev_sectors_write_file = prev_file_prefix "_sectors_write"
+
+            getline prev_sectors_read  < prev_sectors_read_file
+            getline prev_sectors_write < prev_sectors_write_file
+
+            diff_read_sectors  = (curr_sectors_read  - prev_sectors_read)
+            diff_write_sectors = (curr_sectors_write - prev_sectors_write)
+
+            diff_read_bytes  = diff_read_sectors  * bytes_per_sector
+            diff_write_bytes = diff_write_sectors * bytes_per_sector
+
+            diff_read  = diff_read_bytes  / bytes_per_unit
+            diff_write = diff_write_bytes / bytes_per_unit
+
+            print curr_sectors_read  > prev_sectors_read_file
+            print curr_sectors_write > prev_sectors_write_file
+
+            printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
+
+        }
+        ' /sys/block/dm-1/stat
+)
+
 disk=$(
     df \
-    | awk '
+    | awk -v disk_io="$disk_io" '
         function round(n) {return int(n + 0.5)}
 
         $1 == "/dev/mapper/kubuntu--vg-root" {
-            curr_blocks = $3;
             curr_perc = $5; sub("%$", "", curr_perc);
-            prev_file_prefix = "/home/siraaj/var/run/status/disk_space_used";
-
-            prev_perc_file   = prev_file_prefix "_percentage";
-            prev_blocks_file = prev_file_prefix "_blocks";
-
-            getline prev_blocks < prev_blocks_file;
+            prev_perc_file = "/home/siraaj/var/run/status/disk_space_used";
             getline prev_perc   < prev_perc_file;
-
-            print curr_blocks > prev_blocks_file;
             print curr_perc > prev_perc_file;
             if (curr_perc > prev_perc) {
                 direction = ">";
@@ -63,12 +89,11 @@ disk=$(
             } else {
                 direction = "=";
             }
-            diff_blocks = curr_blocks - prev_blocks;
-            printf("%s[%d%% %d]", direction, curr_perc, diff_blocks);
+            printf("%s[%d%% %s]", direction, curr_perc, disk_io);
         }')
 
-io_net=$(
-    awk '
+network=$(
+    awk -v wifi_conn=$(cat $STATUS_FILE__WIFI) '
         BEGIN {
             bytes_per_unit = 1024 * 1024
         }
@@ -91,7 +116,14 @@ io_net=$(
             print curr_read  > prev_read_file;
             print curr_write > prev_write_file;
 
-            printf("%s %0.3f▲ %0.3f▼\n", device, diff_write, diff_read);
+            devices[device] = sprintf("%0.3f▲ %0.3f▼", diff_write, diff_read);
+        }
+
+        END {
+            lo   = devices["lo"]
+            #eth = devices["enp0s25"]
+            wifi = devices["wlp3s0"]
+            printf("[%s | %s %s]", lo, wifi_conn, wifi)
         }
     ' /proc/net/dev
 )
@@ -160,8 +192,6 @@ volume_pactl=$(
 
 volume="[$volume_pactl]"
 
-wifi=$(cat $STATUS_FILE__WIFI)
-
 screen_brightness=$(
     max=$(cat /sys/class/backlight/acpi_video0/max_brightness)
     cur=$(cat /sys/class/backlight/acpi_video0/brightness)
@@ -289,6 +319,29 @@ signal_last_msg_age=$(
     | tr -d ' '
 )
 
+mpd_state=$(
+    echo 'status' \
+    | nc 127.0.0.1 6600 \
+    | awk '
+        {
+            status[$1] = $2
+        }
+
+        END {
+            state = status["state:"]
+            symbol = "-"
+            if (state == "play") {
+                symbol = "▶"
+            } else if (state == "pause") {
+                symbol = "❚❚"
+            } else if (state == "stop") {
+                symbol = "⬛"
+            }
+            printf("%s", symbol)
+        }
+        '
+)
+
 echo \
 "\
  E$energy\
@@ -297,23 +350,27 @@ echo \
  M$memory\
  \
  \
D$disk\
C=[$cpu  ${temp}°C ${fan}rpm]\
  \
  \
C=[$cpu  ${temp}°C ${fan}rpm]\
L=$load\
  \
  \
S=$screen_brightness\
D$disk\
  \
  \
V=$volume\
N:$network\
  \
  \
  B:$bluetooth_power\
  \
  \
- W:[$wifi $(echo "$io_net" | awk '/^wlp3s0/ {print $2, $3}')]\
+ S=$screen_brightness\
+ \
+ \
+ V=$volume\
  \
+ $mpd_state\
  \
  $signal_last_msg_age\
  \
This page took 0.04881 seconds and 4 git commands to generate.