Skip to content

Commit

Permalink
log_to_metrics: allow custom namespace and subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
flobz committed Jul 17, 2024
1 parent 239ca35 commit 76d2c6e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Empty file removed build/.empty
Empty file.
30 changes: 27 additions & 3 deletions plugins/filter_log_to_metrics/log_to_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static int log_to_metrics_destroy(struct log_to_metrics_ctx *ctx)
flb_free(ctx->buckets);
flb_free(ctx->bucket_counter);
flb_free(ctx->label_counter);
flb_sds_destroy(ctx->metric_subsystem);
flb_free(ctx);
return 0;
}
Expand Down Expand Up @@ -453,6 +454,8 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,
flb_sds_t tmp;
char metric_description[MAX_METRIC_LENGTH];
char metric_name[MAX_METRIC_LENGTH];
char metric_namespace[MAX_METRIC_LENGTH];
char metric_subsystem[MAX_METRIC_LENGTH];
char value_field[MAX_METRIC_LENGTH];
struct flb_input_instance *input_ins;
int label_count;
Expand Down Expand Up @@ -556,6 +559,14 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,
return -1;
}
snprintf(metric_name, sizeof(metric_name) - 1, "%s", ctx->metric_name);
snprintf(metric_namespace, sizeof(metric_namespace) - 1, "%s", ctx->metric_namespace);

/* Check property subsystem name */
if (ctx->metric_subsystem == NULL || strlen(ctx->metric_subsystem) == 0) {
ctx->metric_subsystem = flb_sds_create(tmp);
}
snprintf(metric_subsystem, sizeof(metric_subsystem) - 1, "%s",
ctx->metric_subsystem);

/* Check property metric description */
if (ctx->metric_description == NULL ||
Expand Down Expand Up @@ -602,17 +613,17 @@ static int cb_log_to_metrics_init(struct flb_filter_instance *f_ins,
/* Depending on mode create different types of cmetrics metrics */
switch (ctx->mode) {
case FLB_LOG_TO_METRICS_COUNTER:
ctx->c = cmt_counter_create(ctx->cmt, "log_metric", "counter",
ctx->c = cmt_counter_create(ctx->cmt, metric_namespace, metric_subsystem,
metric_name, metric_description,
label_count, ctx->label_keys);
break;
case FLB_LOG_TO_METRICS_GAUGE:
ctx->g = cmt_gauge_create(ctx->cmt, "log_metric", "gauge",
ctx->g = cmt_gauge_create(ctx->cmt, metric_namespace, metric_subsystem,
metric_name, metric_description,
label_count, ctx->label_keys);
break;
case FLB_LOG_TO_METRICS_HISTOGRAM:
ctx->h = cmt_histogram_create(ctx->cmt, "log_metric", "histogram",
ctx->h = cmt_histogram_create(ctx->cmt, metric_namespace, metric_subsystem,
metric_name, metric_description,
ctx->histogram_buckets,
label_count, ctx->label_keys);
Expand Down Expand Up @@ -956,6 +967,19 @@ static struct flb_config_map config_map[] = {
offsetof(struct log_to_metrics_ctx, metric_name),
"Name of metric"
},
{
FLB_CONFIG_MAP_STR, "metric_namespace",
DEFAULT_LOG_TO_METRICS_NAMESPACE,
FLB_FALSE, FLB_TRUE,
offsetof(struct log_to_metrics_ctx, metric_namespace),
"Namespace of the metric"
},
{
FLB_CONFIG_MAP_STR, "metric_subsystem",NULL,
FLB_FALSE, FLB_TRUE,
offsetof(struct log_to_metrics_ctx, metric_subsystem),
"Subsystem of the metric"
},
{
FLB_CONFIG_MAP_STR, "metric_description", NULL,
FLB_FALSE, FLB_TRUE,
Expand Down
3 changes: 3 additions & 0 deletions plugins/filter_log_to_metrics/log_to_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define MAX_LABEL_COUNT 32

#define FLB_MEM_BUF_LIMIT_DEFAULT "10M"
#define DEFAULT_LOG_TO_METRICS_NAMESPACE "log_metric"


struct log_to_metrics_ctx
Expand All @@ -57,6 +58,8 @@ struct log_to_metrics_ctx
struct flb_filter_instance *ins;
int mode;
flb_sds_t metric_name;
flb_sds_t metric_namespace;
flb_sds_t metric_subsystem;
flb_sds_t metric_description;
struct cmt *cmt;
struct flb_input_instance *input_ins;
Expand Down

0 comments on commit 76d2c6e

Please sign in to comment.