X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fhugepages.c;h=c5b0ecb996328032fe1384469238412240a28bb5;hp=b5acfba2a731d482be2d375261b1525c4ecc6dbc;hb=da11ce02eb202b3e01d3e2d1b40f248a84430973;hpb=9dadbd1f23d0ecbae7e8a7dc4fbaa7f73e7ea18a diff --git a/src/hugepages.c b/src/hugepages.c index b5acfba2..c5b0ecb9 100644 --- a/src/hugepages.c +++ b/src/hugepages.c @@ -25,9 +25,11 @@ * Authors: * Jaroslav Safka * Kim-Marie Jones + * Florian Forster */ #include "collectd.h" + #include "common.h" /* auxiliary functions */ #include "plugin.h" /* plugin_register_*, plugin_dispatch_values */ @@ -36,6 +38,10 @@ static const char g_plugin_name[] = "hugepages"; static _Bool g_flag_rpt_numa = 1; static _Bool g_flag_rpt_mm = 1; +static _Bool g_values_pages = 1; +static _Bool g_values_bytes = 0; +static _Bool g_values_percent = 0; + #define HP_HAVE_NR 0x01 #define HP_HAVE_SURPLUS 0x02 #define HP_HAVE_FREE 0x04 @@ -59,47 +65,67 @@ static int hp_config(oconfig_item_t *ci) { cf_util_get_boolean(child, &g_flag_rpt_numa); else if (strcasecmp("ReportRootHP", child->key) == 0) cf_util_get_boolean(child, &g_flag_rpt_mm); + else if (strcasecmp("ValuesPages", child->key) == 0) + cf_util_get_boolean(child, &g_values_pages); + else if (strcasecmp("ValuesBytes", child->key) == 0) + cf_util_get_boolean(child, &g_values_bytes); + else if (strcasecmp("ValuesPercentage", child->key) == 0) + cf_util_get_boolean(child, &g_values_percent); else ERROR("%s: Invalid configuration option: \"%s\".", g_plugin_name, child->key); } - return (0); + return 0; } -static void submit_hp(const char *plug_inst, const char *type_instance, - gauge_t free_value, gauge_t used_value) { +static void submit_hp(const struct entry_info *info) { value_list_t vl = VALUE_LIST_INIT; - value_t values[] = { - { .gauge = free_value }, - { .gauge = used_value }, - }; - - vl.values = values; - vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); - sstrncpy(vl.plugin, g_plugin_name, sizeof(vl.plugin)); - sstrncpy(vl.plugin_instance, plug_inst, sizeof(vl.plugin_instance)); - sstrncpy(vl.type, "hugepages", sizeof(vl.type)); - if (type_instance != NULL) { - sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); + vl.values = &(value_t){.gauge = NAN}; + vl.values_len = 1; + + sstrncpy(vl.plugin, g_plugin_name, sizeof(vl.plugin)); + if (info->node) { + snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%zuKb", + info->node, info->page_size_kb); + } else { + snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%zuKb", + info->page_size_kb); } - DEBUG("submit_hp pl_inst:%s, inst_type %s, free=%lf, used=%lf", plug_inst, - type_instance, free_value, used_value); + /* ensure all metrics have the same timestamp */ + vl.time = cdtime(); + + gauge_t free = info->free; + gauge_t used = (info->nr + info->surplus) - info->free; - plugin_dispatch_values(&vl); + if (g_values_pages) { + sstrncpy(vl.type, "vmpage_number", sizeof(vl.type)); + plugin_dispatch_multivalue(&vl, /* store_percentage = */ 0, DS_TYPE_GAUGE, + "free", free, "used", used, NULL); + } + if (g_values_bytes) { + gauge_t page_size = (gauge_t)(1024 * info->page_size_kb); + sstrncpy(vl.type, "memory", sizeof(vl.type)); + plugin_dispatch_multivalue(&vl, /* store_percentage = */ 0, DS_TYPE_GAUGE, + "free", free * page_size, "used", + used * page_size, NULL); + } + if (g_values_percent) { + sstrncpy(vl.type, "percent", sizeof(vl.type)); + plugin_dispatch_multivalue(&vl, /* store_percentage = */ 1, DS_TYPE_GAUGE, + "free", free, "used", used, NULL); + } } static int read_hugepage_entry(const char *path, const char *entry, void *e_info) { char path2[PATH_MAX]; - char type_instance[PATH_MAX]; struct entry_info *info = e_info; double value; - ssnprintf(path2, sizeof(path2), "%s/%s", path, entry); + snprintf(path2, sizeof(path2), "%s/%s", path, entry); FILE *fh = fopen(path2, "rt"); if (fh == NULL) { @@ -129,10 +155,7 @@ static int read_hugepage_entry(const char *path, const char *entry, return 0; } - ssnprintf(type_instance, sizeof(type_instance), "free_used-%zukB", - info->page_size_kb); - submit_hp(info->node, type_instance, info->free, - (info->nr + info->surplus) - info->free); + submit_hp(info); /* Reset flags so subsequent calls don't submit again. */ info->flags = 0; @@ -170,7 +193,7 @@ static int read_syshugepages(const char *path, const char *node) { } /* /sys/devices/system/node/node?/hugepages/ */ - ssnprintf(path2, sizeof(path2), "%s/%s", path, result->d_name); + snprintf(path2, sizeof(path2), "%s/%s", path, result->d_name); walk_directory(path2, read_hugepage_entry, &(struct entry_info){ @@ -215,7 +238,7 @@ static int read_nodes(void) { continue; } - ssnprintf(path, sizeof(path), sys_node_hugepages, result->d_name); + snprintf(path, sizeof(path), sys_node_hugepages, result->d_name); read_syshugepages(path, result->d_name); errno = 0; }