allow hostname to be configured for backend
Costa Tsaousis (ktsaou) committed
Nov 20, 2016 at 13:16 UTC
76fff8cf42adfc481b220efd960307823af59f1f
1 file changed
+17
-10
src/backends.c
+17
-10
@@ -210,37 +210,41 @@ static inline calculated_number backend_duration_average(RRDSET *st, RRDDIM *rd,
210
return sum / (calculated_number)counter;
211
}
212
213
-static inline void format_dimension_collected_graphite_plaintext(BUFFER *b, const char *prefix, RRDHOST *host, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
213
+static inline void format_dimension_collected_graphite_plaintext(BUFFER *b, const char *prefix, RRDHOST *host, const char *hostname, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
214
+ (void)host;
215
(void)after;
216
(void)before;
217
(void)options;
217
- buffer_sprintf(b, "%s.%s.%s.%s " COLLECTED_NUMBER_FORMAT " %u\n", prefix, host->hostname, st->id, rd->id, rd->last_collected_value, (uint32_t)rd->last_collected_time.tv_sec);
218
+ buffer_sprintf(b, "%s.%s.%s.%s " COLLECTED_NUMBER_FORMAT " %u\n", prefix, hostname, st->id, rd->id, rd->last_collected_value, (uint32_t)rd->last_collected_time.tv_sec);
219
}
220
220
-static inline void format_dimension_stored_graphite_plaintext(BUFFER *b, const char *prefix, RRDHOST *host, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
221
+static inline void format_dimension_stored_graphite_plaintext(BUFFER *b, const char *prefix, RRDHOST *host, const char *hostname, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
222
+ (void)host;
223
calculated_number value = backend_duration_average(st, rd, after, before, options);
224
if(!isnan(value))
223
- buffer_sprintf(b, "%s.%s.%s.%s " CALCULATED_NUMBER_FORMAT " %u\n", prefix, host->hostname, st->id, rd->id, value, (uint32_t)before);
225
+ buffer_sprintf(b, "%s.%s.%s.%s " CALCULATED_NUMBER_FORMAT " %u\n", prefix, hostname, st->id, rd->id, value, (uint32_t)before);
226
}
227
226
-static inline void format_dimension_collected_opentsdb_telnet(BUFFER *b, const char *prefix, RRDHOST *host, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
228
+static inline void format_dimension_collected_opentsdb_telnet(BUFFER *b, const char *prefix, RRDHOST *host, const char *hostname, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
229
+ (void)host;
230
(void)after;
231
(void)before;
232
(void)options;
230
- buffer_sprintf(b, "put %s.%s.%s %u " COLLECTED_NUMBER_FORMAT " host=%s\n", prefix, st->id, rd->id, (uint32_t)rd->last_collected_time.tv_sec, rd->last_collected_value, host->hostname);
233
+ buffer_sprintf(b, "put %s.%s.%s %u " COLLECTED_NUMBER_FORMAT " host=%s\n", prefix, st->id, rd->id, (uint32_t)rd->last_collected_time.tv_sec, rd->last_collected_value, hostname);
234
}
235
233
-static inline void format_dimension_stored_opentsdb_telnet(BUFFER *b, const char *prefix, RRDHOST *host, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
236
+static inline void format_dimension_stored_opentsdb_telnet(BUFFER *b, const char *prefix, RRDHOST *host, const char *hostname, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options) {
237
+ (void)host;
238
calculated_number value = backend_duration_average(st, rd, after, before, options);
239
if(!isnan(value))
236
- buffer_sprintf(b, "put %s.%s.%s %u " CALCULATED_NUMBER_FORMAT " host=%s\n", prefix, st->id, rd->id, (uint32_t)before, value, host->hostname);
240
+ buffer_sprintf(b, "put %s.%s.%s %u " CALCULATED_NUMBER_FORMAT " host=%s\n", prefix, st->id, rd->id, (uint32_t)before, value, hostname);
241
}
242
243
void *backends_main(void *ptr) {
244
(void)ptr;
245
246
BUFFER *b = buffer_create(1);
243
- void (*formatter)(BUFFER *b, const char *prefix, RRDHOST *host, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options);
247
+ void (*formatter)(BUFFER *b, const char *prefix, RRDHOST *host, const char *hostname, RRDSET *st, RRDDIM *rd, time_t after, time_t before, uint32_t options);
248
249
info("BACKEND thread created with task id %d", gettid());
250
@@ -258,6 +262,7 @@ void *backends_main(void *ptr) {
262
const char *type = config_get("backend", "type", "graphite");
263
const char *destination = config_get("backend", "destination", "localhost");
264
const char *prefix = config_get("backend", "prefix", "netdata");
265
+ const char *hostname = config_get("backend", "hostname", localhost.hostname);
266
int frequency = (int)config_get_number("backend", "update every", 30);
267
int buffer_on_failures = (int)config_get_number("backend", "buffer on failures", 10);
268
@@ -303,6 +308,8 @@ void *backends_main(void *ptr) {
308
time_t after = before;
309
int failures = 0;
310
311
+ info("BACKEND configured ('%s' on '%s' sending '%s' data, every %d seconds, as host '%s', with prefix '%s')", type, destination, source, frequency, hostname, prefix);
312
+
313
for(;;) {
314
unsigned long long now_ut = time_usec();
315
unsigned long long next_ut = now_ut - (now_ut % step_ut) + step_ut;
@@ -329,7 +336,7 @@ void *backends_main(void *ptr) {
336
RRDDIM *rd;
337
for(rd = st->dimensions; rd ;rd = rd->next) {
338
if(rd->last_collected_time.tv_sec >= after)
332
- formatter(b, prefix, &localhost, st, rd, after, before, options);
339
+ formatter(b, prefix, &localhost, hostname, st, rd, after, before, options);
340
}
341
342
pthread_rwlock_unlock(&st->rwlock);