graphite.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #define BACKENDS_INTERNALS
  3. #include "graphite.h"
  4. // ----------------------------------------------------------------------------
  5. // graphite backend
  6. int format_dimension_collected_graphite_plaintext(
  7. BUFFER *b // the buffer to write data to
  8. , const char *prefix // the prefix to use
  9. , RRDHOST *host // the host this chart comes from
  10. , const char *hostname // the hostname (to override host->hostname)
  11. , RRDSET *st // the chart
  12. , RRDDIM *rd // the dimension
  13. , time_t after // the start timestamp
  14. , time_t before // the end timestamp
  15. , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
  16. ) {
  17. (void)host;
  18. (void)after;
  19. (void)before;
  20. char chart_name[RRD_ID_LENGTH_MAX + 1];
  21. char dimension_name[RRD_ID_LENGTH_MAX + 1];
  22. backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
  23. backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
  24. buffer_sprintf(
  25. b
  26. , "%s.%s.%s.%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n"
  27. , prefix
  28. , hostname
  29. , chart_name
  30. , dimension_name
  31. , (host->tags)?";":""
  32. , (host->tags)?host->tags:""
  33. , rd->last_collected_value
  34. , (unsigned long long)rd->last_collected_time.tv_sec
  35. );
  36. return 1;
  37. }
  38. int format_dimension_stored_graphite_plaintext(
  39. BUFFER *b // the buffer to write data to
  40. , const char *prefix // the prefix to use
  41. , RRDHOST *host // the host this chart comes from
  42. , const char *hostname // the hostname (to override host->hostname)
  43. , RRDSET *st // the chart
  44. , RRDDIM *rd // the dimension
  45. , time_t after // the start timestamp
  46. , time_t before // the end timestamp
  47. , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
  48. ) {
  49. (void)host;
  50. char chart_name[RRD_ID_LENGTH_MAX + 1];
  51. char dimension_name[RRD_ID_LENGTH_MAX + 1];
  52. backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
  53. backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
  54. time_t first_t = after, last_t = before;
  55. calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
  56. if(!isnan(value)) {
  57. buffer_sprintf(
  58. b
  59. , "%s.%s.%s.%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n"
  60. , prefix
  61. , hostname
  62. , chart_name
  63. , dimension_name
  64. , (host->tags)?";":""
  65. , (host->tags)?host->tags:""
  66. , value
  67. , (unsigned long long) last_t
  68. );
  69. return 1;
  70. }
  71. return 0;
  72. }
  73. int process_graphite_response(BUFFER *b) {
  74. return discard_response(b, "graphite");
  75. }