rrdvar.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef NETDATA_RRDVAR_H
  3. #define NETDATA_RRDVAR_H 1
  4. #include "libnetdata/libnetdata.h"
  5. extern int rrdvar_compare(void *a, void *b);
  6. typedef enum rrdvar_type {
  7. RRDVAR_TYPE_CALCULATED = 1,
  8. RRDVAR_TYPE_TIME_T = 2,
  9. RRDVAR_TYPE_COLLECTED = 3,
  10. RRDVAR_TYPE_TOTAL = 4,
  11. RRDVAR_TYPE_INT = 5
  12. } RRDVAR_TYPE;
  13. typedef enum rrdvar_options {
  14. RRDVAR_OPTION_DEFAULT = 0,
  15. RRDVAR_OPTION_ALLOCATED = (1 << 0), // the value ptr is allocated (not a reference)
  16. RRDVAR_OPTION_CUSTOM_HOST_VAR = (1 << 1), // this is a custom host variable, not associated with a dimension
  17. RRDVAR_OPTION_CUSTOM_CHART_VAR = (1 << 2), // this is a custom chart variable, not associated with a dimension
  18. RRDVAR_OPTION_RRDCALC_LOCAL_VAR = (1 << 3), // this is a an alarm variable, attached to a chart
  19. RRDVAR_OPTION_RRDCALC_FAMILY_VAR = (1 << 4), // this is a an alarm variable, attached to a family
  20. RRDVAR_OPTION_RRDCALC_HOST_CHARTID_VAR = (1 << 5), // this is a an alarm variable, attached to the host, using the chart id
  21. RRDVAR_OPTION_RRDCALC_HOST_CHARTNAME_VAR = (1 << 6), // this is a an alarm variable, attached to the host, using the chart name
  22. } RRDVAR_OPTIONS;
  23. // the variables as stored in the variables indexes
  24. // there are 3 indexes:
  25. // 1. at each chart (RRDSET.rrdvar_root_index)
  26. // 2. at each context (RRDFAMILY.rrdvar_root_index)
  27. // 3. at each host (RRDHOST.rrdvar_root_index)
  28. struct rrdvar {
  29. avl_t avl;
  30. char *name;
  31. uint32_t hash;
  32. RRDVAR_TYPE type;
  33. RRDVAR_OPTIONS options;
  34. void *value;
  35. time_t last_updated;
  36. };
  37. #define RRDVAR_MAX_LENGTH 1024
  38. extern int rrdvar_fix_name(char *variable);
  39. #include "rrd.h"
  40. extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name);
  41. extern void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, NETDATA_DOUBLE value);
  42. extern int foreach_host_variable_callback(RRDHOST *host, int (*callback)(RRDVAR *rv, void *data), void *data);
  43. extern void rrdvar_free_remaining_variables(RRDHOST *host, avl_tree_lock *tree_lock);
  44. extern int rrdvar_callback_for_all_host_variables(RRDHOST *host, int (*callback)(void *rrdvar, void *data), void *data);
  45. extern NETDATA_DOUBLE rrdvar2number(RRDVAR *rv);
  46. extern RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, RRDVAR_OPTIONS options, void *value);
  47. extern void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv);
  48. #endif //NETDATA_RRDVAR_H