]> arthur.barton.de Git - netdata.git/blob - src/health.h
enable browser notifications for alarms; fixes #846; fixes #317; contributes to ...
[netdata.git] / src / health.h
1 #ifndef NETDATA_HEALTH_H
2 #define NETDATA_HEALTH_H
3
4 extern int health_enabled;
5
6 extern int rrdvar_compare(void *a, void *b);
7
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
13
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 {
20     avl avl;
21
22     char *name;
23     uint32_t hash;
24
25     int type;
26     void *value;
27
28     time_t last_updated;
29 } RRDVAR;
30
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
35 // these variables
36 typedef struct rrdsetvar {
37     char *fullid;               // chart type.chart id.variable
38     char *fullname;             // chart type.chart name.variable
39     char *variable;             // variable
40
41     int type;
42     void *value;
43
44     uint32_t options;
45
46     RRDVAR *local;
47     RRDVAR *family;
48     RRDVAR *host;
49     RRDVAR *family_name;
50     RRDVAR *host_name;
51
52     struct rrdset *rrdset;
53
54     struct rrdsetvar *next;
55 } RRDSETVAR;
56
57
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
62 // these variables
63 typedef struct rrddimvar {
64     char *prefix;
65     char *suffix;
66
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
73
74     int type;
75     void *value;
76
77     uint32_t options;
78
79     RRDVAR *local_id;
80     RRDVAR *local_name;
81
82     RRDVAR *family_id;
83     RRDVAR *family_name;
84
85     RRDVAR *host_fullidid;
86     RRDVAR *host_fullidname;
87     RRDVAR *host_fullnameid;
88     RRDVAR *host_fullnamename;
89
90     struct rrddim *rrddim;
91
92     struct rrddimvar *next;
93 } RRDDIMVAR;
94
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.
99 //
100 // These calculations are allocated and linked (->next)
101 // under RRDHOST.
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
106 // next.
107
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
114
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
121
122 typedef struct rrdcalc {
123     uint32_t id;
124     uint32_t next_event_id;
125
126     char *name;
127     uint32_t hash;
128
129     char *exec;
130     char *recipient;
131
132     char *chart;        // the chart id this should be linked to
133     uint32_t hash_chart;
134
135     char *source;       // the source of this calculation
136     char *units;
137     char *info;
138
139     char *dimensions;   // the chart dimensions
140
141     int group;          // grouping method: average, max, etc.
142     int before;         // ending point in time-series
143     int after;          // starting point in time-series
144     uint32_t options;   // calculation options
145     int update_every;   // update frequency for the calculation
146
147     time_t last_updated;
148     time_t next_update;
149
150     EVAL_EXPRESSION *calculation;
151     EVAL_EXPRESSION *warning;
152     EVAL_EXPRESSION *critical;
153
154     uint32_t rrdcalc_flags;
155     int status;
156
157     time_t db_after;
158     time_t db_before;
159     time_t last_status_change;
160
161     calculated_number value;
162     calculated_number old_value;
163
164     calculated_number green;
165     calculated_number red;
166
167     RRDVAR *local;
168     RRDVAR *family;
169     RRDVAR *hostid;
170     RRDVAR *hostname;
171
172     struct rrdset *rrdset;
173     struct rrdcalc *rrdset_next;
174     struct rrdcalc *rrdset_prev;
175
176     struct rrdcalc *next;
177 } RRDCALC;
178
179 #define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
180
181 // RRDCALCTEMPLATE
182 // these are to be applied to charts found dynamically
183 // based on their context.
184 typedef struct rrdcalctemplate {
185     char *name;
186     uint32_t hash_name;
187
188     char *exec;
189     char *recipient;
190
191     char *context;
192     uint32_t hash_context;
193
194     char *source;       // the source of this template
195     char *units;
196     char *info;
197
198     char *dimensions;
199
200     int group;          // grouping method: average, max, etc.
201     int before;         // ending point in time-series
202     int after;          // starting point in time-series
203     uint32_t options;   // calculation options
204     int update_every;   // update frequency for the calculation
205
206     EVAL_EXPRESSION *calculation;
207     EVAL_EXPRESSION *warning;
208     EVAL_EXPRESSION *critical;
209
210     calculated_number green;
211     calculated_number red;
212
213     struct rrdcalctemplate *next;
214 } RRDCALCTEMPLATE;
215
216 #define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
217
218 #define HEALTH_ENTRY_NOTIFICATIONS_PROCESSED    0x00000001
219 #define HEALTH_ENTRY_NOTIFICATIONS_UPDATED      0x00000002
220 #define HEALTH_ENTRY_NOTIFICATIONS_EXEC_RUN     0x00000004
221 #define HEALTH_ENTRY_NOTIFICATIONS_EXEC_FAILED  0x00000008
222
223 typedef struct alarm_entry {
224     uint32_t unique_id;
225     uint32_t alarm_id;
226     uint32_t alarm_event_id;
227
228     time_t when;
229     time_t duration;
230     time_t non_clear_duration;
231
232     char *name;
233     uint32_t hash_name;
234
235     char *chart;
236     uint32_t hash_chart;
237
238     char *family;
239
240     char *exec;
241     char *recipient;
242     int exec_code;
243
244     char *source;
245     char *units;
246     char *info;
247
248     calculated_number old_value;
249     calculated_number new_value;
250     int old_status;
251     int new_status;
252
253     uint32_t notifications;
254
255     struct alarm_entry *updated_by;
256     struct alarm_entry *next;
257 } ALARM_ENTRY;
258
259 typedef struct alarm_log {
260     uint32_t next_log_id;
261     uint32_t next_alarm_id;
262     unsigned int count;
263     unsigned int max;
264     ALARM_ENTRY *alarms;
265     pthread_rwlock_t alarm_log_rwlock;
266 } ALARM_LOG;
267
268 #include "rrd.h"
269
270 extern void rrdsetvar_rename_all(RRDSET *st);
271 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
272 extern void rrdsetvar_free(RRDSETVAR *rs);
273
274 extern void rrddimvar_rename_all(RRDDIM *rd);
275 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
276 extern void rrddimvar_free(RRDDIMVAR *rs);
277
278 extern void rrdsetcalc_link_matching(RRDSET *st);
279 extern void rrdsetcalc_unlink(RRDCALC *rc);
280 extern void rrdcalctemplate_link_matching(RRDSET *st);
281 extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
282
283 extern void health_init(void);
284 extern void *health_main(void *ptr);
285
286 extern void health_reload(void);
287
288 extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
289 extern void health_alarms2json(RRDHOST *host, BUFFER *wb, int all);
290 extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after);
291
292 #endif //NETDATA_HEALTH_H