diff options
author | Vladimir Kobal <vlad@prokk.net> | 2020-03-12 13:28:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-12 13:28:43 +0200 |
commit | bc0ca9b1b3cbdd6d1a76d2150080dff79e116e24 (patch) | |
tree | 2d2c59e6f32e831612a257c73e81bfdf5f65c361 /backends/prometheus | |
parent | bec7b83e19944a7e844c6c7777f92ccba6d504e3 (diff) |
Add a Prometheus Remote Write connector to the exporting engine (#8292)
* Copy files from the Prometheus remote write backend
* Update the documentation
* Rename backend -> exporting
* Add the connector to the Netdata build
* Separate files for the remote write connector
* Add an initializer and formatters
* Read a connector specific configuration option
* Add a separate function for header sending
* Use labels instead of tags
* Separate write request for every instance
* Add unit tests
Diffstat (limited to 'backends/prometheus')
-rw-r--r-- | backends/prometheus/backend_prometheus.c | 88 | ||||
-rw-r--r-- | backends/prometheus/backend_prometheus.h | 28 | ||||
-rw-r--r-- | backends/prometheus/remote_write/remote_write.cc | 23 | ||||
-rw-r--r-- | backends/prometheus/remote_write/remote_write.h | 16 |
4 files changed, 77 insertions, 78 deletions
diff --git a/backends/prometheus/backend_prometheus.c b/backends/prometheus/backend_prometheus.c index 2db911621d..b3f955e15f 100644 --- a/backends/prometheus/backend_prometheus.c +++ b/backends/prometheus/backend_prometheus.c @@ -159,7 +159,7 @@ struct host_variables_callback_options { RRDHOST *host; BUFFER *wb; BACKEND_OPTIONS backend_options; - PROMETHEUS_OUTPUT_OPTIONS output_options; + BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options; const char *prefix; const char *labels; time_t now; @@ -174,14 +174,14 @@ static int print_host_variables(RRDVAR *rv, void *data) { if(!opts->host_header_printed) { opts->host_header_printed = 1; - if(opts->output_options & PROMETHEUS_OUTPUT_HELP) { + if(opts->output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP) { buffer_sprintf(opts->wb, "\n# COMMENT global host and chart variables\n"); } } calculated_number value = rrdvar2number(rv); if(isnan(value) || isinf(value)) { - if(opts->output_options & PROMETHEUS_OUTPUT_HELP) + if(opts->output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP) buffer_sprintf(opts->wb, "# COMMENT variable \"%s\" is %s. Skipped.\n", rv->name, (isnan(value))?"NAN":"INF"); return 0; @@ -196,7 +196,7 @@ static int print_host_variables(RRDVAR *rv, void *data) { prometheus_name_copy(opts->name, rv->name, sizeof(opts->name)); - if(opts->output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(opts->output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(opts->wb , "%s_%s%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n" , opts->prefix @@ -223,7 +223,7 @@ static int print_host_variables(RRDVAR *rv, void *data) { return 0; } -static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb, const char *prefix, BACKEND_OPTIONS backend_options, time_t after, time_t before, int allhosts, PROMETHEUS_OUTPUT_OPTIONS output_options) { +static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb, const char *prefix, BACKEND_OPTIONS backend_options, time_t after, time_t before, int allhosts, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options) { rrdhost_rdlock(host); char hostname[PROMETHEUS_ELEMENT_MAX + 1]; @@ -231,13 +231,13 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER char labels[PROMETHEUS_LABELS_MAX + 1] = ""; if(allhosts) { - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(wb, "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1 %llu\n", hostname, host->program_name, host->program_version, now_realtime_usec() / USEC_PER_MS); else buffer_sprintf(wb, "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1\n", hostname, host->program_name, host->program_version); if(host->tags && *(host->tags)) { - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) { + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) { buffer_sprintf(wb, "netdata_host_tags_info{instance=\"%s\",%s} 1 %llu\n", hostname, host->tags, now_realtime_usec() / USEC_PER_MS); // deprecated, exists only for compatibility with older queries @@ -255,13 +255,13 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER snprintfz(labels, PROMETHEUS_LABELS_MAX, ",instance=\"%s\"", hostname); } else { - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(wb, "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1 %llu\n", hostname, host->program_name, host->program_version, now_realtime_usec() / USEC_PER_MS); else buffer_sprintf(wb, "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"} 1\n", hostname, host->program_name, host->program_version); if(host->tags && *(host->tags)) { - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) { + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) { buffer_sprintf(wb, "netdata_host_tags_info{%s} 1 %llu\n", host->tags, now_realtime_usec() / USEC_PER_MS); // deprecated, exists only for compatibility with older queries @@ -277,7 +277,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER } // send custom variables set for the host - if(output_options & PROMETHEUS_OUTPUT_VARIABLES){ + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_VARIABLES){ struct host_variables_callback_options opts = { .host = host, .wb = wb, @@ -299,7 +299,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER char family[PROMETHEUS_ELEMENT_MAX + 1]; char units[PROMETHEUS_ELEMENT_MAX + 1] = ""; - prometheus_label_copy(chart, (output_options & PROMETHEUS_OUTPUT_NAMES && st->name)?st->name:st->id, PROMETHEUS_ELEMENT_MAX); + prometheus_label_copy(chart, (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && st->name)?st->name:st->id, PROMETHEUS_ELEMENT_MAX); prometheus_label_copy(family, st->family, PROMETHEUS_ELEMENT_MAX); prometheus_name_copy(context, st->context, PROMETHEUS_ELEMENT_MAX); @@ -316,14 +316,14 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER homogeneous = 0; } else { - if(BACKEND_OPTIONS_DATA_SOURCE(backend_options) == BACKEND_SOURCE_DATA_AVERAGE && !(output_options & PROMETHEUS_OUTPUT_HIDEUNITS)) - prometheus_units_copy(units, st->units, PROMETHEUS_ELEMENT_MAX, output_options & PROMETHEUS_OUTPUT_OLDUNITS); + if(BACKEND_OPTIONS_DATA_SOURCE(backend_options) == BACKEND_SOURCE_DATA_AVERAGE && !(output_options & BACKENDS_PROMETHEUS_OUTPUT_HIDEUNITS)) + prometheus_units_copy(units, st->units, PROMETHEUS_ELEMENT_MAX, output_options & BACKENDS_PROMETHEUS_OUTPUT_OLDUNITS); } - if(unlikely(output_options & PROMETHEUS_OUTPUT_HELP)) + if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP)) buffer_sprintf(wb, "\n# COMMENT %s chart \"%s\", context \"%s\", family \"%s\", units \"%s\"\n" , (homogeneous)?"homogeneous":"heterogeneous" - , (output_options & PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id , st->context , st->family , st->units @@ -354,18 +354,18 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER // all the dimensions of the chart, has the same algorithm, multiplier and divisor // we add all dimensions as labels - prometheus_label_copy(dimension, (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); + prometheus_label_copy(dimension, (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); - if(unlikely(output_options & PROMETHEUS_OUTPUT_HELP)) + if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP)) buffer_sprintf(wb , "# COMMENT %s_%s%s: chart \"%s\", context \"%s\", family \"%s\", dimension \"%s\", value * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT " %s %s (%s)\n" , prefix , context , suffix - , (output_options & PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id , st->context , st->family - , (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id , rd->multiplier , rd->divisor , h @@ -373,7 +373,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER , t ); - if(unlikely(output_options & PROMETHEUS_OUTPUT_TYPES)) + if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES)) buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s %s\n" , prefix , context @@ -381,7 +381,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER , t ); - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(wb , "%s_%s%s{chart=\"%s\",family=\"%s\",dimension=\"%s\"%s} " COLLECTED_NUMBER_FORMAT " %llu\n" , prefix @@ -411,19 +411,19 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER // the dimensions of the chart, do not have the same algorithm, multiplier or divisor // we create a metric per dimension - prometheus_name_copy(dimension, (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); + prometheus_name_copy(dimension, (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); - if(unlikely(output_options & PROMETHEUS_OUTPUT_HELP)) + if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP)) buffer_sprintf(wb , "# COMMENT %s_%s_%s%s: chart \"%s\", context \"%s\", family \"%s\", dimension \"%s\", value * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT " %s %s (%s)\n" , prefix , context , dimension , suffix - , (output_options & PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && st->name) ? st->name : st->id , st->context , st->family - , (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id , rd->multiplier , rd->divisor , h @@ -431,7 +431,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER , t ); - if(unlikely(output_options & PROMETHEUS_OUTPUT_TYPES)) + if(unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES)) buffer_sprintf(wb, "# COMMENT TYPE %s_%s_%s%s %s\n" , prefix , context @@ -440,7 +440,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER , t ); - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(wb , "%s_%s_%s%s{chart=\"%s\",family=\"%s\"%s} " COLLECTED_NUMBER_FORMAT " %llu\n" , prefix @@ -480,21 +480,21 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER else if(BACKEND_OPTIONS_DATA_SOURCE(backend_options) == BACKEND_SOURCE_DATA_SUM) suffix = "_sum"; - prometheus_label_copy(dimension, (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); + prometheus_label_copy(dimension, (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); - if (unlikely(output_options & PROMETHEUS_OUTPUT_HELP)) + if (unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP)) buffer_sprintf(wb, "# COMMENT %s_%s%s%s: dimension \"%s\", value is %s, gauge, dt %llu to %llu inclusive\n" , prefix , context , units , suffix - , (output_options & PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id + , (output_options & BACKENDS_PROMETHEUS_OUTPUT_NAMES && rd->name) ? rd->name : rd->id , st->units , (unsigned long long)first_t , (unsigned long long)last_t ); - if (unlikely(output_options & PROMETHEUS_OUTPUT_TYPES)) + if (unlikely(output_options & BACKENDS_PROMETHEUS_OUTPUT_TYPES)) buffer_sprintf(wb, "# COMMENT TYPE %s_%s%s%s gauge\n" , prefix , context @@ -502,7 +502,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER , suffix ); - if(output_options & PROMETHEUS_OUTPUT_TIMESTAMPS) + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS) buffer_sprintf(wb, "%s_%s%s%s{chart=\"%s\",family=\"%s\",dimension=\"%s\"%s} " CALCULATED_NUMBER_FORMAT " %llu\n" , prefix , context @@ -581,7 +581,7 @@ inline static void remote_write_split_words(char *str, char **words, int max_wor } } -void rrd_stats_remote_write_allmetrics_prometheus( +void backends_rrd_stats_remote_write_allmetrics_prometheus( RRDHOST *host , const char *__hostname , const char *prefix @@ -595,7 +595,7 @@ void rrd_stats_remote_write_allmetrics_prometheus( char hostname[PROMETHEUS_ELEMENT_MAX + 1]; prometheus_label_copy(hostname, __hostname, PROMETHEUS_ELEMENT_MAX); - add_host_info("netdata_info", hostname, host->program_name, host->program_version, now_realtime_usec() / USEC_PER_MS); + backends_add_host_info("netdata_info", hostname, host->program_name, host->program_version, now_realtime_usec() / USEC_PER_MS); if(host->tags && *(host->tags)) { char tags[PROMETHEUS_LABELS_MAX + 1]; @@ -605,10 +605,10 @@ void rrd_stats_remote_write_allmetrics_prometheus( remote_write_split_words(tags, words, PROMETHEUS_LABELS_MAX_NUMBER); - add_host_info("netdata_host_tags_info", hostname, NULL, NULL, now_realtime_usec() / USEC_PER_MS); + backends_add_host_info("netdata_host_tags_info", hostname, NULL, NULL, now_realtime_usec() / USEC_PER_MS); for(i = 0; words[i] != NULL && words[i + 1] != NULL && (i + 1) < PROMETHEUS_LABELS_MAX_NUMBER; i += 2) { - add_tag(words[i], words[i + 1]); + backends_add_tag(words[i], words[i + 1]); } } @@ -667,7 +667,7 @@ void rrd_stats_remote_write_allmetrics_prometheus( prometheus_label_copy(dimension, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s%s", prefix, context, suffix); - add_metric(name, chart, family, dimension, hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); + backends_add_metric(name, chart, family, dimension, hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); (*count_dims)++; } else { @@ -677,7 +677,7 @@ void rrd_stats_remote_write_allmetrics_prometheus( prometheus_name_copy(dimension, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s_%s%s", prefix, context, dimension, suffix); - add_metric(name, chart, family, NULL, hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); + backends_add_metric(name, chart, family, NULL, hostname, rd->last_collected_value, timeval_msec(&rd->last_collected_time)); (*count_dims)++; } } @@ -697,7 +697,7 @@ void rrd_stats_remote_write_allmetrics_prometheus( prometheus_label_copy(dimension, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX); snprintf(name, PROMETHEUS_LABELS_MAX, "%s_%s%s%s", prefix, context, units, suffix); - add_metric(name, chart, family, dimension, hostname, value, last_t * MSEC_PER_SEC); + backends_add_metric(name, chart, family, dimension, hostname, value, last_t * MSEC_PER_SEC); (*count_dims)++; } } @@ -710,7 +710,7 @@ void rrd_stats_remote_write_allmetrics_prometheus( } #endif /* ENABLE_PROMETHEUS_REMOTE_WRITE */ -static inline time_t prometheus_preparation(RRDHOST *host, BUFFER *wb, BACKEND_OPTIONS backend_options, const char *server, time_t now, PROMETHEUS_OUTPUT_OPTIONS output_options) { +static inline time_t prometheus_preparation(RRDHOST *host, BUFFER *wb, BACKEND_OPTIONS backend_options, const char *server, time_t now, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options) { if(!server || !*server) server = "default"; time_t after = prometheus_server_last_access(server, host, now); @@ -726,7 +726,7 @@ static inline time_t prometheus_preparation(RRDHOST *host, BUFFER *wb, BACKEND_O after = now - global_backend_update_every; } - if(output_options & PROMETHEUS_OUTPUT_HELP) { + if(output_options & BACKENDS_PROMETHEUS_OUTPUT_HELP) { char *mode; if(BACKEND_OPTIONS_DATA_SOURCE(backend_options) == BACKEND_SOURCE_DATA_AS_COLLECTED) mode = "as collected"; @@ -751,7 +751,7 @@ static inline time_t prometheus_preparation(RRDHOST *host, BUFFER *wb, BACKEND_O return after; } -void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, PROMETHEUS_OUTPUT_OPTIONS output_options) { +void backends_rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options) { time_t before = now_realtime_sec(); // we start at the point we had stopped before @@ -760,7 +760,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(RRDHOST *host, BU rrd_stats_api_v1_charts_allmetrics_prometheus(host, wb, prefix, backend_options, after, before, 0, output_options); } -void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, PROMETHEUS_OUTPUT_OPTIONS output_options) { +void backends_rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options) { time_t before = now_realtime_sec(); // we start at the point we had stopped before @@ -774,7 +774,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(RRDHOST *host, BUFF } #if ENABLE_PROMETHEUS_REMOTE_WRITE -int process_prometheus_remote_write_response(BUFFER *b) { +int backends_process_prometheus_remote_write_response(BUFFER *b) { if(unlikely(!b)) return 1; const char *s = buffer_tostring(b); diff --git a/backends/prometheus/backend_prometheus.h b/backends/prometheus/backend_prometheus.h index d58d24004b..8c14ddc26c 100644 --- a/backends/prometheus/backend_prometheus.h +++ b/backends/prometheus/backend_prometheus.h @@ -5,22 +5,22 @@ #include "backends/backends.h" -typedef enum prometheus_output_flags { - PROMETHEUS_OUTPUT_NONE = 0, - PROMETHEUS_OUTPUT_HELP = (1 << 0), - PROMETHEUS_OUTPUT_TYPES = (1 << 1), - PROMETHEUS_OUTPUT_NAMES = (1 << 2), - PROMETHEUS_OUTPUT_TIMESTAMPS = (1 << 3), - PROMETHEUS_OUTPUT_VARIABLES = (1 << 4), - PROMETHEUS_OUTPUT_OLDUNITS = (1 << 5), - PROMETHEUS_OUTPUT_HIDEUNITS = (1 << 6) -} PROMETHEUS_OUTPUT_OPTIONS; +typedef enum backends_prometheus_output_flags { + BACKENDS_PROMETHEUS_OUTPUT_NONE = 0, + BACKENDS_PROMETHEUS_OUTPUT_HELP = (1 << 0), + BACKENDS_PROMETHEUS_OUTPUT_TYPES = (1 << 1), + BACKENDS_PROMETHEUS_OUTPUT_NAMES = (1 << 2), + BACKENDS_PROMETHEUS_OUTPUT_TIMESTAMPS = (1 << 3), + BACKENDS_PROMETHEUS_OUTPUT_VARIABLES = (1 << 4), + BACKENDS_PROMETHEUS_OUTPUT_OLDUNITS = (1 << 5), + BACKENDS_PROMETHEUS_OUTPUT_HIDEUNITS = (1 << 6) +} BACKENDS_PROMETHEUS_OUTPUT_OPTIONS; -extern void rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_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, BACKEND_OPTIONS backend_options, PROMETHEUS_OUTPUT_OPTIONS output_options); +extern void backends_rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options); +extern void backends_rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(RRDHOST *host, BUFFER *wb, const char *server, const char *prefix, BACKEND_OPTIONS backend_options, BACKENDS_PROMETHEUS_OUTPUT_OPTIONS output_options); #if ENABLE_PROMETHEUS_REMOTE_WRITE -extern void rrd_stats_remote_write_allmetrics_prometheus( +extern void backends_rrd_stats_remote_write_allmetrics_prometheus( RRDHOST *host , const char *__hostname , const char *prefix @@ -31,7 +31,7 @@ extern void rrd_stats_remote_write_allmetrics_prometheus( , size_t *count_dims , size_t *count_dims_skipped ); -extern int process_prometheus_remote_write_response(BUFFER *b); +extern int backends_process_prometheus_remote_write_response(BUFFER *b); #endif #endif //NETDATA_BACKEND_PROMETHEUS_H diff --git a/backends/prometheus/remote_write/remote_write.cc b/backends/prometheus/remote_write/remote_write.cc index 8246feefa6..d74e7d8be9 100644 --- a/backends/prometheus/remote_write/remote_write.cc +++ b/backends/prometheus/remote_write/remote_write.cc @@ -1,25 +1,24 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include <snappy.h> -#include "remote_write.pb.h" +#include "../../../exporting/prometheus/remote_write/remote_write.pb.h" #include "remote_write.h" using namespace prometheus; +static google::protobuf::Arena arena; +static WriteRequest *write_request; -google::protobuf::Arena arena; -WriteRequest *write_request; - -void init_write_request() { +void backends_init_write_request() { GOOGLE_PROTOBUF_VERIFY_VERSION; write_request = google::protobuf::Arena::CreateMessage<WriteRequest>(&arena); } -void clear_write_request() { +void backends_clear_write_request() { write_request->clear_timeseries(); } -void add_host_info(const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp) { +void backends_add_host_info(const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp) { TimeSeries *timeseries; Sample *sample; Label *label; @@ -52,7 +51,7 @@ void add_host_info(const char *name, const char *instance, const char *applicati } // adds tag to the last created timeseries -void add_tag(char *tag, char *value) { +void backends_add_tag(char *tag, char *value) { TimeSeries *timeseries; Label *label; @@ -63,7 +62,7 @@ void add_tag(char *tag, char *value) { label->set_value(value); } -void add_metric(const char *name, const char *chart, const char *family, const char *dimension, const char *instance, const double value, const int64_t timestamp) { +void backends_add_metric(const char *name, const char *chart, const char *family, const char *dimension, const char *instance, const double value, const int64_t timestamp) { TimeSeries *timeseries; Sample *sample; Label *label; @@ -97,7 +96,7 @@ void add_metric(const char *name, const char *chart, const char *family, const c sample->set_timestamp(timestamp); } -size_t get_write_request_size(){ +size_t backends_get_write_request_size(){ #if GOOGLE_PROTOBUF_VERSION < 3001000 size_t size = (size_t)snappy::MaxCompressedLength(write_request->ByteSize()); #else @@ -107,7 +106,7 @@ size_t get_write_request_size(){ return (size < INT_MAX)?size:0; } -int pack_write_request(char *buffer, size_t *size) { +int backends_pack_write_request(char *buffer, size_t *size) { std::string uncompressed_write_request; if(write_request->SerializeToString(&uncompressed_write_request) == false) return 1; @@ -116,6 +115,6 @@ int pack_write_request(char *buffer, size_t *size) { return 0; } -void protocol_buffers_shutdown() { +void backends_protocol_buffers_shutdown() { google::protobuf::ShutdownProtobufLibrary(); } diff --git a/backends/prometheus/remote_write/remote_write.h b/backends/prometheus/remote_write/remote_write.h index edcc477b8d..1307d72810 100644 --- a/backends/prometheus/remote_write/remote_write.h +++ b/backends/prometheus/remote_write/remote_write.h @@ -7,21 +7,21 @@ extern "C" { #endif -void init_write_request(); +void backends_init_write_request(); -void clear_write_request(); +void backends_clear_write_request(); -void add_host_info(const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp); +void backends_add_host_info(const char *name, const char *instance, const char *application, const char *version, const int64_t timestamp); -void add_tag(char *tag, char *value); +void backends_add_tag(char *tag, char *value); -void add_metric(const char *name, const char *chart, const char *family, const char *dimension, const char *instance, const double value, const int64_t timestamp); +void backends_add_metric(const char *name, const char *chart, const char *family, const char *dimension, const char *instance, const double value, const int64_t timestamp); -size_t get_write_request_size(); +size_t backends_get_write_request_size(); -int pack_write_request(char *buffer, size_t *size); +int backends_pack_write_request(char *buffer, size_t *size); -void protocol_buffers_shutdown(); +void backends_protocol_buffers_shutdown(); #ifdef __cplusplus } |