summaryrefslogtreecommitdiffstats
path: root/exporting
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2020-04-13 08:39:52 -0400
committerAustin S. Hemmelgarn <austin@netdata.cloud>2020-04-13 08:42:22 -0400
commite2874320fc027f7ab51ab3e115d5b1889b8fd747 (patch)
treecd755ef9b8522634c61aed9888239c9b67394157 /exporting
parent353780082c0ac8525e5b52aa8a29bbf5b70871e8 (diff)
Revert changes since v1.21 in pereparation for hotfix release.
Diffstat (limited to 'exporting')
-rw-r--r--exporting/aws_kinesis/aws_kinesis.c36
-rw-r--r--exporting/exporting_engine.c10
-rw-r--r--exporting/exporting_engine.h77
-rw-r--r--exporting/graphite/graphite.c2
-rw-r--r--exporting/init_connectors.c16
-rw-r--r--exporting/json/json.c2
-rw-r--r--exporting/mongodb/mongodb.c60
-rw-r--r--exporting/mongodb/mongodb.h3
-rw-r--r--exporting/opentsdb/opentsdb.c4
-rw-r--r--exporting/process_data.c17
-rw-r--r--exporting/prometheus/prometheus.c290
-rw-r--r--exporting/prometheus/prometheus.h6
-rw-r--r--exporting/prometheus/remote_write/remote_write.c2
-rw-r--r--exporting/read_config.c183
-rw-r--r--exporting/send_data.c50
-rw-r--r--exporting/send_internal_metrics.c166
-rw-r--r--exporting/tests/exporting_doubles.c22
-rw-r--r--exporting/tests/exporting_fixtures.c32
-rw-r--r--exporting/tests/netdata_doubles.c86
-rw-r--r--exporting/tests/test_exporting_engine.c471
-rw-r--r--exporting/tests/test_exporting_engine.h11
21 files changed, 253 insertions, 1293 deletions
diff --git a/exporting/aws_kinesis/aws_kinesis.c b/exporting/aws_kinesis/aws_kinesis.c
index 938569a9eb..4b0d5f74a4 100644
--- a/exporting/aws_kinesis/aws_kinesis.c
+++ b/exporting/aws_kinesis/aws_kinesis.c
@@ -75,23 +75,9 @@ void aws_kinesis_connector_worker(void *instance_p)
uv_mutex_lock(&instance->mutex);
uv_cond_wait(&instance->cond_var, &instance->mutex);
- // reset the monitoring chart counters
- stats->received_bytes =
- stats->sent_bytes =
- stats->sent_metrics =
- stats->lost_metrics =
- stats->receptions =
- stats->transmission_successes =
- stats->transmission_failures =
- stats->data_lost_events =
- stats->lost_bytes =
- stats->reconnects = 0;
-
BUFFER *buffer = (BUFFER *)instance->buffer;
size_t buffer_len = buffer_strlen(buffer);
- stats->buffered_bytes = buffer_len;
-
size_t sent = 0;
while (sent < buffer_len) {
@@ -129,7 +115,7 @@ void aws_kinesis_connector_worker(void *instance_p)
connector_specific_data, connector_specific_config->stream_name, partition_key, first_char, record_len);
sent += record_len;
- stats->transmission_successes++;
+ stats->chart_transmission_successes++;
size_t sent_bytes = 0, lost_bytes = 0;
@@ -141,34 +127,30 @@ void aws_kinesis_connector_worker(void *instance_p)
"EXPORTING: failed to write data to database backend '%s'. Willing to write %zu bytes, wrote %zu bytes.",
instance->config.destination, sent_bytes, sent_bytes - lost_bytes);
- stats->transmission_failures++;
- stats->data_lost_events++;
- stats->lost_bytes += lost_bytes;
+ stats->chart_transmission_failures++;
+ stats->chart_data_lost_events++;
+ stats->chart_lost_bytes += lost_bytes;
// estimate the number of lost metrics
- stats->lost_metrics += (collected_number)(
- stats->buffered_metrics *
+ stats->chart_lost_metrics += (collected_number)(
+ stats->chart_buffered_metrics *
(buffer_len && (lost_bytes > buffer_len) ? (double)lost_bytes / buffer_len : 1));
break;
} else {
- stats->receptions++;
+ stats->chart_receptions++;
}
if (unlikely(netdata_exit))
break;
}
- stats->sent_bytes += sent;
+ stats->chart_sent_bytes += sent;
if (likely(sent == buffer_len))
- stats->sent_metrics = stats->buffered_metrics;
+ stats->chart_sent_metrics = stats->chart_buffered_metrics;
buffer_flush(buffer);
- send_internal_metrics(instance);
-
- stats->buffered_metrics = 0;
-
uv_mutex_unlock(&instance->mutex);
#ifdef UNIT_TESTING
diff --git a/exporting/exporting_engine.c b/exporting/exporting_engine.c
index 93347328cd..0a38d66bbe 100644
--- a/exporting/exporting_engine.c
+++ b/exporting/exporting_engine.c
@@ -35,11 +35,6 @@ void *exporting_main(void *ptr)
goto cleanup;
}
- RRDSET *st_main_rusage = NULL;
- RRDDIM *rd_main_user = NULL;
- RRDDIM *rd_main_system = NULL;
- create_main_rusage_chart(&st_main_rusage, &rd_main_user, &rd_main_system);
-
usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC;
heartbeat_t hb;
heartbeat_init(&hb);
@@ -60,7 +55,10 @@ void *exporting_main(void *ptr)
break;
}
- send_main_rusage(st_main_rusage, rd_main_user, rd_main_system);
+ if (send_internal_metrics(engine) != 0) {
+ error("EXPORTING: cannot send metrics for the operation of exporting engine");
+ break;
+ }
#ifdef UNIT_TESTING
break;
diff --git a/exporting/exporting_engine.h b/exporting/exporting_engine.h
index 94daf98e05..1a3a3ecd09 100644
--- a/exporting/exporting_engine.h
+++ b/exporting/exporting_engine.h
@@ -14,10 +14,10 @@
extern struct config exporting_config;
#define EXPORTING_UPDATE_EVERY_OPTION_NAME "update every"
-#define EXPORTING_UPDATE_EVERY_DEFAULT 10
+#define EXPORTING_UPDATE_EVERY_DEFAULT 10
typedef enum exporting_options {
- EXPORTING_OPTION_NON = 0,
+ EXPORTING_OPTION_NONE = 0,
EXPORTING_SOURCE_DATA_AS_COLLECTED = (1 << 0),
EXPORTING_SOURCE_DATA_AVERAGE = (1 << 1),
@@ -42,22 +42,10 @@ typedef enum exporting_options {
(instance->config.options & EXPORTING_OPTION_SEND_AUTOMATIC_LABELS && \
label->label_source != LABEL_SOURCE_NETDATA_CONF))
-typedef enum exporting_connector_types {
- EXPORTING_CONNECTOR_TYPE_UNKNOWN, // Invalid type
- EXPORTING_CONNECTOR_TYPE_GRAPHITE, // Send plain text to Graphite
- EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_TELNET, // Send data to OpenTSDB using telnet API
- EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_HTTP, // Send data to OpenTSDB using HTTP API
- EXPORTING_CONNECTOR_TYPE_JSON, // Stores the data using JSON.
- EXPORTING_CONNECTOR_TYPE_PROMETHEUS_REMOTE_WRITE, // The user selected to use Prometheus backend
- EXPORTING_CONNECTOR_TYPE_KINESIS, // Send message to AWS Kinesis
- EXPORTING_CONNECTOR_TYPE_MONGODB, // Send data to MongoDB collection
- EXPORTING_CONNECTOR_TYPE_NUM // Number of backend types
-} EXPORTING_CONNECTOR_TYPE;
-
struct engine;
struct instance_config {
- EXPORTING_CONNECTOR_TYPE type;
+ BACKEND_TYPE type;
const char *name;
const char *destination;
@@ -99,42 +87,18 @@ struct engine_config {
};
struct stats {
- collected_number buffered_metrics;
- collected_number lost_metrics;
- collected_number sent_metrics;
- collected_number buffered_bytes;
- collected_number lost_bytes;
- collected_number sent_bytes;
- collected_number received_bytes;
- collected_number transmission_successes;
- collected_number data_lost_events;
- collected_number reconnects;
- collected_number transmission_failures;
- collected_number receptions;
-
- int initialized;
-
- RRDSET *st_metrics;
- RRDDIM *rd_buffered_metrics;
- RRDDIM *rd_lost_metrics;
- RRDDIM *rd_sent_metrics;
-
- RRDSET *st_bytes;
- RRDDIM *rd_buffered_bytes;
- RRDDIM *rd_lost_bytes;
- RRDDIM *rd_sent_bytes;
- RRDDIM *rd_received_bytes;
-
- RRDSET *st_ops;
- RRDDIM *rd_transmission_successes;
- RRDDIM *rd_data_lost_events;
- RRDDIM *rd_reconnects;
- RRDDIM *rd_transmission_failures;
- RRDDIM *rd_receptions;
-
- RRDSET *st_rusage;
- RRDDIM *rd_user;
- RRDDIM *rd_system;
+ collected_number chart_buffered_metrics;
+ collected_number chart_lost_metrics;
+ collected_number chart_sent_metrics;
+ collected_number chart_buffered_bytes;
+ collected_number chart_received_bytes;
+ collected_number chart_sent_bytes;
+ collected_number chart_receptions;
+ collected_number chart_transmission_successes;
+ collected_number chart_transmission_failures;
+ collected_number chart_data_lost_events;
+ collected_number chart_lost_bytes;
+ collected_number chart_reconnects;
};
struct instance {
@@ -186,12 +150,10 @@ struct engine {
struct instance *instance_root;
};
-extern struct instance *prometheus_exporter_instance;
-
void *exporting_main(void *ptr);
struct engine *read_exporting_config();
-EXPORTING_CONNECTOR_TYPE exporting_select_type(const char *type);
+BACKEND_TYPE exporting_select_type(const char *type);
int init_connectors(struct engine *engine);
@@ -217,17 +179,12 @@ int end_chart_formatting(struct engine *engine, RRDSET *st);
int end_host_formatting(struct engine *engine, RRDHOST *host);
int end_batch_formatting(struct engine *engine);
int flush_host_labels(struct instance *instance, RRDHOST *host);
-int simple_connector_update_buffered_bytes(struct instance *instance);
int exporting_discard_response(BUFFER *buffer, struct instance *instance);
void simple_connector_receive_response(int *sock, struct instance *instance);
void simple_connector_send_buffer(int *sock, int *failures, struct instance *instance);
void simple_connector_worker(void *instance_p);
-void create_main_rusage_chart(RRDSET **st_rusage, RRDDIM **rd_user, RRDDIM **rd_system);
-void send_main_rusage(RRDSET *st_rusage, RRDDIM *rd_user, RRDDIM *rd_system);
-void send_internal_metrics(struct instance *instance);
-
-#include "exporting/prometheus/prometheus.h"
+int send_internal_metrics(struct engine *engine);
#endif /* NETDATA_EXPORTING_ENGINE_H */
diff --git a/exporting/graphite/graphite.c b/exporting/graphite/graphite.c
index d3f928583c..f815bff89d 100644
--- a/exporting/graphite/graphite.c
+++ b/exporting/graphite/graphite.c
@@ -27,7 +27,7 @@ int init_graphite_instance(struct instance *instance)
instance->end_chart_formatting = NULL;
instance->end_host_formatting = flush_host_labels;
- instance->end_batch_formatting = simple_connector_update_buffered_bytes;
+ instance->end_batch_formatting = NULL;
instance->send_header = NULL;
instance->check_response = exporting_discard_response;
diff --git a/exporting/init_connectors.c b/exporting/init_connectors.c
index 0db0ca1354..798101fd9c 100644
--- a/exporting/init_connectors.c
+++ b/exporting/init_connectors.c
@@ -32,35 +32,35 @@ int init_connectors(struct engine *engine)
instance->after = engine->now;
switch (instance->config.type) {
- case EXPORTING_CONNECTOR_TYPE_GRAPHITE:
+ case BACKEND_TYPE_GRAPHITE:
if (init_graphite_instance(instance) != 0)
return 1;
break;
- case EXPORTING_CONNECTOR_TYPE_JSON:
+ case BACKEND_TYPE_JSON:
if (init_json_instance(instance) != 0)
return 1;
break;
- case EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_TELNET:
+ case BACKEND_TYPE_OPENTSDB_USING_TELNET:
if (init_opentsdb_telnet_instance(instance) != 0)
return 1;
break;
- case EXPORTING_CONNECTOR_TYPE_OPENTSDB_USING_HTTP:
+ case BACKEND_TYPE_OPENTSDB_USING_HTTP:
if (init_opentsdb_http_instance(instance) != 0)
return 1;
break;
- case EXPORTING_CONNECTOR_TYPE_PROMETHEUS_REMOTE_WRITE:
+ case BACKEND_TYPE_PROMETHEUS_REMOTE_WRITE:
#if ENABLE_PROMETHEUS_REMOTE_WRITE
if (init_prometheus_remote_write_instance(instance) != 0)
return 1;
#endif
break;
- case EXPORTING_CONNECTOR_TYPE_KINESIS:
+ case BACKEND_TYPE_KINESIS:
#if HAVE_KINESIS
if (init_aws_kinesis_instance(instance) != 0)
return 1;
#endif
break;
- case EXPORTING_CONNECTOR_TYPE_MONGODB:
+ case BACKEND_TYPE_MONGODB:
#if HAVE_MONGOC
if (init_mongodb_instance(instance) != 0)
return 1;
@@ -77,7 +77,7 @@ int init_connectors(struct engine *engine)
error("EXPORTING: cannot create tread worker. uv_thread_create(): %s", uv_strerror(error));
return 1;
}
- char threadname[NETDATA_THREAD_NAME_MAX + 1];
+ char threadname[NETDATA_THREAD_NAME_MAX+1];
snprintfz(threadname, NETDATA_THREAD_NAME_MAX, "EXPORTING-%zu", instance->index);
uv_thread_set_name_np(instance->thread, threadname);
}
diff --git a/exporting/json/json.c b/exporting/json/json.c
index b334804cff..9886b55567 100644
--- a/exporting/json/json.c
+++ b/exporting/json/json.c
@@ -27,7 +27,7 @@ int init_json_instance(struct instance *instance)
instance->end_chart_formatting = NULL;
instance->end_host_formatting = flush_host_labels;
- instance->end_batch_formatting = simple_connector_update_buffered_bytes;
+ instance->end_batch_formatting = NULL;
instance->send_header = NULL;
instance->check_response = exporting_discard_response;
diff --git a/exporting/mongodb/mongodb.c b/exporting/mongodb/mongodb.c
index f20c4f1c80..b10a8fa664 100644
--- a/exporting/mongodb/mongodb.c
+++ b/exporting/mongodb/mongodb.c
@@ -183,10 +183,8 @@ int format_batch_mongodb(struct instance *instance)
// ring buffer is full, reuse the oldest element
connector_specific_data->first_buffer = connector_specific_data->first_buffer->next;
free_bson(insert, connector_specific_data->last_buffer->documents_inserted);
- connector_specific_data->total_documents_inserted -= connector_specific_data->last_buffer->documents_inserted;
- stats->buffered_bytes -= connector_specific_data->last_buffer->buffered_bytes;
}
- insert = callocz((size_t)stats->buffered_metrics, sizeof(bson_t *));
+ insert = callocz((size_t)stats->chart_buffered_metrics, sizeof(bson_t *));
connector_specific_data->last_buffer->insert = insert;
BUFFER *buffer = (BUFFER *)instance->buffer;
@@ -195,7 +193,7 @@ int format_batch_mongodb(struct instance *instance)
size_t documents_inserted = 0;
- while (*end && documents_inserted <= (size_t)stats->buffered_metrics) {
+ while (*end && documents_inserted <= (size_t)stats->chart_buffered_metrics) {
while (*end && *end != '\n')
end++;
@@ -210,8 +208,7 @@ int format_batch_mongodb(struct instance *instance)
insert[documents_inserted] = bson_new_from_json((const uint8_t *)start, -1, &bson_error);
if (unlikely(!insert[documents_inserted])) {
- error(
- "EXPORTING: Failed creating a BSON document from a JSON string \"%s\" : %s", start, bson_error.message);
+ error("EXPORTING: %s", bson_error.message);
free_bson(insert, documents_inserted);
return 1;
}
@@ -221,16 +218,8 @@ int format_batch_mongodb(struct instance *instance)
documents_inserted++;
}
- stats->buffered_bytes += connector_specific_data->last_buffer->buffered_bytes = buffer_strlen(buffer);
-
buffer_flush(buffer);
- // The stats->buffered_metrics is used in the MongoDB batch formatting as a variable for the number
- // of metrics, added in the current iteration, so we are clearing it here. We will use the
- // connector_specific_data->total_documents_inserted in the worker to show the statistics.
- stats->buffered_metrics = 0;
- connector_specific_data->total_documents_inserted += documents_inserted;
-
connector_specific_data->last_buffer->documents_inserted = documents_inserted;
connector_specific_data->last_buffer = connector_specific_data->last_buffer->next;
@@ -257,25 +246,11 @@ void mongodb_connector_worker(void *instance_p)
uv_mutex_lock(&instance->mutex);
uv_cond_wait(&instance->cond_var, &instance->mutex);
- // reset the monitoring chart counters
- stats->received_bytes =
- stats->sent_bytes =
- stats->sent_metrics =
- stats->lost_metrics =
- stats->receptions =
- stats->transmission_successes =
- stats->transmission_failures =
- stats->data_lost_events =
- stats->lost_bytes =
- stats->reconnects = 0;
-
bson_t **insert = connector_specific_data->first_buffer->insert;
size_t documents_inserted = connector_specific_data->first_buffer->documents_inserted;
- size_t buffered_bytes = connector_specific_data->first_buffer->buffered_bytes;
connector_specific_data->first_buffer->insert = NULL;
connector_specific_data->first_buffer->documents_inserted = 0;
- connector_specific_data->first_buffer->buffered_bytes = 0;
connector_specific_data->first_buffer = connector_specific_data->first_buffer->next;
uv_mutex_unlock(&instance->mutex);
@@ -304,10 +279,9 @@ void mongodb_connector_worker(void *instance_p)
NULL,
NULL,
&bson_error))) {
- stats->sent_metrics = documents_inserted;
- stats->sent_bytes += data_size;
- stats->transmission_successes++;
- stats->receptions++;
+ stats->chart_sent_bytes += data_size;
+ stats->chart_transmission_successes++;
+ stats->chart_receptions++;
} else {
// oops! we couldn't send (all or some of the) data
error("EXPORTING: %s", bson_error.message);
@@ -316,10 +290,10 @@ void mongodb_connector_worker(void *instance_p)
"Willing to write %zu bytes, wrote %zu bytes.",
instance->config.destination, data_size, 0UL);
- stats->transmission_failures++;
- stats->data_lost_events++;
- stats->lost_bytes += buffered_bytes;
- stats->lost_metrics += documents_inserted;
+ stats->chart_transmission_failures++;
+ stats->chart_data_lost_events++;
+ stats->chart_lost_bytes += data_size;
+ stats->chart_lost_metrics += stats->chart_buffered_metrics;
}
free_bson(insert, documents_inserted);
@@ -327,18 +301,8 @@ void mongodb_connector_worker(void *instance_p)
if (unlikely(netdata_exit))
break;
- uv_mutex_lock(&instance->mutex);
-
- stats->buffered_metrics = connector_specific_data->total_documents_inserted;
-
- send_internal_metrics(instance);
-
- connector_specific_data->total_documents_inserted -= documents_inserted;
-
- stats->buffered_metrics = 0;
- stats->buffered_bytes -= buffered_bytes;
-
- uv_mutex_unlock(&instance->mutex);
+ stats->chart_sent_bytes += data_size;
+ stats->chart_sent_metrics = stats->chart_buffered_metrics;
#ifdef UNIT_TESTING
break;
diff --git a/exporting/mongodb/mongodb.h b/exporting/mongodb/mongodb.h
index 5116e66fab..0f23705f55 100644
--- a/exporting/mongodb/mongodb.h
+++ b/exporting/mongodb/mongodb.h
@@ -10,7 +10,6 @@
struct bson_buffer {
bson_t **insert;
size_t documents_inserted;
- size_t buffered_bytes;
struct bson_buffer *next;
};
@@ -19,8 +18,6 @@ struct mongodb_specific_data {
mongoc_client_t *client;
mongoc_collection_t *collection;
- size_t total_documents_inserted;
-
bson_t **current_insert;
struct bson_buffer *first_buffer;
struct bson_buffer *last_buffer;
diff --git a/exporting/opentsdb/opentsdb.c b/exporting/opentsdb/opentsdb.c
index 2d5b2db698..54f3c3c04d 100644
--- a/exporting/opentsdb/opentsdb.c
+++ b/exporting/opentsdb/opentsdb.c
@@ -27,7 +27,7 @@ int init_opentsdb_telnet_instance(struct instance *instance)
instance->end_chart_formatting = NULL;
instance->end_host_formatting = flush_host_labels;
- instance->end_batch_formatting = simple_connector_update_buffered_bytes;
+ instance->end_batch_formatting = NULL;
instance->send_header = NULL;
instance->check_response = exporting_discard_response;
@@ -68,7 +68,7 @@ int init_opentsdb_http_instance(struct instance *instance)
instance->end_chart_formatting = NULL;
instance->end_host_formatting = flush_host_labels;
- instance->end_batch_formatting = simple_connector_update_buffered_bytes;
+ instance->end_batch_formatting = NULL;
instance->send_header = NULL;
instance->check_response = exporting_discard_response;
diff --git a/exporting/process_data.c b/exporting/process_data.c
index f2442e701c..c902aabdda 100644
--- a/exporting/process_data.c
+++ b/exporting/process_data.c
@@ -206,7 +206,7 @@ int start_host_formatting(struct engine *engine, RRDHOST *host)
* Start chart formatting for every connector instance's buffer
*
* @param engine an engine data structure.
- * @param st a chart.
+ * @param a chart.
* @return Returns 0 on success, 1 on failure.
*/
int start_chart_formatting(struct engine *engine, RRDSET *st)
@@ -242,7 +242,7 @@ int metric_formatting(struct engine *engine, RRDDIM *rd)
error("EXPORTING: cannot format metric for %s", instance->config.name);
return 1;
}
- instance->stats.buffered_metrics++;
+ instance->stats.chart_buffered_metrics++;
}
}
@@ -390,19 +390,6 @@ int flush_host_labels(struct instance *instance, RRDHOST *host)
}
/**
- * Update stats for buffered bytes
- *
- * @param instance an instance data structure.
- * @return Always returns 0.
- */
-int simple_connector_update_buffered_bytes(struct instance *instance)
-{
- instance->stats.buffered_bytes = (collected_number)buffer_strlen((BUFFER *)(instance->buffer));
-
- return 0;
-}
-
-/**
* Notify workers
*
* Notify exporting connector instance working threads that data is ready to send.
diff --git a/exporting/prometheus/prometheus.c b/exporting/prometheus/prometheus.c
index f25ceed9d5..7e91a0c962 100644
--- a/exporting/prometheus/prometheus.c
+++ b/exporting/prometheus/prometheus.c
@@ -7,16 +7,10 @@
// PROMETHEUS
// /api/v1/allmetrics?format=prometheus and /api/v1/allmetrics?format=prometheus_all_hosts
-/**
- * Check if a chart can be sent to an external databese
- *
- * @param instance an instance data structure.
- * @param st a chart.
- * @return Returns 1 if the chart can be sent, 0 otherwise.
- */
inline int can_send_rrdset(struct instance *instance, RRDSET *st)
{
RRDHOST *host = st->rrdhost;
+ (void)host;
if (unlikely(rrdset_flag_check(st, RRDSET_FLAG_BACKEND_IGNORE)))
return 0;
@@ -30,7 +24,7 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st)
rrdset_flag_set(st, RRDSET_FLAG_BACKEND_IGNORE);
debug(
D_BACKEND,
- "EXPORTING: not sending chart '%s' of host '%s', because it is disabled for exporting.",
+ "BACKEND: not sending chart '%s' of host '%s', because it is disabled for backends.",
st->id,
host->hostname);
return 0;
@@ -40,7 +34,7 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st)
if (unlikely(!rrdset_is_available_for_backends(st))) {
debug(
D_BACKEND,
- "EXPORTING: not sending chart '%s' of host '%s', because it is not available for exporting.",
+ "BACKEND: not sending chart '%s' of host '%s', because it is not available for backends.",
st->id,
host->hostname);
return 0;
@@ -48,10 +42,10 @@ inline int can_send_rrdset(struct instance *instance, RRDSET *st)
if (unlikely(
st->rrd_memory_mode == RRD_MEMORY_MODE_NONE &&
- !(EXPORTING_OPTIONS_DATA_SOURCE(instance->config.options) == EXPORTING_SOURCE_DATA_AS_COLLECTED))) {
+ !(BACKEND_OPTIONS_DATA_SOURCE(instance->config.options) == BACKEND_SOURCE_DATA_AS_COLLECTED))) {
debug(
D_BACKEND,
- "EXPORTING: not sending chart '%s' of host '%s' because its memory mode is '%s' and the exporting connector requires database access.",
+ "BACKEND: not sending chart '%s' of host '%s' because its memory mode is '%s' and the backend requires database access.",
st->id,
host->hostname,
rrd_memory_mode_name(host->rrd_memory_mode));
@@ -69,19 +63,8 @@ static struct prometheus_server {
struct prometheus_server *next;
} *prometheus_server_root = NULL;
-/**
- * Get the last time when a Prometheus server scraped the Netdata Prometheus exporter.
- *
- * @param server the name of the Prometheus server.
- * @param host a data collecting host.
- * @param now actual time.
- * @return Returns the last time when the server accessed Netdata, or 0 if it is the first occurrence.
- */
static inline time_t prometheus_server_last_access(const char *server, RRDHOST *host, time_t now)
{
-#ifdef UNIT_TESTING
- return 0;
-#endif
static netdata_mutex_t prometheus_server_root_mutex = NETDATA_MUTEX_INITIALIZER;
uint32_t hash = simple_hash(server);
@@ -110,14 +93,6 @@ static inline time_t prometheus_server_last_access(const char *server, RRDHOST *
return 0;
}
-/**
- * Copy and sanitize name.
- *
- * @param d a destination string.
- * @param s a source sting.
- * @param usable the number of characters to copy.
- * @return Returns the length of the copied string.
- */
inline size_t prometheus_name_copy(char *d, const char *s, size_t usable)
{
size_t n;
@@ -135,14 +110,6 @@ inline size_t prometheus_name_copy(char *d, const char *s, size_t usable)
return n;
}
-/**
- * Copy and sanitize label.
- *
- * @param d a destination string.
- * @param s a source sting.
- * @param usable the number of characters to copy.
- * @return Returns the length of the copied string.
- */
inline size_t prometheus_label_copy(char *d, const char *s, size_t usable)
{
size_t n;
@@ -164,15 +131,6 @@ inline size_t prometheus_label_copy(char *d, const char *s, size_t usable)
return n;
}
-/**
- * Copy and sanitize units.
- *
- * @param d a destination string.
- * @param s a source sting.
- * @param usable the number of characters to copy.
- * @param showoldunits set this flag to 1 to show old (before v1.12) units.
- * @return Returns the destination string.
- */
inline char *prometheus_units_copy(char *d, const char *s, size_t usable, int showoldunits)
{
const char *sorig = s;
@@ -245,43 +203,6 @@ inline char *prometheus_units_copy(char *d, const char *s, size_t usable, int sh
return ret;
}
-/**
- * Format host labels for the Prometheus exporter
- *
- * @param instance an instance data structure.
- * @param host a data collecting host.
- */
-void format_host_labels_prometheus(struct instance *instance, RRDHOST *host)
-{
- if (unlikely(!sending_labels_configured(instance)))
- return;
-
- if (!instance->labels)
- instance->labels = buffer_create(1024);
-
- int count = 0;
- rrdhost_check_rdlock(host);
- netdata_rwlock_rdlock(&host->labels_rwlock);
- for (struct label *label = host->labels; label; label = label->next) {
- if (!should_send_label(instance, label))
- continue;
-
- char key[PROMETHEUS_ELEMENT_MAX + 1];
- char value[PROMETHEUS_ELEMENT_MAX + 1];
-
- prometheus_name_copy(key, label->key, PROMETHEUS_ELEMENT_MAX);
- prometheus_label_copy(value, label->value, PROMETHEUS_ELEMENT_MAX);
-
- if (*key && *value) {
- if (count > 0)
- buffer_strcat(instance->labels, ",");
- buffer_sprintf(instance->labels, "%s=\"%s\"", key, value);
- count++;
- }
- }
- netdata_rwlock_unlock(&host->labels_rwlock);
-}
-
struct host_variables_callback_options {
RRDHOST *host;
BUFFER *wb;
@@ -294,13 +215,6 @@ struct host_variables_callback_options {
char name[PROMETHEUS_VARIABLE_MAX + 1];
};
-/**
- * Print host variables.
- *
- * @param rv a variable.
- * @param data callback options.
- * @return Returns 1 if the chart can be sent, 0 otherwise.
- */
static int print_host_variables(RRDVAR *rv, void *data)
{
struct host_variables_callback_options *opts = data;
@@ -360,23 +274,14 @@ static int print_host_variables(RRDVAR *rv, void *data)
return 0;
}
-/**
- * Write metrics in Prometheus format to a buffer.
- *
- * @param instance an instance data structure.
- * @param host a data collecting host.
- * @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.
- * @param allhosts set to 1 if host instance should be in the output for tags.
- * @param output_options options to configure the format of the output.
- */
static void rrd_stats_api_v1_charts_allmetrics_prometheus(
struct instance *instance,
RRDHOST *host,
BUFFER *wb,
const char *prefix,
EXPORTING_OPTIONS exporting_options,
+ time_t after,
+ time_t before,
int allhosts,
PROMETHEUS_OUTPUT_OPTIONS output_options)
<