]> arthur.barton.de Git - netdata.git/blob - src/health.h
track the duration of all alarms
[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
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 (RRDCONTEXT.variables_root_index)
17 // 3. at each host    (RRDHOST.variables_root_index)
18 typedef struct rrdvar {
19     avl avl;
20
21     char *name;
22     uint32_t hash;
23
24     int type;
25     void *value;
26
27     time_t last_updated;
28 } RRDVAR;
29
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
34 // these variables
35 typedef struct rrdsetvar {
36     char *fullid;               // chart type.chart id.variable
37     char *fullname;             // chart type.chart name.variable
38     char *variable;             // variable
39
40     int type;
41     void *value;
42
43     uint32_t options;
44
45     RRDVAR *local;
46     RRDVAR *context;
47     RRDVAR *host;
48     RRDVAR *context_name;
49     RRDVAR *host_name;
50
51     struct rrdset *rrdset;
52
53     struct rrdsetvar *next;
54 } RRDSETVAR;
55
56
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
61 // these variables
62 typedef struct rrddimvar {
63     char *prefix;
64     char *suffix;
65
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
72
73     int type;
74     void *value;
75
76     uint32_t options;
77
78     RRDVAR *local_id;
79     RRDVAR *local_name;
80
81     RRDVAR *context_id;
82     RRDVAR *context_name;
83
84     RRDVAR *host_fullidid;
85     RRDVAR *host_fullidname;
86     RRDVAR *host_fullnameid;
87     RRDVAR *host_fullnamename;
88
89     struct rrddim *rrddim;
90
91     struct rrddimvar *next;
92 } RRDDIMVAR;
93
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.
98 //
99 // These calculations are allocated and linked (->next)
100 // under RRDHOST.
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
105 // next.
106
107 #define RRDCALC_STATUS_UNINITIALIZED  0
108 #define RRDCALC_STATUS_UNDEFINED     -1
109 #define RRDCALC_STATUS_OFF            1
110 #define RRDCALC_STATUS_RAISED         2
111
112 #define RRDCALC_OPTION_DB_ERROR      0x00000001
113 #define RRDCALC_OPTION_DB_NAN        0x00000002
114 #define RRDCALC_OPTION_DB_STALE      0x00000004
115 #define RRDCALC_OPTION_CALC_ERROR    0x00000008
116 #define RRDCALC_OPTION_WARN_ERROR    0x00000010
117 #define RRDCALC_OPTION_CRIT_ERROR    0x00000020
118
119 typedef struct rrdcalc {
120     char *name;
121     uint32_t hash;
122
123     char *exec;
124
125     char *chart;        // the chart id this should be linked to
126     uint32_t hash_chart;
127
128     char *source;       // the source of this calculation
129
130     char *dimensions;   // the chart dimensions
131
132     int group;          // grouping method: average, max, etc.
133     int before;         // ending point in time-series
134     int after;          // starting point in time-series
135     uint32_t options;   // calculation options
136     int update_every;   // update frequency for the calculation
137
138     time_t last_updated;
139     time_t next_update;
140
141     EVAL_EXPRESSION *calculation;
142     EVAL_EXPRESSION *warning;
143     EVAL_EXPRESSION *critical;
144
145     uint32_t rrdcalc_options;
146     int warning_status;
147     int critical_status;
148
149     time_t db_timestamp;
150     time_t last_status_change;
151
152     calculated_number value;
153     calculated_number old_value;
154
155     calculated_number green;
156     calculated_number red;
157
158     RRDVAR *local;
159     RRDVAR *context;
160     RRDVAR *hostid;
161     RRDVAR *hostname;
162
163     struct rrdset *rrdset;
164     struct rrdcalc *rrdset_next;
165     struct rrdcalc *rrdset_prev;
166
167     struct rrdcalc *next;
168 } RRDCALC;
169
170 #define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
171
172 // RRDCALCTEMPLATE
173 // these are to be applied to charts found dynamically
174 // based on their context.
175 typedef struct rrdcalctemplate {
176     char *name;
177     uint32_t hash_name;
178
179     char *exec;
180
181     char *context;
182     uint32_t hash_context;
183
184     char *source;       // the source of this template
185
186     char *dimensions;
187
188     int group;          // grouping method: average, max, etc.
189     int before;         // ending point in time-series
190     int after;          // starting point in time-series
191     uint32_t options;   // calculation options
192     int update_every;   // update frequency for the calculation
193
194     EVAL_EXPRESSION *calculation;
195     EVAL_EXPRESSION *warning;
196     EVAL_EXPRESSION *critical;
197
198     calculated_number green;
199     calculated_number red;
200
201     struct rrdcalctemplate *next;
202 } RRDCALCTEMPLATE;
203
204 #define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
205
206 #define ALARM_ENTRY_TYPE_WARNING  1
207 #define ALARM_ENTRY_TYPE_CRITICAL 2
208
209 #define HEALTH_ENTRY_NOTIFICATIONS_PROCESSED 0x00000001
210
211 typedef struct alarm_entry {
212     uint32_t id;
213     time_t when;
214     time_t duration;
215     int type;
216     char *name;
217     char *chart;
218     char *exec;
219     char *source;
220     calculated_number old_value;
221     calculated_number new_value;
222     int old_status;
223     int new_status;
224     uint32_t notifications;
225     struct alarm_entry *next;
226 } ALARM_ENTRY;
227
228 typedef struct alarm_log {
229     uint32_t nextid;
230     unsigned int count;
231     unsigned int max;
232     ALARM_ENTRY *alarms;
233 } ALARM_LOG;
234
235 #include "rrd.h"
236
237 extern void rrdsetvar_rename_all(RRDSET *st);
238 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
239 extern void rrdsetvar_free(RRDSETVAR *rs);
240
241 extern void rrddimvar_rename_all(RRDDIM *rd);
242 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
243 extern void rrddimvar_free(RRDDIMVAR *rs);
244
245 extern void rrdsetcalc_link_matching(RRDSET *st);
246 extern void rrdsetcalc_unlink(RRDCALC *rc);
247 extern void rrdcalctemplate_link_matching(RRDSET *st);
248
249 extern void health_init(void);
250 extern void *health_main(void *ptr);
251
252 extern void health_reload(void);
253
254 extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
255
256 #endif //NETDATA_HEALTH_H