X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_bar;h=b8e47e610b160d6cb2c289bd4556d37bbf97fd25;hb=2e820ad561199f2ccc1ee3fa7e7e708e5dc8bc39;hp=bd31283b437ec3451e98acc67e241bccd2cbfc81;hpb=224be98a3467adc3171247eeaf9df8a37b76c062;p=khatus.git diff --git a/bin/khatus_bar b/bin/khatus_bar index bd31283..b8e47e6 100755 --- a/bin/khatus_bar +++ b/bin/khatus_bar @@ -13,6 +13,7 @@ BEGIN { FS = msg_fs ? msg_fs : "|" OFS = msg_fs ? msg_fs : "|" Kfs = key_fs ? key_fs : ":" + GC_Interval = GC_Interval ? GC_Interval : 3600 # seconds _total_to_diff["khatus_sensor_net_addr_io", "bytes_read" ] = 1 _total_to_diff["khatus_sensor_net_addr_io", "bytes_written" ] = 1 @@ -44,6 +45,8 @@ $1 == "OK" { $1 == "OK" && \ $2 == "khatus_sensor_datetime" { + # Code for make_status_bar definition is expected to be passed as an + # additional source file, using -f flag. print_msg_ok("status_bar", make_status_bar()) } @@ -65,7 +68,7 @@ function cache_update( src, key, val, len_line, len_head, len_val, time) { _cache[src, key] = val time = cache_get_time() _cache_mtime[src, key] = time - if (time % 3600 == 0) { + if (time % GC_Interval == 0) { cache_gc() } } @@ -96,14 +99,22 @@ function cache_get_time( src, key, time) { return time } -function cache_gc( src_and_key, unused_for) { +function cache_gc( src_and_key, parts, src, key, unused_for) { for (src_and_key in _cache) { - unused_for = cache_get_time() - _cache_atime[src_and_key] - if (unused_for > 3600) { + split(src_and_key, parts, SUBSEP) + src = parts[1] + key = parts[2] + val = _cache[src, key] + unused_for = cache_get_time() - _cache_atime[src, key] + if (unused_for > GC_Interval) { print_msg_info(\ - "cache_gc", "Deleting unused src_and_key: " src_and_key \ + "cache_gc", + sprintf(\ + "Deleting unused data SRC=%s KEY=%s VAL=%s", + src, key, val\ + ) \ ) - delete _cache[src_and_key] + delete _cache[src, key] } } } @@ -132,29 +143,6 @@ function cache_maybe_scale(src, key, val, key_parts) { # Status bar # ----------------------------------------------------------------------------- -function make_status_bar( position, bar, sep, i, j) { - position[++i] = "" - position[++i] = make_status_energy() - position[++i] = make_status_mem() - position[++i] = make_status_cpu() - position[++i] = make_status_disk() - position[++i] = make_status_net() - position[++i] = make_status_bluetooth() - position[++i] = make_status_screen_brightness() - position[++i] = make_status_volume() - position[++i] = make_status_mpd() - position[++i] = make_status_weather() - position[++i] = make_status_datetime() - position[++i] = "" - bar = "" - sep = "" - for (j = 1; j <= i; j++) { - bar = bar sep position[j] - sep = " " - } - return bar -} - function make_status_energy( state, charge, direction_of_change) { cache_get(state , "khatus_sensor_energy", "battery_state" , 0) cache_get(charge, "khatus_sensor_energy", "battery_percentage", 0) @@ -186,6 +174,30 @@ function make_status_mem( total, used, percent, status) { return sprintf("M=%s", status) } +function make_status_procs() { + # From man ps: + # D uninterruptible sleep (usually IO) + # R running or runnable (on run queue) + # S interruptible sleep (waiting for an event to complete) + # T stopped by job control signal + # t stopped by debugger during the tracing + # W paging (not valid since the 2.6.xx kernel) + # X dead (should never be seen) + # Z defunct ("zombie") process, terminated but not reaped by its parent + # + # Additionally, not documented in ps man page: + # I Idle + # + src = "khatus_sensor_procs" + all = cache_get_fmt_def(src, "total_procs" , 15, "%d") + r = cache_get_fmt_def(src, "total_per_state" Kfs "R", 15, "%d", "0") + d = cache_get_fmt_def(src, "total_per_state" Kfs "D", 15, "%d", "0") + t = cache_get_fmt_def(src, "total_per_state" Kfs "T", 15, "%d", "0") + i = cache_get_fmt_def(src, "total_per_state" Kfs "I", 15, "%d", "0") + z = cache_get_fmt_def(src, "total_per_state" Kfs "Z", 15, "%d", "0") + return sprintf("P=[%s %sr %sd %st %si %sz]", all, r, d, t, i, z) +} + function make_status_cpu( l, t, f) { l_src = "khatus_sensor_loadavg" t_src = "khatus_sensor_temperature"