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
12 #define RRDVAR_TYPE_INT 5
14 // the variables as stored in the variables indexes
15 // there are 3 indexes:
16 // 1. at each chart (RRDSET.variables_root_index)
17 // 2. at each context (RRDFAMILY.variables_root_index)
18 // 3. at each host (RRDHOST.variables_root_index)
19 typedef struct rrdvar {
31 // variables linked to charts
32 // We link variables to point to the values that are already
33 // calculated / processed by the normal data collection process
34 // This means, there will be no speed penalty for using
36 typedef struct rrdsetvar {
37 char *fullid; // chart type.chart id.variable
38 char *fullname; // chart type.chart name.variable
39 char *variable; // variable
52 struct rrdset *rrdset;
54 struct rrdsetvar *next;
58 // variables linked to individual dimensions
59 // We link variables to point the values that are already
60 // calculated / processed by the normal data collection process
61 // This means, there will be no speed penalty for using
63 typedef struct rrddimvar {
67 char *id; // dimension id
68 char *name; // dimension name
69 char *fullidid; // chart type.chart id.dimension id
70 char *fullidname; // chart type.chart id.dimension name
71 char *fullnameid; // chart type.chart name.dimension id
72 char *fullnamename; // chart type.chart name.dimension name
85 RRDVAR *host_fullidid;
86 RRDVAR *host_fullidname;
87 RRDVAR *host_fullnameid;
88 RRDVAR *host_fullnamename;
90 struct rrddim *rrddim;
92 struct rrddimvar *next;
95 // calculated variables (defined in health configuration)
96 // These aggregate time-series data at fixed intervals
97 // (defined in their update_every member below)
98 // These increase the overhead of netdata.
100 // These calculations are allocated and linked (->next)
102 // Then are also linked to RRDSET (of course only when the
103 // chart is found, via ->rrdset_next and ->rrdset_prev).
104 // This double-linked list is maintained sorted at all times
105 // having as RRDSET.calculations the RRDCALC to be processed
108 #define RRDCALC_STATUS_UNINITIALIZED 0
109 #define RRDCALC_STATUS_UNDEFINED -1
110 #define RRDCALC_STATUS_CLEAR 1
111 #define RRDCALC_STATUS_RAISED 2
112 #define RRDCALC_STATUS_WARNING 3
113 #define RRDCALC_STATUS_CRITICAL 4
115 #define RRDCALC_FLAG_DB_ERROR 0x00000001
116 #define RRDCALC_FLAG_DB_NAN 0x00000002
117 #define RRDCALC_FLAG_DB_STALE 0x00000004
118 #define RRDCALC_FLAG_CALC_ERROR 0x00000008
119 #define RRDCALC_FLAG_WARN_ERROR 0x00000010
120 #define RRDCALC_FLAG_CRIT_ERROR 0x00000020
122 typedef struct rrdcalc {
128 char *chart; // the chart id this should be linked to
131 char *source; // the source of this calculation
133 char *dimensions; // the chart dimensions
135 int group; // grouping method: average, max, etc.
136 int before; // ending point in time-series
137 int after; // starting point in time-series
138 uint32_t options; // calculation options
139 int update_every; // update frequency for the calculation
144 EVAL_EXPRESSION *calculation;
145 EVAL_EXPRESSION *warning;
146 EVAL_EXPRESSION *critical;
148 uint32_t rrdcalc_flags;
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;
229 calculated_number old_value;
230 calculated_number new_value;
234 uint32_t notifications;
236 struct alarm_entry *updated_by;
237 struct alarm_entry *next;
240 typedef struct alarm_log {
249 extern void rrdsetvar_rename_all(RRDSET *st);
250 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
251 extern void rrdsetvar_free(RRDSETVAR *rs);
253 extern void rrddimvar_rename_all(RRDDIM *rd);
254 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
255 extern void rrddimvar_free(RRDDIMVAR *rs);
257 extern void rrdsetcalc_link_matching(RRDSET *st);
258 extern void rrdsetcalc_unlink(RRDCALC *rc);
259 extern void rrdcalctemplate_link_matching(RRDSET *st);
260 extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
262 extern void health_init(void);
263 extern void *health_main(void *ptr);
265 extern void health_reload(void);
267 extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
268 extern void health_alarms2json(RRDHOST *host, BUFFER *wb);
270 #endif //NETDATA_HEALTH_H