diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-09 04:52:57 +0000 |
commit | 00151562145df50cc65e9902d52d5fa77f89fe50 (patch) | |
tree | 2737716802f6725a5074d606ec8fe5422c58a83c /exporting/prometheus | |
parent | Releasing debian version 1.34.1-1. (diff) | |
download | netdata-00151562145df50cc65e9902d52d5fa77f89fe50.tar.xz netdata-00151562145df50cc65e9902d52d5fa77f89fe50.zip |
Merging upstream version 1.35.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'exporting/prometheus')
-rw-r--r-- | exporting/prometheus/prometheus.c | 35 | ||||
-rw-r--r-- | exporting/prometheus/prometheus.h | 6 |
2 files changed, 30 insertions, 11 deletions
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c index 97c3a29f..c7f3f1d3 100644 --- a/exporting/prometheus/prometheus.c +++ b/exporting/prometheus/prometheus.c @@ -7,14 +7,22 @@ // PROMETHEUS // /api/v1/allmetrics?format=prometheus and /api/v1/allmetrics?format=prometheus_all_hosts +static int is_matches_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN *filter) { + if (instance->config.options & EXPORTING_OPTION_SEND_NAMES) { + return simple_pattern_matches(filter, st->name); + } + return simple_pattern_matches(filter, st->id); +} + /** * Check if a chart can be sent to Prometheus * * @param instance an instance data structure. * @param st a chart. + * @param filter a simple pattern to match against. * @return Returns 1 if the chart can be sent, 0 otherwise. */ -inline int can_send_rrdset(struct instance *instance, RRDSET *st) +inline int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN *filter) { #ifdef NETDATA_INTERNAL_CHECKS RRDHOST *host = st->rrdhost; @@ -27,12 +35,15 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st) if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_IGNORE))) return 0; - if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) { + if (filter) { + if (!is_matches_rrdset(instance, st, filter)) { + return 0; + } + } else if (unlikely(!rrdset_flag_check(st, RRDSET_FLAG_EXPORTING_SEND))) { // we have not checked this chart - if (simple_pattern_matches(instance->config.charts_pattern, st->id) || - simple_pattern_matches(instance->config.charts_pattern, st->name)) + if (is_matches_rrdset(instance, st, instance->config.charts_pattern)) { rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND); - else { + } else { rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE); debug( D_EXPORTING, @@ -480,6 +491,7 @@ static void generate_as_collected_prom_metric(BUFFER *wb, struct gen_parameters * * @param instance an instance data structure. * @param host a data collecting host. + * @param filter_string a simple pattern filter. * @param wb the buffer to fill with metrics. * @param prefix a prefix for every metric. * @param exporting_options options to configure what data is exported. @@ -489,12 +501,14 @@ static void generate_as_collected_prom_metric(BUFFER *wb, struct gen_parameters static void rrd_stats_api_v1_charts_allmetrics_prometheus( struct instance *instance, RRDHOST *host, + const char *filter_string, BUFFER *wb, const char *prefix, EXPORTING_OPTIONS exporting_options, int allhosts, PROMETHEUS_OUTPUT_OPTIONS output_options) { + SIMPLE_PATTERN *filter = simple_pattern_create(filter_string, NULL, SIMPLE_PATTERN_EXACT); rrdhost_rdlock(host); char hostname[PROMETHEUS_ELEMENT_MAX + 1]; @@ -592,7 +606,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( rrdset_foreach_read(st, host) { - if (likely(can_send_rrdset(instance, st))) { + if (likely(can_send_rrdset(instance, st, filter))) { rrdset_rdlock(st); char chart[PROMETHEUS_ELEMENT_MAX + 1]; @@ -777,6 +791,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( } rrdhost_unlock(host); + simple_pattern_free(filter); } /** @@ -850,6 +865,7 @@ static inline time_t prometheus_preparation( * Write metrics and auxiliary information for one host to a buffer. * * @param host a data collecting host. + * @param filter_string a simple pattern filter. * @param wb the buffer to write to. * @param server the name of a Prometheus server. * @param prefix a prefix for every metric. @@ -858,6 +874,7 @@ static inline time_t prometheus_preparation( */ void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host( RRDHOST *host, + const char *filter_string, BUFFER *wb, const char *server, const char *prefix, @@ -880,13 +897,14 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host( output_options); rrd_stats_api_v1_charts_allmetrics_prometheus( - prometheus_exporter_instance, host, wb, prefix, exporting_options, 0, output_options); + prometheus_exporter_instance, host, filter_string, wb, prefix, exporting_options, 0, output_options); } /** * Write metrics and auxiliary information for all hosts to a buffer. * * @param host a data collecting host. + * @param filter_string a simple pattern filter. * @param wb the buffer to write to. * @param server the name of a Prometheus server. * @param prefix a prefix for every metric. @@ -895,6 +913,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host( */ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts( RRDHOST *host, + const char *filter_string, BUFFER *wb, const char *server, const char *prefix, @@ -920,7 +939,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts( rrdhost_foreach_read(host) { rrd_stats_api_v1_charts_allmetrics_prometheus( - prometheus_exporter_instance, host, wb, prefix, exporting_options, 1, output_options); + prometheus_exporter_instance, host, filter_string, wb, prefix, exporting_options, 1, output_options); } rrd_unlock(); } diff --git a/exporting/prometheus/prometheus.h b/exporting/prometheus/prometheus.h index 2f0845ce..4b8860de 100644 --- a/exporting/prometheus/prometheus.h +++ b/exporting/prometheus/prometheus.h @@ -23,13 +23,13 @@ typedef enum prometheus_output_flags { } PROMETHEUS_OUTPUT_OPTIONS; extern void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host( - RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, + RRDHOST *host, const char *filter_string, BUFFER *wb, const char *server, const char *prefix, EXPORTING_OPTIONS exporting_options, PROMETHEUS_OUTPUT_OPTIONS output_options); extern void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts( - RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, + RRDHOST *host, const char *filter_string, BUFFER *wb, const char *server, const char *prefix, EXPORTING_OPTIONS exporting_options, PROMETHEUS_OUTPUT_OPTIONS output_options); -int can_send_rrdset(struct instance *instance, RRDSET *st); +int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN *filter); size_t prometheus_name_copy(char *d, const char *s, size_t usable); size_t prometheus_label_copy(char *d, const char *s, size_t usable); char *prometheus_units_copy(char *d, const char *s, size_t usable, int showoldunits); |