rrdr.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_QUERIES_RRDR_H
  3. #define NETDATA_QUERIES_RRDR_H
  4. #include "libnetdata/libnetdata.h"
  5. typedef enum rrdr_options {
  6. RRDR_OPTION_NONZERO = 0x00000001, // don't output dimensions will just zero values
  7. RRDR_OPTION_REVERSED = 0x00000002, // output the rows in reverse order (oldest to newest)
  8. RRDR_OPTION_ABSOLUTE = 0x00000004, // values positive, for DATASOURCE_SSV before summing
  9. RRDR_OPTION_MIN2MAX = 0x00000008, // when adding dimensions, use max - min, instead of sum
  10. RRDR_OPTION_SECONDS = 0x00000010, // output seconds, instead of dates
  11. RRDR_OPTION_MILLISECONDS = 0x00000020, // output milliseconds, instead of dates
  12. RRDR_OPTION_NULL2ZERO = 0x00000040, // do not show nulls, convert them to zeros
  13. RRDR_OPTION_OBJECTSROWS = 0x00000080, // each row of values should be an object, not an array
  14. RRDR_OPTION_GOOGLE_JSON = 0x00000100, // comply with google JSON/JSONP specs
  15. RRDR_OPTION_JSON_WRAP = 0x00000200, // wrap the response in a JSON header with info about the result
  16. RRDR_OPTION_LABEL_QUOTES = 0x00000400, // in CSV output, wrap header labels in double quotes
  17. RRDR_OPTION_PERCENTAGE = 0x00000800, // give values as percentage of total
  18. RRDR_OPTION_NOT_ALIGNED = 0x00001000, // do not align charts for persistant timeframes
  19. RRDR_OPTION_DISPLAY_ABS = 0x00002000, // for badges, display the absolute value, but calculate colors with sign
  20. RRDR_OPTION_MATCH_IDS = 0x00004000, // when filtering dimensions, match only IDs
  21. RRDR_OPTION_MATCH_NAMES = 0x00008000, // when filtering dimensions, match only names
  22. } RRDR_OPTIONS;
  23. typedef enum rrdr_value_flag {
  24. RRDR_VALUE_NOTHING = 0x00, // no flag set (a good default)
  25. RRDR_VALUE_EMPTY = 0x01, // the database value is empty
  26. RRDR_VALUE_RESET = 0x02, // the database value is marked as reset (overflown)
  27. } RRDR_VALUE_FLAGS;
  28. typedef enum rrdr_dimension_flag {
  29. RRDR_DIMENSION_DEFAULT = 0x00,
  30. RRDR_DIMENSION_HIDDEN = 0x04, // the dimension is hidden (not to be presented to callers)
  31. RRDR_DIMENSION_NONZERO = 0x08, // the dimension is non zero (contains non-zero values)
  32. RRDR_DIMENSION_SELECTED = 0x10, // the dimension is selected for evaluation in this RRDR
  33. } RRDR_DIMENSION_FLAGS;
  34. // RRDR result options
  35. typedef enum rrdr_result_flags {
  36. RRDR_RESULT_OPTION_ABSOLUTE = 0x00000001, // the query uses absolute time-frames (can be cached by browsers and proxies)
  37. RRDR_RESULT_OPTION_RELATIVE = 0x00000002, // the query uses relative time-frames (should not to be cached by browsers and proxies)
  38. } RRDR_RESULT_FLAGS;
  39. typedef struct rrdresult {
  40. struct rrdset *st; // the chart this result refers to
  41. RRDR_RESULT_FLAGS result_options; // RRDR_RESULT_OPTION_*
  42. int d; // the number of dimensions
  43. long n; // the number of values in the arrays
  44. long rows; // the number of rows used
  45. RRDR_DIMENSION_FLAGS *od; // the options for the dimensions
  46. time_t *t; // array of n timestamps
  47. calculated_number *v; // array n x d values
  48. RRDR_VALUE_FLAGS *o; // array n x d options for each value returned
  49. long group; // how many collected values were grouped for each row
  50. int update_every; // what is the suggested update frequency in seconds
  51. calculated_number min;
  52. calculated_number max;
  53. time_t before;
  54. time_t after;
  55. int has_st_lock; // if st is read locked by us
  56. // internal rrd2rrdr() members below this point
  57. struct {
  58. long points_wanted;
  59. long resampling_group;
  60. calculated_number resampling_divisor;
  61. void *(*grouping_create)(struct rrdresult *r);
  62. void (*grouping_reset)(struct rrdresult *r);
  63. void (*grouping_free)(struct rrdresult *r);
  64. void (*grouping_add)(struct rrdresult *r, calculated_number value);
  65. calculated_number (*grouping_flush)(struct rrdresult *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr);
  66. void *grouping_data;
  67. #ifdef NETDATA_INTERNAL_CHECKS
  68. const char *log;
  69. #endif
  70. size_t db_points_read;
  71. size_t result_points_generated;
  72. } internal;
  73. } RRDR;
  74. #define rrdr_rows(r) ((r)->rows)
  75. extern void rrdr_free(RRDR *r);
  76. extern RRDR *rrdr_create(struct rrdset *st, long n);
  77. #include "../web_api_v1.h"
  78. #include "web/api/queries/query.h"
  79. extern RRDR *rrd2rrdr(RRDSET *st, long points_requested, long long after_requested, long long before_requested, RRDR_GROUPING group_method, long resampling_time_requested, RRDR_OPTIONS options, const char *dimensions);
  80. #include "query.h"
  81. #endif //NETDATA_QUERIES_RRDR_H