1 #ifndef NETDATA_HEALTH_H
2 #define NETDATA_HEALTH_H
4 extern int health_enabled;
6 extern int rrdvar_compare(void *a, void *b);
8 #define RRDVAR_TYPE_CALCULATED 1
9 #define RRDVAR_TYPE_TIME_T 2
10 #define RRDVAR_TYPE_COLLECTED 3
11 #define RRDVAR_TYPE_TOTAL 4
13 // the variables as stored in the variables indexes
14 // there are 3 indexes:
15 // 1. at each chart (RRDSET.variables_root_index)
16 // 2. at each context (RRDFAMILY.variables_root_index)
17 // 3. at each host (RRDHOST.variables_root_index)
18 typedef struct rrdvar {
30 // variables linked to charts
31 // We link variables to point to the values that are already
32 // calculated / processed by the normal data collection process
33 // This means, there will be no speed penalty for using
35 typedef struct rrdsetvar {
36 char *fullid; // chart type.chart id.variable
37 char *fullname; // chart type.chart name.variable
38 char *variable; // variable
51 struct rrdset *rrdset;
53 struct rrdsetvar *next;
57 // variables linked to individual dimensions
58 // We link variables to point the values that are already
59 // calculated / processed by the normal data collection process
60 // This means, there will be no speed penalty for using
62 typedef struct rrddimvar {
66 char *id; // dimension id
67 char *name; // dimension name
68 char *fullidid; // chart type.chart id.dimension id
69 char *fullidname; // chart type.chart id.dimension name
70 char *fullnameid; // chart type.chart name.dimension id
71 char *fullnamename; // chart type.chart name.dimension name
84 RRDVAR *host_fullidid;
85 RRDVAR *host_fullidname;
86 RRDVAR *host_fullnameid;
87 RRDVAR *host_fullnamename;
89 struct rrddim *rrddim;
91 struct rrddimvar *next;
94 // calculated variables (defined in health configuration)
95 // These aggregate time-series data at fixed intervals
96 // (defined in their update_every member below)
97 // These increase the overhead of netdata.
99 // These calculations are allocated and linked (->next)
101 // Then are also linked to RRDSET (of course only when the
102 // chart is found, via ->rrdset_next and ->rrdset_prev).
103 // This double-linked list is maintained sorted at all times
104 // having as RRDSET.calculations the RRDCALC to be processed
107 #define RRDCALC_STATUS_UNINITIALIZED 0
108 #define RRDCALC_STATUS_UNDEFINED -1
109 #define RRDCALC_STATUS_CLEAR 1
110 #define RRDCALC_STATUS_RAISED 2
111 #define RRDCALC_STATUS_WARNING 3
112 #define RRDCALC_STATUS_CRITICAL 4
114 #define RRDCALC_OPTION_DB_ERROR 0x00000001
115 #define RRDCALC_OPTION_DB_NAN 0x00000002
116 #define RRDCALC_OPTION_DB_STALE 0x00000004
117 #define RRDCALC_OPTION_CALC_ERROR 0x00000008
118 #define RRDCALC_OPTION_WARN_ERROR 0x00000010
119 #define RRDCALC_OPTION_CRIT_ERROR 0x00000020
121 typedef struct rrdcalc {
127 char *chart; // the chart id this should be linked to
130 char *source; // the source of this calculation
132 char *dimensions; // the chart dimensions
134 int group; // grouping method: average, max, etc.
135 int before; // ending point in time-series
136 int after; // starting point in time-series
137 uint32_t options; // calculation options
138 int update_every; // update frequency for the calculation
143 EVAL_EXPRESSION *calculation;
144 EVAL_EXPRESSION *warning;
145 EVAL_EXPRESSION *critical;
147 uint32_t rrdcalc_options;
153 time_t last_status_change;
155 calculated_number value;
156 calculated_number old_value;
158 calculated_number green;
159 calculated_number red;
166 struct rrdset *rrdset;
167 struct rrdcalc *rrdset_next;
168 struct rrdcalc *rrdset_prev;
170 struct rrdcalc *next;
173 #define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
176 // these are to be applied to charts found dynamically
177 // based on their context.
178 typedef struct rrdcalctemplate {
185 uint32_t hash_context;
187 char *source; // the source of this template
191 int group; // grouping method: average, max, etc.
192 int before; // ending point in time-series
193 int after; // starting point in time-series
194 uint32_t options; // calculation options
195 int update_every; // update frequency for the calculation
197 EVAL_EXPRESSION *calculation;
198 EVAL_EXPRESSION *warning;
199 EVAL_EXPRESSION *critical;
201 calculated_number green;
202 calculated_number red;
204 struct rrdcalctemplate *next;
207 #define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
209 #define HEALTH_ENTRY_NOTIFICATIONS_PROCESSED 0x00000001
210 #define HEALTH_ENTRY_NOTIFICATIONS_UPDATED 0x00000002
212 typedef struct alarm_entry {
217 time_t non_clear_duration;
227 calculated_number old_value;
228 calculated_number new_value;
232 uint32_t notifications;
234 struct alarm_entry *updated_by;
235 struct alarm_entry *next;
238 typedef struct alarm_log {
247 extern void rrdsetvar_rename_all(RRDSET *st);
248 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
249 extern void rrdsetvar_free(RRDSETVAR *rs);
251 extern void rrddimvar_rename_all(RRDDIM *rd);
252 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
253 extern void rrddimvar_free(RRDDIMVAR *rs);
255 extern void rrdsetcalc_link_matching(RRDSET *st);
256 extern void rrdsetcalc_unlink(RRDCALC *rc);
257 extern void rrdcalctemplate_link_matching(RRDSET *st);
259 extern void health_init(void);
260 extern void *health_main(void *ptr);
262 extern void health_reload(void);
264 extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
266 #endif //NETDATA_HEALTH_H