Show graphics card (NVIDIA) temp and mem usage
[khatus.git] / bin / khatus_show
index da35e6e..c0a41a1 100755 (executable)
@@ -7,9 +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
 
-SYMBOL_WIFI='📶'
-
-#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)
 
@@ -40,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 = ">";
@@ -65,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
         }
@@ -93,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
 )
@@ -162,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)
@@ -314,21 +342,55 @@ mpd_state=$(
         '
 )
 
+mpd_current_file=$(
+    echo 'currentsong' \
+    | nc 127.0.0.1 6600 \
+    | awk -v max_chars=10 '
+        /^file:/ {
+            file = $2
+            for (i=3; i<=NF; i++) {file = file " " $i}
+            last = split(file, parts, "/")
+            print substr(parts[last], 1, max_chars)
+        }
+        '
+)
+
+graphics_card=$(
+    nvidia-smi \
+        --format=csv,noheader,nounits \
+        --query-gpu=memory.total,memory.used,temperature.gpu \
+    | awk -F ',' '
+        {
+            mem_total = $1;
+            mem_used  = $2;
+            temp      = $3;
+            mem_used_percent = (100 * mem_used) / mem_total;
+            printf("[%d%% %dC]", mem_used_percent, temp);
+        }
+        '
+)
+
 echo \
 "\
  E$energy\
  \
  \
+ G=$graphics_card\
+ \
+ \
  M$memory\
  \
  \
  C=[$cpu  ${temp}°C ${fan}rpm]\
  \
  \
+ L=$load\
+ \
+ \
  D$disk\
  \
  \
$SYMBOL_WIFI [$wifi $(echo "$io_net" | awk '/^wlp3s0/ {print $2, $3}')]\
N:$network\
  \
  \
  B:$bluetooth_power\
@@ -339,7 +401,7 @@ echo \
  \
  V=$volume\
  \
$mpd_state\
[$mpd_state $mpd_current_file]\
  \
  $signal_last_msg_age\
  \
This page took 0.040566 seconds and 4 git commands to generate.