summaryrefslogtreecommitdiffstats
path: root/exporting/opentsdb
diff options
context:
space:
mode:
Diffstat (limited to 'exporting/opentsdb')
-rw-r--r--exporting/opentsdb/README.md42
-rw-r--r--exporting/opentsdb/opentsdb.c110
-rw-r--r--exporting/opentsdb/opentsdb.h10
3 files changed, 81 insertions, 81 deletions
diff --git a/exporting/opentsdb/README.md b/exporting/opentsdb/README.md
index 6b5f198b0b..3765ad2712 100644
--- a/exporting/opentsdb/README.md
+++ b/exporting/opentsdb/README.md
@@ -1,40 +1,30 @@
<!--
-title: "Export metrics to OpenTSDB with HTTP"
-description: "Archive your Agent's metrics to a OpenTSDB database for long-term storage and further analysis."
+title: "Export metrics to OpenTSDB"
+description: "Archive your Agent's metrics to an OpenTSDB database for long-term storage and further analysis."
custom_edit_url: https://github.com/netdata/netdata/edit/master/exporting/opentsdb/README.md
-sidebar_label: OpenTSDB with HTTP
+sidebar_label: OpenTSDB
-->
-# Export metrics to OpenTSDB with HTTP
+# Export metrics to OpenTSDB
-Netdata can easily communicate with OpenTSDB using HTTP API. To enable this channel, run `./edit-config exporting.conf`
-in the Netdata configuration directory and set the following options:
+You can use the OpenTSDB connector for the [exporting engine](/exporting/README.md) to archive your agent's metrics to OpenTSDB
+databases for long-term storage, further analysis, or correlation with data from other sources.
-```conf
-[opentsdb:http:my_instance]
- enabled = yes
- destination = localhost:4242
-```
-
-In this example, OpenTSDB is running with its default port, which is `4242`. If you run OpenTSDB on a different port,
-change the `destination = localhost:4242` line accordingly.
+## Configuration
-## HTTPS
-
-As of [v1.16.0](https://github.com/netdata/netdata/releases/tag/v1.16.0), Netdata can send metrics to OpenTSDB using
-TLS/SSL. Unfortunately, OpenTDSB does not support encrypted connections, so you will have to configure a reverse proxy
-to enable HTTPS communication between Netdata and OpenTSBD. You can set up a reverse proxy with
-[Nginx](/docs/Running-behind-nginx.md).
-
-After your proxy is configured, make the following changes to `exporting.conf`:
+To enable data exporting to an OpenTSDB database, run `./edit-config exporting.conf` in the Netdata configuration
+directory and set the following options:
```conf
-[opentsdb:https:my_instance]
+[opentsdb:my_opentsdb_instance]
enabled = yes
- destination = localhost:8082
+ destination = localhost:4242
```
-In this example, we used the port `8082` for our reverse proxy. If your reverse proxy listens on a different port,
-change the `destination = localhost:8082` line accordingly.
+Add `:http` or `:https` modifiers to the connector type if you need to use other than a plaintext protocol. For example: `opentsdb:http:my_opentsdb_instance`,
+`opentsdb:https:my_opentsdb_instance`.
+
+The OpenTSDB connector is further configurable using additional settings. See the [exporting reference
+doc](/exporting/README.md#options) for details.
[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fexporting%2Fopentsdb%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
diff --git a/exporting/opentsdb/opentsdb.c b/exporting/opentsdb/opentsdb.c
index 76ee0a7bf2..4ee1e3a6f3 100644
--- a/exporting/opentsdb/opentsdb.c
+++ b/exporting/opentsdb/opentsdb.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "opentsdb.h"
+#include "../json/json.h"
/**
* Initialize OpenTSDB telnet connector instance
@@ -16,6 +17,17 @@ int init_opentsdb_telnet_instance(struct instance *instance)
instance->config.connector_specific_config = (void *)connector_specific_config;
connector_specific_config->default_port = 4242;
+ struct simple_connector_data *connector_specific_data = callocz(1, sizeof(struct simple_connector_data));
+ instance->connector_specific_data = connector_specific_data;
+
+#ifdef ENABLE_HTTPS
+ connector_specific_data->flags = NETDATA_SSL_START;
+ connector_specific_data->conn = NULL;
+ if (instance->config.options & EXPORTING_OPTION_USE_TLS) {
+ security_start_ssl(NETDATA_SSL_CONTEXT_EXPORTING);
+ }
+#endif
+
instance->start_batch_formatting = NULL;
instance->start_host_formatting = format_host_labels_opentsdb_telnet;
instance->start_chart_formatting = NULL;
@@ -27,9 +39,9 @@ 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 = simple_connector_end_batch;
- instance->send_header = NULL;
+ instance->prepare_header = NULL;
instance->check_response = exporting_discard_response;
instance->buffer = (void *)buffer_create(0);
@@ -37,6 +49,9 @@ int init_opentsdb_telnet_instance(struct instance *instance)
error("EXPORTING: cannot create buffer for opentsdb telnet exporting connector instance %s", instance->config.name);
return 1;
}
+
+ simple_connector_init(instance);
+
if (uv_mutex_init(&instance->mutex))
return 1;
if (uv_cond_init(&instance->cond_var))
@@ -59,17 +74,17 @@ int init_opentsdb_http_instance(struct instance *instance)
instance->config.connector_specific_config = (void *)connector_specific_config;
connector_specific_config->default_port = 4242;
+ struct simple_connector_data *connector_specific_data = callocz(1, sizeof(struct simple_connector_data));
#ifdef ENABLE_HTTPS
- struct opentsdb_specific_data *connector_specific_data = callocz(1, sizeof(struct opentsdb_specific_data));
connector_specific_data->flags = NETDATA_SSL_START;
connector_specific_data->conn = NULL;
if (instance->config.options & EXPORTING_OPTION_USE_TLS) {
- security_start_ssl(NETDATA_SSL_CONTEXT_OPENTSDB);
+ security_start_ssl(NETDATA_SSL_CONTEXT_EXPORTING);
}
- instance->connector_specific_data = connector_specific_data;
#endif
+ instance->connector_specific_data = connector_specific_data;
- instance->start_batch_formatting = NULL;
+ instance->start_batch_formatting = open_batch_json_http;
instance->start_host_formatting = format_host_labels_opentsdb_http;
instance->start_chart_formatting = NULL;
@@ -80,9 +95,9 @@ 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 = close_batch_json_http;
- instance->send_header = NULL;
+ instance->prepare_header = opentsdb_http_prepare_header;
instance->check_response = exporting_discard_response;
instance->buffer = (void *)buffer_create(0);
@@ -90,6 +105,9 @@ int init_opentsdb_http_instance(struct instance *instance)
error("EXPORTING: cannot create buffer for opentsdb HTTP exporting connector instance %s", instance->config.name);
return 1;
}
+
+ simple_connector_init(instance);
+
if (uv_mutex_init(&instance->mutex))
return 1;
if (uv_cond_init(&instance->cond_var))
@@ -240,26 +258,26 @@ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *r
}
/**
- * Prepare an HTTP message for OpenTSDB HTTP connector
+ * Ppepare HTTP header
*
- * @param buffer a buffer to write the message to.
- * @param message the body of the message.
- * @param hostname the name of the host that sends the message.
- * @param length the length of the message body.
+ * @param instance an instance data structure.
+ * @return Returns 0 on success, 1 on failure.
*/
-static inline void opentsdb_build_message(BUFFER *buffer, char *message, const char *hostname, int length)
+void opentsdb_http_prepare_header(struct instance *instance)
{
+ struct simple_connector_data *simple_connector_data = instance->connector_specific_data;
+
buffer_sprintf(
- buffer,
+ simple_connector_data->last_buffer->header,
"POST /api/put HTTP/1.1\r\n"
"Host: %s\r\n"
"Content-Type: application/json\r\n"
- "Content-Length: %d\r\n"
- "\r\n"
- "%s",
- hostname,
- length,
- message);
+ "Content-Length: %lu\r\n"
+ "\r\n",
+ instance->config.destination,
+ buffer_strlen(simple_connector_data->last_buffer->buffer));
+
+ return;
}
/**
@@ -324,17 +342,18 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *
(instance->config.options & EXPORTING_OPTION_SEND_NAMES && rd->name) ? rd->name : rd->id,
RRD_ID_LENGTH_MAX);
- char message[1024];
- int length = snprintfz(
- message,
- sizeof(message),
+ if (buffer_strlen((BUFFER *)instance->buffer) > 2)
+ buffer_strcat(instance->buffer, ",\n");
+
+ buffer_sprintf(
+ instance->buffer,
"{"
- " \"metric\": \"%s.%s.%s\","
- " \"timestamp\": %llu,"
- " \"value\": " COLLECTED_NUMBER_FORMAT ","
- " \"tags\": {"
- " \"host\": \"%s%s%s\"%s"
- " }"
+ "\"metric\":\"%s.%s.%s\","
+ "\"timestamp\":%llu,"
+ "\"value\":"COLLECTED_NUMBER_FORMAT","
+ "\"tags\":{"
+ "\"host\":\"%s%s%s\"%s"
+ "}"
"}",
instance->config.prefix,
chart_name,
@@ -346,10 +365,6 @@ int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *
(host->tags) ? host->tags : "",
instance->labels ? buffer_tostring(instance->labels) : "");
- if (length > 0) {
- opentsdb_build_message(instance->buffer, message, engine->config.hostname, length);
- }
-
return 0;
}
@@ -384,17 +399,18 @@ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd)
if(isnan(value))
return 0;
- char message[1024];
- int length = snprintfz(
- message,
- sizeof(message),
+ if (buffer_strlen((BUFFER *)instance->buffer) > 2)
+ buffer_strcat(instance->buffer, ",\n");
+
+ buffer_sprintf(
+ instance->buffer,
"{"
- " \"metric\": \"%s.%s.%s\","
- " \"timestamp\": %llu,"
- " \"value\": " CALCULATED_NUMBER_FORMAT ","
- " \"tags\": {"
- " \"host\": \"%s%s%s\"%s"
- " }"
+ "\"metric\":\"%s.%s.%s\","
+ "\"timestamp\":%llu,"
+ "\"value\":"CALCULATED_NUMBER_FORMAT","
+ "\"tags\":{"
+ "\"host\":\"%s%s%s\"%s"
+ "}"
"}",
instance->config.prefix,
chart_name,
@@ -406,9 +422,5 @@ int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd)
(host->tags) ? host->tags : "",
instance->labels ? buffer_tostring(instance->labels) : "");
- if (length > 0) {
- opentsdb_build_message(instance->buffer, message, engine->config.hostname, length);
- }
-
return 0;
}
diff --git a/exporting/opentsdb/opentsdb.h b/exporting/opentsdb/opentsdb.h
index d7eeee0ac8..d53a5054f5 100644
--- a/exporting/opentsdb/opentsdb.h
+++ b/exporting/opentsdb/opentsdb.h
@@ -18,11 +18,9 @@ int format_dimension_stored_opentsdb_telnet(struct instance *instance, RRDDIM *r
int format_dimension_collected_opentsdb_http(struct instance *instance, RRDDIM *rd);
int format_dimension_stored_opentsdb_http(struct instance *instance, RRDDIM *rd);
-#ifdef ENABLE_HTTPS
-struct opentsdb_specific_data {
- SSL *conn; //SSL connection
- int flags; //The flags for SSL connection
-};
-#endif
+int open_batch_opentsdb_http(struct instance *instance);
+int close_batch_opentsdb_http(struct instance *instance);
+
+void opentsdb_http_prepare_header(struct instance *instance);
#endif //NETDATA_EXPORTING_OPENTSDB_H