X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_bar;h=ed3d8c4a8abc917124bbefa653dd6017161fd5d6;hb=f2273cab04f5f7b9188b9bd62b0e7be928054c28;hp=fed9b11d3d0b999037a678c36803ae1bb4a9222b;hpb=8ab38d67c4dbbd640673a47d44ad4c87da223090;p=khatus.git diff --git a/bin/khatus_bar b/bin/khatus_bar index fed9b11..ed3d8c4 100755 --- a/bin/khatus_bar +++ b/bin/khatus_bar @@ -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,11 @@ 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 + is_expired = ttl && age > ttl return is_expired ? "" : Data[src, key] } @@ -73,6 +75,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 # -----------------------------------------------------------------------------