diff options
author | Vladimir Kobal <vlad@prokk.net> | 2020-11-05 19:08:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 19:08:17 +0200 |
commit | 943ee2482b16a81afd54b426f4fb0952f99c48e7 (patch) | |
tree | 5603b2bbd3cba974f665699a2b132256b2dfe912 /exporting/graphite | |
parent | edd6d02dec1c65593acb9d7b98dbb3f594d58c3a (diff) |
Add HTTP and HTTPS support to the simple exporting connector (#9911)
Diffstat (limited to 'exporting/graphite')
-rw-r--r-- | exporting/graphite/README.md | 4 | ||||
-rw-r--r-- | exporting/graphite/graphite.c | 45 | ||||
-rw-r--r-- | exporting/graphite/graphite.h | 2 |
3 files changed, 49 insertions, 2 deletions
diff --git a/exporting/graphite/README.md b/exporting/graphite/README.md index 95b8ef954d..2ac7adc7af 100644 --- a/exporting/graphite/README.md +++ b/exporting/graphite/README.md @@ -3,6 +3,7 @@ title: "Export metrics to Graphite providers" sidebar_label: Graphite description: "Archive your Agent's metrics to a any Graphite database provider for long-term storage, further analysis, or correlation with data from other sources." custom_edit_url: https://github.com/netdata/netdata/edit/master/exporting/graphite/README.md +sidebar_label: Graphite --> # Export metrics to Graphite providers @@ -21,6 +22,9 @@ directory and set the following options: destination = localhost:2003 ``` +Add `:http` or `:https` modifiers to the connector type if you need to use other than a plaintext protocol. For example: `graphite:http:my_graphite_instance`, +`graphite:https:my_graphite_instance`. + The Graphite connector is further configurable using additional settings. See the [exporting reference doc](/exporting/README.md#options) for details. diff --git a/exporting/graphite/graphite.c b/exporting/graphite/graphite.c index 6aad2054db..23e40c369e 100644 --- a/exporting/graphite/graphite.c +++ b/exporting/graphite/graphite.c @@ -16,6 +16,17 @@ int init_graphite_instance(struct instance *instance) instance->config.connector_specific_config = (void *)connector_specific_config; connector_specific_config->default_port = 2003; + 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_graphite_plaintext; instance->start_chart_formatting = NULL; @@ -27,9 +38,13 @@ 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 = simple_connector_end_batch; + + if (instance->config.type == EXPORTING_CONNECTOR_TYPE_GRAPHITE_HTTP) + instance->prepare_header = graphite_http_prepare_header; + else + instance->prepare_header = NULL; - instance->send_header = NULL; instance->check_response = exporting_discard_response; instance->buffer = (void *)buffer_create(0); @@ -37,6 +52,9 @@ int init_graphite_instance(struct instance *instance) error("EXPORTING: cannot create buffer for graphite 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)) @@ -187,3 +205,26 @@ int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM return 0; } + +/** + * Ppepare HTTP header + * + * @param instance an instance data structure. + * @return Returns 0 on success, 1 on failure. + */ +void graphite_http_prepare_header(struct instance *instance) +{ + struct simple_connector_data *simple_connector_data = instance->connector_specific_data; + + buffer_sprintf( + simple_connector_data->last_buffer->header, + "POST /api/put HTTP/1.1\r\n" + "Host: %s\r\n" + "Content-Type: application/graphite\r\n" + "Content-Length: %lu\r\n" + "\r\n", + instance->config.destination, + buffer_strlen(simple_connector_data->last_buffer->buffer)); + + return; +} diff --git a/exporting/graphite/graphite.h b/exporting/graphite/graphite.h index edda498e85..993c12e57a 100644 --- a/exporting/graphite/graphite.h +++ b/exporting/graphite/graphite.h @@ -13,4 +13,6 @@ int format_host_labels_graphite_plaintext(struct instance *instance, RRDHOST *ho int format_dimension_collected_graphite_plaintext(struct instance *instance, RRDDIM *rd); int format_dimension_stored_graphite_plaintext(struct instance *instance, RRDDIM *rd); +void graphite_http_prepare_header(struct instance *instance); + #endif //NETDATA_EXPORTING_GRAPHITE_H |