summaryrefslogtreecommitdiffstats
path: root/exporting/prometheus
diff options
context:
space:
mode:
Diffstat (limited to 'exporting/prometheus')
-rw-r--r--exporting/prometheus/prometheus.c39
-rw-r--r--exporting/prometheus/remote_write/remote_write.c24
2 files changed, 33 insertions, 30 deletions
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c
index 0e0e8abf..9f24ba1b 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);
}
diff --git a/exporting/prometheus/remote_write/remote_write.c b/exporting/prometheus/remote_write/remote_write.c
index 660b798e..2b53b1c2 100644
--- a/exporting/prometheus/remote_write/remote_write.c
+++ b/exporting/prometheus/remote_write/remote_write.c
@@ -234,7 +234,7 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
struct prometheus_remote_write_specific_data *connector_specific_data =
(struct prometheus_remote_write_specific_data *)simple_connector_data->connector_specific_data;
- if (rd->collections_counter && !rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) {
+ if (rd->collector.counter && !rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) {
char name[PROMETHEUS_LABELS_MAX + 1];
char dimension[PROMETHEUS_ELEMENT_MAX + 1];
char *suffix = "";
@@ -243,14 +243,14 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
if (as_collected) {
// we need as-collected / raw data
- if (unlikely(rd->last_collected_time.tv_sec < instance->after)) {
- debug(
+ if (unlikely(rd->collector.last_collected_time.tv_sec < instance->after)) {
+ netdata_log_debug(
D_EXPORTING,
"EXPORTING: not sending dimension '%s' of chart '%s' from host '%s', "
"its last data collection (%lu) is not within our timeframe (%lu to %lu)",
rrddim_id(rd), rrdset_id(rd->rrdset),
(host == localhost) ? instance->config.hostname : rrdhost_hostname(host),
- (unsigned long)rd->last_collected_time.tv_sec,
+ (unsigned long)rd->collector.last_collected_time.tv_sec,
(unsigned long)instance->after,
(unsigned long)instance->before);
return 0;
@@ -272,10 +272,10 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s%s", instance->config.prefix, context, suffix);
add_metric(
- connector_specific_data->write_request,
- name, chart, family, dimension,
+ connector_specific_data->write_request,
+ name, chart, family, dimension,
(host == localhost) ? instance->config.hostname : rrdhost_hostname(host),
- rd->last_collected_value, timeval_msec(&rd->last_collected_time));
+ rd->collector.last_collected_value, timeval_msec(&rd->collector.last_collected_time));
} else {
// the dimensions of the chart, do not have the same algorithm, multiplier or divisor
// we create a metric per dimension
@@ -289,10 +289,10 @@ int format_dimension_prometheus_remote_write(struct instance *instance, RRDDIM *
suffix);
add_metric(
- connector_specific_data->write_request,
- name, chart, family, NULL,
+ connector_specific_data->write_request,
+ name, chart, family, NULL,
(host == localhost) ? instance->config.hostname : rrdhost_hostname(host),
- rd->last_collected_value, timeval_msec(&rd->last_collected_time));
+ rd->collector.last_collected_value, timeval_msec(&rd->collector.last_collected_time));
}
} else {
// we need average or sum of the data
@@ -386,7 +386,7 @@ int format_batch_prometheus_remote_write(struct instance *instance)
size_t data_size = get_write_request_size(connector_specific_data->write_request);
if (unlikely(!data_size)) {
- error("EXPORTING: write request size is out of range");
+ netdata_log_error("EXPORTING: write request size is out of range");
return 1;
}
@@ -394,7 +394,7 @@ int format_batch_prometheus_remote_write(struct instance *instance)
buffer_need_bytes(buffer, data_size);
if (unlikely(pack_and_clear_write_request(connector_specific_data->write_request, buffer->buffer, &data_size))) {
- error("EXPORTING: cannot pack write request");
+ netdata_log_error("EXPORTING: cannot pack write request");
return 1;
}
buffer->len = data_size;