From 00151562145df50cc65e9902d52d5fa77f89fe50 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 9 Jun 2022 06:52:47 +0200 Subject: Merging upstream version 1.35.0. Signed-off-by: Daniel Baumann --- collectors/proc.plugin/proc_pressure.c | 189 +++++++++++++++++++-------------- 1 file changed, 111 insertions(+), 78 deletions(-) (limited to 'collectors/proc.plugin/proc_pressure.c') diff --git a/collectors/proc.plugin/proc_pressure.c b/collectors/proc.plugin/proc_pressure.c index 4a40b4aaf..66884dbcb 100644 --- a/collectors/proc.plugin/proc_pressure.c +++ b/collectors/proc.plugin/proc_pressure.c @@ -8,22 +8,36 @@ // linux calculates this every 2 seconds, see kernel/sched/psi.c PSI_FREQ #define MIN_PRESSURE_UPDATE_EVERY 2 +static int pressure_update_every = 0; static struct pressure resources[PRESSURE_NUM_RESOURCES] = { - { - .some = { .id = "cpu_pressure", .title = "CPU Pressure" }, - }, - { - .some = { .id = "memory_some_pressure", .title = "Memory Pressure" }, - .full = { .id = "memory_full_pressure", .title = "Memory Full Pressure" }, - }, - { - .some = { .id = "io_some_pressure", .title = "I/O Pressure" }, - .full = { .id = "io_full_pressure", .title = "I/O Full Pressure" }, - }, + { + .some = + {.share_time = {.id = "cpu_some_pressure", .title = "CPU some pressure"}, + .total_time = {.id = "cpu_some_pressure_stall_time", .title = "CPU some pressure stall time"}}, + .full = + {.share_time = {.id = "cpu_full_pressure", .title = "CPU full pressure"}, + .total_time = {.id = "cpu_full_pressure_stall_time", .title = "CPU full pressure stall time"}}, + }, + { + .some = + {.share_time = {.id = "memory_some_pressure", .title = "Memory some pressure"}, + .total_time = {.id = "memory_some_pressure_stall_time", .title = "Memory some pressure stall time"}}, + .full = + {.share_time = {.id = "memory_full_pressure", .title = "Memory full pressure"}, + .total_time = {.id = "memory_full_pressure_stall_time", .title = "Memory full pressure stall time"}}, + }, + { + .some = + {.share_time = {.id = "io_some_pressure", .title = "I/O some pressure"}, + .total_time = {.id = "io_some_pressure_stall_time", .title = "I/O some pressure stall time"}}, + .full = + {.share_time = {.id = "io_full_pressure", .title = "I/O full pressure"}, + .total_time = {.id = "io_full_pressure_stall_time", .title = "I/O full pressure stall time"}}, + }, }; -static struct { +static struct resource_info { procfile *pf; const char *name; // metric file name const char *family; // webui section name @@ -34,12 +48,83 @@ static struct { { .name = "io", .family = "disk", .section_priority = NETDATA_CHART_PRIO_SYSTEM_IO }, }; -void update_pressure_chart(struct pressure_chart *chart) { - rrddim_set_by_pointer(chart->st, chart->rd10, (collected_number)(chart->value10 * 100)); - rrddim_set_by_pointer(chart->st, chart->rd60, (collected_number) (chart->value60 * 100)); - rrddim_set_by_pointer(chart->st, chart->rd300, (collected_number) (chart->value300 * 100)); +void update_pressure_charts(struct pressure_charts *pcs) { + if (pcs->share_time.st) { + rrddim_set_by_pointer( + pcs->share_time.st, pcs->share_time.rd10, (collected_number)(pcs->share_time.value10 * 100)); + rrddim_set_by_pointer( + pcs->share_time.st, pcs->share_time.rd60, (collected_number)(pcs->share_time.value60 * 100)); + rrddim_set_by_pointer( + pcs->share_time.st, pcs->share_time.rd300, (collected_number)(pcs->share_time.value300 * 100)); + rrdset_done(pcs->share_time.st); + } + if (pcs->total_time.st) { + rrddim_set_by_pointer( + pcs->total_time.st, pcs->total_time.rdtotal, (collected_number)(pcs->total_time.value_total)); + rrdset_done(pcs->total_time.st); + } +} + +static void proc_pressure_do_resource(procfile *ff, int res_idx, int some) { + struct pressure_charts *pcs; + struct resource_info ri; + pcs = some ? &resources[res_idx].some : &resources[res_idx].full; + ri = resource_info[res_idx]; + + if (unlikely(!pcs->share_time.st)) { + pcs->share_time.st = rrdset_create_localhost( + "system", + pcs->share_time.id, + NULL, + ri.family, + NULL, + pcs->share_time.title, + "percentage", + PLUGIN_PROC_NAME, + PLUGIN_PROC_MODULE_PRESSURE_NAME, + ri.section_priority + (some ? 40 : 50), + pressure_update_every, + RRDSET_TYPE_LINE); + pcs->share_time.rd10 = + rrddim_add(pcs->share_time.st, some ? "some 10" : "full 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); + pcs->share_time.rd60 = + rrddim_add(pcs->share_time.st, some ? "some 60" : "full 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); + pcs->share_time.rd300 = + rrddim_add(pcs->share_time.st, some ? "some 300" : "full 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); + } else { + rrdset_next(pcs->share_time.st); + } + pcs->share_time.value10 = strtod(procfile_lineword(ff, some ? 0 : 1, 2), NULL); + pcs->share_time.value60 = strtod(procfile_lineword(ff, some ? 0 : 1, 4), NULL); + pcs->share_time.value300 = strtod(procfile_lineword(ff, some ? 0 : 1, 6), NULL); + + if (unlikely(!pcs->total_time.st)) { + pcs->total_time.st = rrdset_create_localhost( + "system", + pcs->total_time.id, + NULL, + ri.family, + NULL, + pcs->total_time.title, + "ms", + PLUGIN_PROC_NAME, + PLUGIN_PROC_MODULE_PRESSURE_NAME, + ri.section_priority + (some ? 45 : 55), + pressure_update_every, + RRDSET_TYPE_LINE); + pcs->total_time.rdtotal = rrddim_add(pcs->total_time.st, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); + } else { + rrdset_next(pcs->total_time.st); + } + pcs->total_time.value_total = str2ull(procfile_lineword(ff, some ? 0 : 1, 8)) / 1000; +} - rrdset_done(chart->st); +static void proc_pressure_do_resource_some(procfile *ff, int res_idx) { + proc_pressure_do_resource(ff, res_idx, 1); +} + +static void proc_pressure_do_resource_full(procfile *ff, int res_idx) { + proc_pressure_do_resource(ff, res_idx, 0); } int do_proc_pressure(int update_every, usec_t dt) { @@ -50,6 +135,7 @@ int do_proc_pressure(int update_every, usec_t dt) { static char *base_path = NULL; update_every = (update_every < MIN_PRESSURE_UPDATE_EVERY) ? MIN_PRESSURE_UPDATE_EVERY : update_every; + pressure_update_every = update_every; if (next_pressure_dt <= dt) { next_pressure_dt = update_every * USEC_PER_SEC; @@ -80,11 +166,10 @@ int do_proc_pressure(int update_every, usec_t dt) { snprintfz(config_key, CONFIG_MAX_NAME, "enable %s some pressure", resource_info[i].name); do_some = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_PRESSURE, config_key, CONFIG_BOOLEAN_YES); resources[i].some.enabled = do_some; - if (resources[i].full.id) { - snprintfz(config_key, CONFIG_MAX_NAME, "enable %s full pressure", resource_info[i].name); - do_full = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_PRESSURE, config_key, CONFIG_BOOLEAN_YES); - resources[i].full.enabled = do_full; - } + + snprintfz(config_key, CONFIG_MAX_NAME, "enable %s full pressure", resource_info[i].name); + do_full = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_PRESSURE, config_key, CONFIG_BOOLEAN_YES); + resources[i].full.enabled = do_full; ff = procfile_open(filename, " =", PROCFILE_FLAG_DEFAULT); if (unlikely(!ff)) { @@ -108,65 +193,13 @@ int do_proc_pressure(int update_every, usec_t dt) { continue; } - struct pressure_chart *chart; if (do_some) { - chart = &resources[i].some; - if (unlikely(!chart->st)) { - chart->st = rrdset_create_localhost( - "system" - , chart->id - , NULL - , resource_info[i].family - , NULL - , chart->title - , "percentage" - , PLUGIN_PROC_NAME - , PLUGIN_PROC_MODULE_PRESSURE_NAME - , resource_info[i].section_priority + 40 - , update_every - , RRDSET_TYPE_LINE - ); - chart->rd10 = rrddim_add(chart->st, "some 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - chart->rd60 = rrddim_add(chart->st, "some 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - chart->rd300 = rrddim_add(chart->st, "some 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - } else { - rrdset_next(chart->st); - } - - chart->value10 = strtod(procfile_lineword(ff, 0, 2), NULL); - chart->value60 = strtod(procfile_lineword(ff, 0, 4), NULL); - chart->value300 = strtod(procfile_lineword(ff, 0, 6), NULL); - update_pressure_chart(chart); + proc_pressure_do_resource_some(ff, i); + update_pressure_charts(&resources[i].some); } - if (do_full && lines > 2) { - chart = &resources[i].full; - if (unlikely(!chart->st)) { - chart->st = rrdset_create_localhost( - "system" - , chart->id - , NULL - , resource_info[i].family - , NULL - , chart->title - , "percentage" - , PLUGIN_PROC_NAME - , PLUGIN_PROC_MODULE_PRESSURE_NAME - , resource_info[i].section_priority + 45 - , update_every - , RRDSET_TYPE_LINE - ); - chart->rd10 = rrddim_add(chart->st, "full 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - chart->rd60 = rrddim_add(chart->st, "full 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - chart->rd300 = rrddim_add(chart->st, "full 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); - } else { - rrdset_next(chart->st); - } - - chart->value10 = strtod(procfile_lineword(ff, 1, 2), NULL); - chart->value60 = strtod(procfile_lineword(ff, 1, 4), NULL); - chart->value300 = strtod(procfile_lineword(ff, 1, 6), NULL); - update_pressure_chart(chart); + proc_pressure_do_resource_full(ff, i); + update_pressure_charts(&resources[i].full); } } -- cgit v1.2.3