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 *key_fullid; // chart type.chart id.variable
38 char *key_fullname; // chart type.chart name.variable
39 char *variable; // variable
49 RRDVAR *var_family_name;
50 RRDVAR *var_host_name;
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 *key_id; // dimension id
68 char *key_name; // dimension name
69 char *key_contextid; // context + dimension id
70 char *key_contextname; // context + dimension name
71 char *key_fullidid; // chart type.chart id + dimension id
72 char *key_fullidname; // chart type.chart id + dimension name
73 char *key_fullnameid; // chart type.chart name + dimension id
74 char *key_fullnamename; // chart type.chart name + dimension name
82 RRDVAR *var_local_name;
84 RRDVAR *var_family_id;
85 RRDVAR *var_family_name;
86 RRDVAR *var_family_contextid;
87 RRDVAR *var_family_contextname;
89 RRDVAR *var_host_chartidid;
90 RRDVAR *var_host_chartidname;
91 RRDVAR *var_host_chartnameid;
92 RRDVAR *var_host_chartnamename;
94 struct rrddim *rrddim;
96 struct rrddimvar *next;
99 // calculated variables (defined in health configuration)
100 // These aggregate time-series data at fixed intervals
101 // (defined in their update_every member below)
102 // These increase the overhead of netdata.
104 // These calculations are allocated and linked (->next)
106 // Then are also linked to RRDSET (of course only when the
107 // chart is found, via ->rrdset_next and ->rrdset_prev).
108 // This double-linked list is maintained sorted at all times
109 // having as RRDSET.calculations the RRDCALC to be processed
112 #define RRDCALC_STATUS_REMOVED -2
113 #define RRDCALC_STATUS_UNDEFINED -1
114 #define RRDCALC_STATUS_UNINITIALIZED 0
115 #define RRDCALC_STATUS_CLEAR 1
116 #define RRDCALC_STATUS_RAISED 2
117 #define RRDCALC_STATUS_WARNING 3
118 #define RRDCALC_STATUS_CRITICAL 4
120 #define RRDCALC_FLAG_DB_ERROR 0x00000001
121 #define RRDCALC_FLAG_DB_NAN 0x00000002
122 /* #define RRDCALC_FLAG_DB_STALE 0x00000004 */
123 #define RRDCALC_FLAG_CALC_ERROR 0x00000008
124 #define RRDCALC_FLAG_WARN_ERROR 0x00000010
125 #define RRDCALC_FLAG_CRIT_ERROR 0x00000020
126 #define RRDCALC_FLAG_RUNNABLE 0x00000040
128 typedef struct rrdcalc {
129 uint32_t id; // the unique id of this alarm
130 uint32_t next_event_id; // the next event id that will be used for this alarm
132 char *name; // the name of this alarm
135 char *exec; // the command to execute when this alarm switches state
136 char *recipient; // the recipient of the alarm (the first parameter to exec)
138 char *chart; // the chart id this should be linked to
141 char *source; // the source of this alarm
142 char *units; // the units of the alarm
143 char *info; // a short description of the alarm
145 int update_every; // update frequency for the alarm
147 // the red and green threshold of this alarm (to be set to the chart)
148 calculated_number green;
149 calculated_number red;
151 // ------------------------------------------------------------------------
152 // database lookup settings
154 char *dimensions; // the chart dimensions
155 int group; // grouping method: average, max, etc.
156 int before; // ending point in time-series
157 int after; // starting point in time-series
158 uint32_t options; // calculation options
160 // ------------------------------------------------------------------------
161 // expressions related to the alarm
163 EVAL_EXPRESSION *calculation; // expression to calculate the value of the alarm
164 EVAL_EXPRESSION *warning; // expression to check the warning condition
165 EVAL_EXPRESSION *critical; // expression to check the critical condition
167 // ------------------------------------------------------------------------
168 // notification delay settings
170 int delay_up_duration; // duration to delay notifications when alarm raises
171 int delay_down_duration; // duration to delay notifications when alarm lowers
172 int delay_max_duration; // the absolute max delay to apply to this alarm
173 float delay_multiplier; // multiplier for all delays when alarms switch status
174 // while now < delay_up_to
176 // ------------------------------------------------------------------------
177 // runtime information
179 int status; // the current status of the alarm
181 calculated_number value; // the current value of the alarm
182 calculated_number old_value; // the previous value of the alarm
184 uint32_t rrdcalc_flags; // check RRDCALC_FLAG_*
186 time_t last_updated; // the last update timestamp of the alarm
187 time_t next_update; // the next update timestamp of the alarm
188 time_t last_status_change; // the timestamp of the last time this alarm changed status
190 time_t db_after; // the first timestamp evaluated by the db lookup
191 time_t db_before; // the last timestamp evaluated by the db lookup
193 time_t delay_up_to_timestamp; // the timestamp up to which we should delay notifications
194 int delay_up_current; // the current up notification delay duration
195 int delay_down_current; // the current down notification delay duration
196 int delay_last; // the last delay we used
198 // ------------------------------------------------------------------------
199 // variables this alarm exposes to the rest of the alarms
206 // ------------------------------------------------------------------------
207 // the chart this alarm it is linked to
209 struct rrdset *rrdset;
211 // linking of this alarm on its chart
212 struct rrdcalc *rrdset_next;
213 struct rrdcalc *rrdset_prev;
215 struct rrdcalc *next;
218 #define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
221 // these are to be applied to charts found dynamically
222 // based on their context.
223 typedef struct rrdcalctemplate {
231 uint32_t hash_context;
233 char *source; // the source of this alarm
234 char *units; // the units of the alarm
235 char *info; // a short description of the alarm
237 int update_every; // update frequency for the alarm
239 // the red and green threshold of this alarm (to be set to the chart)
240 calculated_number green;
241 calculated_number red;
243 // ------------------------------------------------------------------------
244 // database lookup settings
246 char *dimensions; // the chart dimensions
247 int group; // grouping method: average, max, etc.
248 int before; // ending point in time-series
249 int after; // starting point in time-series
250 uint32_t options; // calculation options
252 // ------------------------------------------------------------------------
253 // notification delay settings
255 int delay_up_duration; // duration to delay notifications when alarm raises
256 int delay_down_duration; // duration to delay notifications when alarm lowers
257 int delay_max_duration; // the absolute max delay to apply to this alarm
258 float delay_multiplier; // multiplier for all delays when alarms switch status
260 // ------------------------------------------------------------------------
261 // expressions related to the alarm
263 EVAL_EXPRESSION *calculation;
264 EVAL_EXPRESSION *warning;
265 EVAL_EXPRESSION *critical;
267 struct rrdcalctemplate *next;
270 #define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
272 #define HEALTH_ENTRY_FLAG_PROCESSED 0x00000001
273 #define HEALTH_ENTRY_FLAG_UPDATED 0x00000002
274 #define HEALTH_ENTRY_FLAG_EXEC_RUN 0x00000004
275 #define HEALTH_ENTRY_FLAG_EXEC_FAILED 0x00000008
276 #define HEALTH_ENTRY_FLAG_SAVED 0x10000000
278 typedef struct alarm_entry {
281 uint32_t alarm_event_id;
285 time_t non_clear_duration;
297 time_t exec_run_timestamp;
304 calculated_number old_value;
305 calculated_number new_value;
312 time_t delay_up_to_timestamp;
314 uint32_t updated_by_id;
317 struct alarm_entry *next;
320 typedef struct alarm_log {
321 uint32_t next_log_id;
322 uint32_t next_alarm_id;
326 pthread_rwlock_t alarm_log_rwlock;
331 extern void rrdsetvar_rename_all(RRDSET *st);
332 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
333 extern void rrdsetvar_free(RRDSETVAR *rs);
335 extern void rrddimvar_rename_all(RRDDIM *rd);
336 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
337 extern void rrddimvar_free(RRDDIMVAR *rs);
339 extern void rrdsetcalc_link_matching(RRDSET *st);
340 extern void rrdsetcalc_unlink(RRDCALC *rc);
341 extern void rrdcalctemplate_link_matching(RRDSET *st);
342 extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
344 extern void health_init(void);
345 extern void *health_main(void *ptr);
347 extern void health_reload(void);
349 extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
350 extern void health_alarms2json(RRDHOST *host, BUFFER *wb, int all);
351 extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after);
353 void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf);
355 #endif //NETDATA_HEALTH_H