Comment on the effective meaning of ttl=0
[khatus.git] / bin / khatus_bar
index fed9b11..bddf0b9 100755 (executable)
@@ -4,6 +4,11 @@ BEGIN {
      FS = msg_fs ? msg_fs : "|"
     OFS = msg_fs ? msg_fs : "|"
     Kfs = key_fs ? key_fs : ":"
+
+    _total_to_diff["khatus_sensor_net_addr_io", "bytes_read"     ] = 1
+    _total_to_diff["khatus_sensor_net_addr_io", "bytes_written"  ] = 1
+    _total_to_diff["khatus_sensor_disk_io"    , "sectors_read"   ] = 1
+    _total_to_diff["khatus_sensor_disk_io"    , "sectors_written"] = 1
 }
 
 # -----------------------------------------------------------------------------
@@ -18,9 +23,6 @@ $2 == "khatus_sensor_datetime" {
     print_msg_ok("status_bar", make_status_bar())
 }
 
-# Let everything else through
-//
-
 # -----------------------------------------------------------------------------
 # Data
 # -----------------------------------------------------------------------------
@@ -36,7 +38,7 @@ function Data_update(    src, key, val, len_line, len_head, len_val, time) {
     len_val  = len_line - len_head
     val = substr($0, len_head + 1, len_val)
 
-    Data[src, key] = val
+    Data[src, key] = Data_maybe_total_to_diff(src, key, val)
     time = Data_get_time()
     M_time[src, key] = time
 
@@ -45,11 +47,12 @@ function Data_update(    src, key, val, len_line, len_head, len_val, time) {
     }
 }
 
-function Data_get(src, key, age_max,    time, age, is_expired) {
+function Data_get(src, key, ttl,    time, age, is_expired) {
     time = Data_get_time()
     A_time[src, key] = time
     age = time - M_time[src, key]
-    is_expired = age_max && age > age_max
+    # ttl = 0 => forever
+    is_expired = ttl && age > ttl
     return is_expired ? "" : Data[src, key]
 }
 
@@ -73,6 +76,17 @@ function Data_gc(    src_and_key, unused_for) {
     }
 }
 
+function Data_maybe_total_to_diff(src, key, val,    key_parts) {
+    split(key, key_parts, Kfs)
+    if (_total_to_diff[src, key_parts[1]]) {
+        _prev[src, key] = _curr[src, key]
+        _curr[src, key] = val
+        return (_curr[src, key] - _prev[src, key])
+    } else {
+        return val
+    }
+}
+
 # -----------------------------------------------------------------------------
 # Status bar
 # -----------------------------------------------------------------------------
This page took 0.021253 seconds and 4 git commands to generate.