summaryrefslogtreecommitdiffstats
path: root/exporting/prometheus/prometheus.c
diff options
context:
space:
mode:
Diffstat (limited to 'exporting/prometheus/prometheus.c')
-rw-r--r--exporting/prometheus/prometheus.c35
1 files changed, 27 insertions, 8 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();
}