0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-05-18 07:01:20 +00:00
netdata_netdata/backends/graphite/graphite.c
Vladimir Kobal 6f27081912
Implement the main flow for the Exporting Engine ()
* Add top level tests

* Add a skeleton for preparing buffers

* Initialize graphite instance

* Prepare buffers for all instances

* Add Grafite collected value formatter

* Add support for exporting.conf read and parsing

* - Use new exporting_config instead of netdata_config

* Implement Grafite worker

* Disable exporting engine compilation if libuv is not available

* Add mutex locks

- Configure connectors as connector_<type> in sections of exporting.conf

- Change exporting_select_type to check for connector_ fields

* - Override exporting_config structure if there no exporting.conf so that
  look ups don't fail and we maintain backwards compatibility

* Separate fixtures in unit tests

* Test exporting_discard_responce

* Test response receiving

* Test buffer sending

* Test simple connector worker

- Instance section has the format connector:instance_name
  e.g graphite:my_graphite_instance

- Connectors with : in their name e.g graphite:plaintext are reserved
  So graphite:plaintext is not accepted because it would activate an
  instance with name "plaintext"
  It should be graphite:plaintext:instance_name

* - Enable the add_connector_instance to cleanup the internal structure
  by passing NULL,not NULL arguments

* Implement configurable update interval

- Add additional check to verify instance uniqueness across connectors

* Add host and chart filters

* Add the value calculation over a database series

* Add the calculated over stored data graphite connector

* Add tests for graphite connector

* Add JSON connector

* Add tests for JSON formatting functions

* Add OpenTSDB connector

* Add tests for the OpenTSDB connector

* Add temporaty notes to the documentation
2019-12-12 21:41:11 +02:00

90 lines
3.3 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#define BACKENDS_INTERNALS
#include "graphite.h"
// ----------------------------------------------------------------------------
// graphite backend
int backends_format_dimension_collected_graphite_plaintext(
BUFFER *b // the buffer to write data to
, const char *prefix // the prefix to use
, RRDHOST *host // the host this chart comes from
, const char *hostname // the hostname (to override host->hostname)
, RRDSET *st // the chart
, RRDDIM *rd // the dimension
, time_t after // the start timestamp
, time_t before // the end timestamp
, BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
) {
(void)host;
(void)after;
(void)before;
char chart_name[RRD_ID_LENGTH_MAX + 1];
char dimension_name[RRD_ID_LENGTH_MAX + 1];
backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
buffer_sprintf(
b
, "%s.%s.%s.%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n"
, prefix
, hostname
, chart_name
, dimension_name
, (host->tags)?";":""
, (host->tags)?host->tags:""
, rd->last_collected_value
, (unsigned long long)rd->last_collected_time.tv_sec
);
return 1;
}
int backends_format_dimension_stored_graphite_plaintext(
BUFFER *b // the buffer to write data to
, const char *prefix // the prefix to use
, RRDHOST *host // the host this chart comes from
, const char *hostname // the hostname (to override host->hostname)
, RRDSET *st // the chart
, RRDDIM *rd // the dimension
, time_t after // the start timestamp
, time_t before // the end timestamp
, BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
) {
(void)host;
char chart_name[RRD_ID_LENGTH_MAX + 1];
char dimension_name[RRD_ID_LENGTH_MAX + 1];
backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
time_t first_t = after, last_t = before;
calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
if(!isnan(value)) {
buffer_sprintf(
b
, "%s.%s.%s.%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n"
, prefix
, hostname
, chart_name
, dimension_name
, (host->tags)?";":""
, (host->tags)?host->tags:""
, value
, (unsigned long long) last_t
);
return 1;
}
return 0;
}
int process_graphite_response(BUFFER *b) {
return discard_response(b, "graphite");
}