# Naming convention:
# Variables:
# - global, builtin : ALLCAPS
-# - global, public : CamelCase
+# - global, public : Camel_Snake_Man_Bear_Pig
# - global, private : _snake_case_prefixed_underscore
# - local : snake_case
# Functions:
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
_cache[src, key] = val
time = cache_get_time()
_cache_mtime[src, key] = time
- if (time % 3600 == 0) {
+ if (time % GC_Interval == 0) {
cache_gc()
}
}
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]
}
}
}
position[++i] = ""
position[++i] = make_status_energy()
position[++i] = make_status_mem()
+ position[++i] = make_status_procs()
position[++i] = make_status_cpu()
position[++i] = make_status_disk()
position[++i] = make_status_net()
return sprintf("M=%s", status)
}
+function make_status_procs() {
+ 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"
function make_status_disk( u, w, r, src_u, src_io) {
src_u = "khatus_sensor_disk_space"
src_io = "khatus_sensor_disk_io"
- u = cache_get_fmt_def(src_space, "disk_usage_percentage", 10, "%s")
- w = cache_get_fmt_def(src_io , "sectors_written" , 5, "%0.3f")
- r = cache_get_fmt_def(src_io , "sectors_read" , 5, "%0.3f")
+ u = cache_get_fmt_def(src_u , "disk_usage_percentage", 10, "%s")
+ w = cache_get_fmt_def(src_io, "sectors_written" , 5, "%0.3f")
+ r = cache_get_fmt_def(src_io, "sectors_read" , 5, "%0.3f")
return sprintf("D=[%s%% %s▲ %s▼]", u, w, r)
}
sep \
) {
number_of_net_interfaces_to_show = \
- split(opt_net_interfaces_to_show, net_interfaces_to_show, ",")
+ split(Opt_Net_Interfaces_To_Show, net_interfaces_to_show, ",")
io = "khatus_sensor_net_addr_io"
wi = "khatus_sensor_net_wifi_status"
out = ""
}
function make_status_volume( sink, mu, vl, vr, show) {
- sink = opt_pulseaudio_sink
+ sink = Opt_Pulseaudio_Sink
cache_get(mu, "khatus_sensor_volume", "mute" Kfs sink, 5)
cache_get(vl, "khatus_sensor_volume", "vol_left" Kfs sink, 5)
cache_get(vr, "khatus_sensor_volume", "vol_right" Kfs sink, 5)
song = cache_get_fmt_def(s, "song" , 5, "%s", "?")
time = cache_get_fmt_def(s, "play_time_minimal_units", 5, "%s", "?")
percent = cache_get_fmt_def(s, "play_time_percentage" , 5, "%s", "?")
- song = substr(song, 1, opt_mpd_song_max_chars)
+ song = substr(song, 1, Opt_Mpd_Song_Max_Chars)
return sprintf("%s %s %s %s", symbol, time, percent, song)
}