Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_node_exporter_metrics: sanitize meminfo metric names #3724

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion plugins/in_node_exporter_metrics/ne_meminfo_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static int meminfo_configure(struct flb_ne *ctx)
{
int ret;
int parts;
int len;
char *p;
char desc[] = "Memory information field ";
struct cmt_gauge *g;
struct mk_list *head;
Expand Down Expand Up @@ -82,8 +84,20 @@ static int meminfo_configure(struct flb_ne *ctx)
/* set metric name */
entry = mk_list_entry_first(&split_list, struct flb_slist_entry, _head);

if ((p = strstr(entry->str, "(anon)")) ||
(p = strstr(entry->str, "(file)"))) {
*p = '_';
len = flb_sds_len(entry->str) - 2;
flb_sds_len_set(entry->str, len);
}
else {
len = flb_sds_len(entry->str) - 1;
flb_sds_len_set(entry->str, len);
}
entry->str[len] = '\0';

flb_sds_len_set(metric_name, 0);
flb_sds_cat(metric_name, entry->str, flb_sds_len(entry->str) - 1);
flb_sds_cat(metric_name, entry->str, flb_sds_len(entry->str));

/* Metric description */
flb_sds_len_set(metric_desc, 0);
Expand Down Expand Up @@ -151,10 +165,12 @@ static int meminfo_update(struct flb_ne *ctx)
{
int i = 0;
int ret;
int len;
int parts;
uint64_t ts;
double val;
size_t out_size;
char *p;
flb_sds_t tmp;
flb_sds_t metric_name = NULL;
struct cmt_gauge *g;
Expand Down Expand Up @@ -190,6 +206,13 @@ static int meminfo_update(struct flb_ne *ctx)
entry = mk_list_entry_first(&split_list, struct flb_slist_entry, _head);
metric_name = entry->str;

if ((p = strstr(entry->str, "(anon)")) ||
(p = strstr(entry->str, "(file)"))) {
*p = '_';
len = flb_sds_len(metric_name) - 1;
flb_sds_len_set(metric_name, len);
}

/* Metric value */
entry = mk_list_entry_next(&split_list, struct flb_slist_entry, _head,
&entry->_head);
Expand Down