rrdcalc.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "rrd.h"
  3. #ifndef NETDATA_RRDCALC_H
  4. #define NETDATA_RRDCALC_H 1
  5. // calculated variables (defined in health configuration)
  6. // These aggregate time-series data at fixed intervals
  7. // (defined in their update_every member below)
  8. // They increase the overhead of netdata.
  9. //
  10. // These calculations are allocated and linked (->next)
  11. // under RRDHOST.
  12. // Then are also linked to RRDSET (of course only when the
  13. // chart is found, via ->rrdset_next and ->rrdset_prev).
  14. // This double-linked list is maintained sorted at all times
  15. // having as RRDSET.calculations the RRDCALC to be processed
  16. // next.
  17. #define RRDCALC_FLAG_DB_ERROR 0x00000001
  18. #define RRDCALC_FLAG_DB_NAN 0x00000002
  19. /* #define RRDCALC_FLAG_DB_STALE 0x00000004 */
  20. #define RRDCALC_FLAG_CALC_ERROR 0x00000008
  21. #define RRDCALC_FLAG_WARN_ERROR 0x00000010
  22. #define RRDCALC_FLAG_CRIT_ERROR 0x00000020
  23. #define RRDCALC_FLAG_RUNNABLE 0x00000040
  24. #define RRDCALC_FLAG_DISABLED 0x00000080
  25. #define RRDCALC_FLAG_SILENCED 0x00000100
  26. #define RRDCALC_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
  27. struct rrdcalc {
  28. uint32_t id; // the unique id of this alarm
  29. uint32_t next_event_id; // the next event id that will be used for this alarm
  30. char *name; // the name of this alarm
  31. uint32_t hash;
  32. char *exec; // the command to execute when this alarm switches state
  33. char *recipient; // the recipient of the alarm (the first parameter to exec)
  34. char *chart; // the chart id this should be linked to
  35. uint32_t hash_chart;
  36. char *source; // the source of this alarm
  37. char *units; // the units of the alarm
  38. char *info; // a short description of the alarm
  39. int update_every; // update frequency for the alarm
  40. // the red and green threshold of this alarm (to be set to the chart)
  41. calculated_number green;
  42. calculated_number red;
  43. // ------------------------------------------------------------------------
  44. // database lookup settings
  45. char *dimensions; // the chart dimensions
  46. RRDR_GROUPING group; // grouping method: average, max, etc.
  47. int before; // ending point in time-series
  48. int after; // starting point in time-series
  49. uint32_t options; // calculation options
  50. // ------------------------------------------------------------------------
  51. // expressions related to the alarm
  52. EVAL_EXPRESSION *calculation; // expression to calculate the value of the alarm
  53. EVAL_EXPRESSION *warning; // expression to check the warning condition
  54. EVAL_EXPRESSION *critical; // expression to check the critical condition
  55. // ------------------------------------------------------------------------
  56. // notification delay settings
  57. int delay_up_duration; // duration to delay notifications when alarm raises
  58. int delay_down_duration; // duration to delay notifications when alarm lowers
  59. int delay_max_duration; // the absolute max delay to apply to this alarm
  60. float delay_multiplier; // multiplier for all delays when alarms switch status
  61. // while now < delay_up_to
  62. // ------------------------------------------------------------------------
  63. // runtime information
  64. RRDCALC_STATUS status; // the current status of the alarm
  65. calculated_number value; // the current value of the alarm
  66. calculated_number old_value; // the previous value of the alarm
  67. uint32_t rrdcalc_flags; // check RRDCALC_FLAG_*
  68. time_t last_updated; // the last update timestamp of the alarm
  69. time_t next_update; // the next update timestamp of the alarm
  70. time_t last_status_change; // the timestamp of the last time this alarm changed status
  71. time_t db_after; // the first timestamp evaluated by the db lookup
  72. time_t db_before; // the last timestamp evaluated by the db lookup
  73. time_t delay_up_to_timestamp; // the timestamp up to which we should delay notifications
  74. int delay_up_current; // the current up notification delay duration
  75. int delay_down_current; // the current down notification delay duration
  76. int delay_last; // the last delay we used
  77. // ------------------------------------------------------------------------
  78. // variables this alarm exposes to the rest of the alarms
  79. RRDVAR *local;
  80. RRDVAR *family;
  81. RRDVAR *hostid;
  82. RRDVAR *hostname;
  83. // ------------------------------------------------------------------------
  84. // the chart this alarm it is linked to
  85. struct rrdset *rrdset;
  86. // linking of this alarm on its chart
  87. struct rrdcalc *rrdset_next;
  88. struct rrdcalc *rrdset_prev;
  89. struct rrdcalc *next;
  90. };
  91. #define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
  92. extern void rrdsetcalc_link_matching(RRDSET *st);
  93. extern void rrdsetcalc_unlink(RRDCALC *rc);
  94. extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
  95. extern const char *rrdcalc_status2string(RRDCALC_STATUS status);
  96. extern void rrdcalc_free(RRDCALC *rc);
  97. extern void rrdcalc_unlink_and_free(RRDHOST *host, RRDCALC *rc);
  98. extern int rrdcalc_exists(RRDHOST *host, const char *chart, const char *name, uint32_t hash_chart, uint32_t hash_name);
  99. extern uint32_t rrdcalc_get_unique_id(RRDHOST *host, const char *chart, const char *name, uint32_t *next_event_id);
  100. extern RRDCALC *rrdcalc_create(RRDHOST *host, RRDCALCTEMPLATE *rt, const char *chart);
  101. extern void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc);
  102. #endif //NETDATA_RRDCALC_H