rrdcontext.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_RRDCONTEXT_H
  3. #define NETDATA_RRDCONTEXT_H 1
  4. // ----------------------------------------------------------------------------
  5. // RRDMETRIC
  6. typedef struct rrdmetric_acquired RRDMETRIC_ACQUIRED;
  7. // ----------------------------------------------------------------------------
  8. // RRDINSTANCE
  9. typedef struct rrdinstance_acquired RRDINSTANCE_ACQUIRED;
  10. // ----------------------------------------------------------------------------
  11. // RRDCONTEXT
  12. typedef struct rrdcontexts_dictionary RRDCONTEXTS;
  13. typedef struct rrdcontext_acquired RRDCONTEXT_ACQUIRED;
  14. // ----------------------------------------------------------------------------
  15. #include "rrd.h"
  16. const char *rrdmetric_acquired_id(RRDMETRIC_ACQUIRED *rma);
  17. const char *rrdmetric_acquired_name(RRDMETRIC_ACQUIRED *rma);
  18. NETDATA_DOUBLE rrdmetric_acquired_last_stored_value(RRDMETRIC_ACQUIRED *rma);
  19. const char *rrdinstance_acquired_id(RRDINSTANCE_ACQUIRED *ria);
  20. const char *rrdinstance_acquired_name(RRDINSTANCE_ACQUIRED *ria);
  21. DICTIONARY *rrdinstance_acquired_labels(RRDINSTANCE_ACQUIRED *ria);
  22. DICTIONARY *rrdinstance_acquired_functions(RRDINSTANCE_ACQUIRED *ria);
  23. // ----------------------------------------------------------------------------
  24. // public API for rrdhost
  25. void rrdhost_load_rrdcontext_data(RRDHOST *host);
  26. void rrdhost_create_rrdcontexts(RRDHOST *host);
  27. void rrdhost_destroy_rrdcontexts(RRDHOST *host);
  28. void rrdcontext_host_child_connected(RRDHOST *host);
  29. void rrdcontext_host_child_disconnected(RRDHOST *host);
  30. int rrdcontext_foreach_instance_with_rrdset_in_context(RRDHOST *host, const char *context, int (*callback)(RRDSET *st, void *data), void *data);
  31. typedef enum {
  32. RRDCONTEXT_OPTION_NONE = 0,
  33. RRDCONTEXT_OPTION_SHOW_METRICS = (1 << 0),
  34. RRDCONTEXT_OPTION_SHOW_INSTANCES = (1 << 1),
  35. RRDCONTEXT_OPTION_SHOW_LABELS = (1 << 2),
  36. RRDCONTEXT_OPTION_SHOW_QUEUED = (1 << 3),
  37. RRDCONTEXT_OPTION_SHOW_FLAGS = (1 << 4),
  38. RRDCONTEXT_OPTION_SHOW_DELETED = (1 << 5),
  39. RRDCONTEXT_OPTION_DEEPSCAN = (1 << 6),
  40. RRDCONTEXT_OPTION_SHOW_UUIDS = (1 << 7),
  41. RRDCONTEXT_OPTION_SHOW_HIDDEN = (1 << 8),
  42. RRDCONTEXT_OPTION_SKIP_ID = (1 << 31), // internal use
  43. } RRDCONTEXT_TO_JSON_OPTIONS;
  44. #define RRDCONTEXT_OPTIONS_ALL (RRDCONTEXT_OPTION_SHOW_METRICS|RRDCONTEXT_OPTION_SHOW_INSTANCES|RRDCONTEXT_OPTION_SHOW_LABELS|RRDCONTEXT_OPTION_SHOW_QUEUED|RRDCONTEXT_OPTION_SHOW_FLAGS|RRDCONTEXT_OPTION_SHOW_DELETED|RRDCONTEXT_OPTION_SHOW_UUIDS|RRDCONTEXT_OPTION_SHOW_HIDDEN)
  45. int rrdcontext_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, const char *context, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions);
  46. int rrdcontexts_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions);
  47. // ----------------------------------------------------------------------------
  48. // public API for rrdcontexts
  49. const char *rrdcontext_acquired_id(RRDCONTEXT_ACQUIRED *rca);
  50. // ----------------------------------------------------------------------------
  51. // public API for rrddims
  52. void rrdcontext_updated_rrddim(RRDDIM *rd);
  53. void rrdcontext_removed_rrddim(RRDDIM *rd);
  54. void rrdcontext_updated_rrddim_algorithm(RRDDIM *rd);
  55. void rrdcontext_updated_rrddim_multiplier(RRDDIM *rd);
  56. void rrdcontext_updated_rrddim_divisor(RRDDIM *rd);
  57. void rrdcontext_updated_rrddim_flags(RRDDIM *rd);
  58. void rrdcontext_collected_rrddim(RRDDIM *rd);
  59. int rrdcontext_find_dimension_uuid(RRDSET *st, const char *id, uuid_t *store_uuid);
  60. // ----------------------------------------------------------------------------
  61. // public API for rrdsets
  62. void rrdcontext_updated_rrdset(RRDSET *st);
  63. void rrdcontext_removed_rrdset(RRDSET *st);
  64. void rrdcontext_updated_rrdset_name(RRDSET *st);
  65. void rrdcontext_updated_rrdset_flags(RRDSET *st);
  66. void rrdcontext_updated_retention_rrdset(RRDSET *st);
  67. void rrdcontext_collected_rrdset(RRDSET *st);
  68. int rrdcontext_find_chart_uuid(RRDSET *st, uuid_t *store_uuid);
  69. // ----------------------------------------------------------------------------
  70. // public API for ACLK
  71. void rrdcontext_hub_checkpoint_command(void *cmd);
  72. void rrdcontext_hub_stop_streaming_command(void *cmd);
  73. // ----------------------------------------------------------------------------
  74. // public API for threads
  75. void rrdcontext_db_rotation(void);
  76. void *rrdcontext_main(void *);
  77. // ----------------------------------------------------------------------------
  78. // public API for weights
  79. struct metric_entry {
  80. RRDCONTEXT_ACQUIRED *rca;
  81. RRDINSTANCE_ACQUIRED *ria;
  82. RRDMETRIC_ACQUIRED *rma;
  83. };
  84. DICTIONARY *rrdcontext_all_metrics_to_dict(RRDHOST *host, SIMPLE_PATTERN *contexts);
  85. // ----------------------------------------------------------------------------
  86. // public API for queries
  87. typedef struct query_metric {
  88. struct query_metric_tier {
  89. struct storage_engine *eng;
  90. STORAGE_METRIC_HANDLE *db_metric_handle;
  91. time_t db_first_time_t; // the oldest timestamp available for this tier
  92. time_t db_last_time_t; // the latest timestamp available for this tier
  93. time_t db_update_every; // latest update every for this tier
  94. } tiers[RRD_STORAGE_TIERS];
  95. struct {
  96. RRDHOST *host;
  97. RRDCONTEXT_ACQUIRED *rca;
  98. RRDINSTANCE_ACQUIRED *ria;
  99. RRDMETRIC_ACQUIRED *rma;
  100. } link;
  101. struct {
  102. STRING *id;
  103. STRING *name;
  104. RRDR_DIMENSION_FLAGS options;
  105. } dimension;
  106. struct {
  107. STRING *id;
  108. STRING *name;
  109. } chart;
  110. } QUERY_METRIC;
  111. #define MAX_QUERY_TARGET_ID_LENGTH 255
  112. typedef struct query_target_request {
  113. RRDHOST *host; // the host to be queried (can be NULL, hosts will be used)
  114. RRDCONTEXT_ACQUIRED *rca; // the context to be queried (can be NULL)
  115. RRDINSTANCE_ACQUIRED *ria; // the instance to be queried (can be NULL)
  116. RRDMETRIC_ACQUIRED *rma; // the metric to be queried (can be NULL)
  117. RRDSET *st; // the chart to be queried (NULL, for context queries)
  118. const char *hosts; // hosts simple pattern
  119. const char *contexts; // contexts simple pattern (context queries)
  120. const char *charts; // charts simple pattern (for context queries)
  121. const char *dimensions; // dimensions simple pattern
  122. const char *chart_label_key; // select only the chart having this label key
  123. const char *charts_labels_filter; // select only the charts having this combo of label key:value
  124. time_t after; // the requested timeframe
  125. time_t before; // the requested timeframe
  126. size_t points; // the requested number of points
  127. time_t timeout; // the timeout of the query in seconds
  128. uint32_t format; // DATASOURCE_FORMAT
  129. RRDR_OPTIONS options;
  130. RRDR_GROUPING group_method;
  131. const char *group_options;
  132. time_t resampling_time;
  133. size_t tier;
  134. } QUERY_TARGET_REQUEST;
  135. typedef struct query_target {
  136. char id[MAX_QUERY_TARGET_ID_LENGTH + 1]; // query identifier (for logging)
  137. QUERY_TARGET_REQUEST request;
  138. bool used; // when true, this query is currently being used
  139. size_t queries; // how many query we have done so far
  140. struct {
  141. bool relative; // true when the request made with relative timestamps, true if it was absolute
  142. bool aligned;
  143. time_t after; // the absolute timestamp this query is about
  144. time_t before; // the absolute timestamp this query is about
  145. time_t query_granularity;
  146. size_t points; // the number of points the query will return (maybe different from the request)
  147. size_t group;
  148. RRDR_GROUPING group_method;
  149. const char *group_options;
  150. size_t resampling_group;
  151. NETDATA_DOUBLE resampling_divisor;
  152. RRDR_OPTIONS options;
  153. size_t tier;
  154. } window;
  155. struct {
  156. time_t first_time_t; // the combined first_time_t of all metrics in the query, across all tiers
  157. time_t last_time_t; // the combined last_time_T of all metrics in the query, across all tiers
  158. time_t minimum_latest_update_every; // the min update every of the metrics in the query
  159. } db;
  160. struct {
  161. QUERY_METRIC *array; // the metrics to be queried (all of them should be queried, no exceptions)
  162. uint32_t used; // how many items of the array are used
  163. uint32_t size; // the size of the array
  164. SIMPLE_PATTERN *pattern;
  165. } query;
  166. struct {
  167. RRDMETRIC_ACQUIRED **array;
  168. uint32_t used; // how many items of the array are used
  169. uint32_t size; // the size of the array
  170. } metrics;
  171. struct {
  172. RRDINSTANCE_ACQUIRED **array;
  173. uint32_t used; // how many items of the array are used
  174. uint32_t size; // the size of the array
  175. SIMPLE_PATTERN *pattern;
  176. SIMPLE_PATTERN *chart_label_key_pattern;
  177. SIMPLE_PATTERN *charts_labels_filter_pattern;
  178. } instances;
  179. struct {
  180. RRDCONTEXT_ACQUIRED **array;
  181. uint32_t used; // how many items of the array are used
  182. uint32_t size; // the size of the array
  183. SIMPLE_PATTERN *pattern;
  184. } contexts;
  185. struct {
  186. RRDHOST **array;
  187. uint32_t used; // how many items of the array are used
  188. uint32_t size; // the size of the array
  189. SIMPLE_PATTERN *pattern;
  190. } hosts;
  191. } QUERY_TARGET;
  192. void query_target_free(void);
  193. void query_target_release(QUERY_TARGET *qt);
  194. QUERY_TARGET *query_target_create(QUERY_TARGET_REQUEST *qtr);
  195. #endif // NETDATA_RRDCONTEXT_H