Skip to content

Commit

Permalink
in_node_exporter_metrics: sanitize meminfo metric names
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jul 6, 2021
1 parent 72deaf7 commit 7b1d658
Showing 1 changed file with 24 additions and 1 deletion.
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

0 comments on commit 7b1d658

Please sign in to comment.