diff options
Diffstat (limited to 'exporting/prometheus/prometheus.c')
-rw-r--r-- | exporting/prometheus/prometheus.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c index 0e0e8abf0..9f24ba1b0 100644 --- a/exporting/prometheus/prometheus.c +++ b/exporting/prometheus/prometheus.c @@ -41,7 +41,7 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_SEND); } else { rrdset_flag_set(st, RRDSET_FLAG_EXPORTING_IGNORE); - debug( + netdata_log_debug( D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.", rrdset_id(st), @@ -51,7 +51,7 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN } if (unlikely(!rrdset_is_available_for_exporting_and_alarms(st))) { - debug( + netdata_log_debug( D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s', because it is not available for exporting.", rrdset_id(st), @@ -62,7 +62,7 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st, SIMPLE_PATTERN if (unlikely( st->rrd_memory_mode == RRD_MEMORY_MODE_NONE && !(EXPORTING_OPTIONS_DATA_SOURCE(instance->config.options) == EXPORTING_SOURCE_DATA_AS_COLLECTED))) { - debug( + netdata_log_debug( D_EXPORTING, "EXPORTING: not sending chart '%s' of host '%s' because its memory mode is '%s' and the exporting connector requires database access.", rrdset_id(st), @@ -244,7 +244,7 @@ inline char *prometheus_units_copy(char *d, const char *s, size_t usable, int sh uint32_t hash = simple_hash(s); for (i = 0; units[i].newunit; i++) { if (unlikely(hash == units[i].hash && !strcmp(s, units[i].newunit))) { - // info("matched extension for filename '%s': '%s'", filename, last_dot); + // netdata_log_info("matched extension for filename '%s': '%s'", filename, last_dot); s = units[i].oldunit; sorig = s; break; @@ -497,7 +497,7 @@ static void generate_as_collected_prom_help(BUFFER *wb, struct gen_parameters *p if (prometheus_collector) buffer_sprintf(wb, "1 / 1"); else - buffer_sprintf(wb, COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT, p->rd->multiplier, p->rd->divisor); + buffer_sprintf(wb, "%d / %d", p->rd->multiplier, p->rd->divisor); buffer_sprintf(wb, " %s %s (%s)\n", p->relation, rrdset_units(p->st), p->type); } @@ -540,13 +540,13 @@ static void generate_as_collected_prom_metric(BUFFER *wb, buffer_sprintf( wb, NETDATA_DOUBLE_FORMAT, - (NETDATA_DOUBLE)p->rd->last_collected_value * (NETDATA_DOUBLE)p->rd->multiplier / - (NETDATA_DOUBLE)p->rd->divisor); + (NETDATA_DOUBLE)p->rd->collector.last_collected_value * (NETDATA_DOUBLE)p->rd->multiplier / + (NETDATA_DOUBLE)p->rd->divisor); else - buffer_sprintf(wb, COLLECTED_NUMBER_FORMAT, p->rd->last_collected_value); + buffer_sprintf(wb, COLLECTED_NUMBER_FORMAT, p->rd->collector.last_collected_value); if (p->output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) - buffer_sprintf(wb, " %llu\n", timeval_msec(&p->rd->last_collected_time)); + buffer_sprintf(wb, " %llu\n", timeval_msec(&p->rd->collector.last_collected_time)); else buffer_sprintf(wb, "\n"); } @@ -627,6 +627,8 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( static struct format_prometheus_chart_label_callback plabels = { .labels_buffer = NULL, }; + + STRING *prometheus = string_strdupz("prometheus"); rrdset_foreach_read(st, host) { if (likely(can_send_rrdset(instance, st, filter))) { @@ -642,16 +644,18 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( int as_collected = (EXPORTING_OPTIONS_DATA_SOURCE(exporting_options) == EXPORTING_SOURCE_DATA_AS_COLLECTED); int homogeneous = 1; int prometheus_collector = 0; + RRDSET_FLAGS flags = __atomic_load_n(&st->flags, __ATOMIC_RELAXED); if (as_collected) { - if (rrdset_flag_check(st, RRDSET_FLAG_HOMOGENEOUS_CHECK)) + if (flags & RRDSET_FLAG_HOMOGENEOUS_CHECK) rrdset_update_heterogeneous_flag(st); - if (rrdset_flag_check(st, RRDSET_FLAG_HETEROGENEOUS)) + if (flags & RRDSET_FLAG_HETEROGENEOUS) homogeneous = 0; - if (!strcmp(rrdset_module_name(st), "prometheus")) + if (st->module_name == prometheus) prometheus_collector = 1; - } else { + } + else { if (EXPORTING_OPTIONS_DATA_SOURCE(exporting_options) == EXPORTING_SOURCE_DATA_AVERAGE && !(output_options & PROMETHEUS_OUTPUT_HIDEUNITS)) prometheus_units_copy( @@ -671,7 +675,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( // for each dimension RRDDIM *rd; rrddim_foreach_read(rd, st) { - if (rd->collections_counter && !rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) { + if (rd->collector.counter && !rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) { char dimension[PROMETHEUS_ELEMENT_MAX + 1]; char *suffix = ""; @@ -690,7 +694,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus( p.st = st; p.rd = rd; - if (unlikely(rd->last_collected_time.tv_sec < instance->after)) + if (unlikely(rd->collector.last_collected_time.tv_sec < instance->after)) continue; p.type = "gauge"; @@ -953,11 +957,10 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts( prometheus_exporter_instance->before, output_options); - rrd_rdlock(); - rrdhost_foreach_read(host) + dfe_start_reentrant(rrdhost_root_index, host) { rrd_stats_api_v1_charts_allmetrics_prometheus( prometheus_exporter_instance, host, filter_string, wb, prefix, exporting_options, 1, output_options); } - rrd_unlock(); + dfe_done(host); } |