]> arthur.barton.de Git - netdata.git/blob - src/health.h
health configuration now parses templates too
[netdata.git] / src / health.h
1 #ifndef NETDATA_HEALTH_H
2 #define NETDATA_HEALTH_H
3
4 extern int rrdvar_compare(void *a, void *b);
5
6 /*
7  * RRDVAR
8  * a variable
9  *
10  * There are 4 scopes: local (chart), context, host and global variables
11  *
12  * Standard global variables:
13  *  $now
14  *
15  * Standard host variables:
16  *  - none -
17  *
18  * Standard context variables:
19  *  - none -
20  *
21  * Standard local variables:
22  *  $last_updated
23  *  $last_collected_value
24  *  $last_value
25  *
26  */
27
28 #define RRDVAR_TYPE_CALCULATED 1
29 #define RRDVAR_TYPE_TIME_T     2
30 #define RRDVAR_TYPE_COLLECTED  3
31 #define RRDVAR_TYPE_TOTAL      4
32
33 // the variables as stored in the variables indexes
34 // there are 3 indexes:
35 // 1. at each chart   (RRDSET.variables_root_index)
36 // 2. at each context (RRDCONTEXT.variables_root_index)
37 // 3. at each host    (RRDHOST.variables_root_index)
38 typedef struct rrdvar {
39     avl avl;
40
41     char *name;
42     uint32_t hash;
43
44     int type;
45     void *value;
46
47     time_t last_updated;
48 } RRDVAR;
49
50 // variables linked to charts
51 // We link variables to point to the values that are already
52 // calculated / processed by the normal data collection process
53 // This means, there will be no speed penalty for using
54 // these variables
55 typedef struct rrdsetvar {
56     char *fullid;               // chart type.chart id.variable
57     uint32_t hash_fullid;
58
59     char *fullname;             // chart type.chart name.variable
60     uint32_t hash_fullname;
61
62     char *variable;             // variable
63     uint32_t hash_variable;
64
65     int type;
66     void *value;
67
68     uint32_t options;
69
70     RRDVAR *local;
71     RRDVAR *context;
72     RRDVAR *host;
73     RRDVAR *context_name;
74     RRDVAR *host_name;
75
76     struct rrdset *rrdset;
77
78     struct rrdsetvar *next;
79 } RRDSETVAR;
80
81
82 // variables linked to individual dimensions
83 // We link variables to point the values that are already
84 // calculated / processed by the normal data collection process
85 // This means, there will be no speed penalty for using
86 // these variables
87 typedef struct rrddimvar {
88     char *prefix;
89     char *suffix;
90
91     char *id;                   // dimension id
92     uint32_t hash;
93
94     char *name;                 // dimension name
95     uint32_t hash_name;
96
97     char *fullidid;             // chart type.chart id.dimension id
98     uint32_t hash_fullidid;
99
100     char *fullidname;           // chart type.chart id.dimension name
101     uint32_t hash_fullidname;
102
103     char *fullnameid;           // chart type.chart name.dimension id
104     uint32_t hash_fullnameid;
105
106     char *fullnamename;         // chart type.chart name.dimension name
107     uint32_t hash_fullnamename;
108
109     int type;
110     void *value;
111
112     uint32_t options;
113
114     RRDVAR *local_id;
115     RRDVAR *local_name;
116
117     RRDVAR *context_fullidid;
118     RRDVAR *context_fullidname;
119     RRDVAR *context_fullnameid;
120     RRDVAR *context_fullnamename;
121
122     RRDVAR *host_fullidid;
123     RRDVAR *host_fullidname;
124     RRDVAR *host_fullnameid;
125     RRDVAR *host_fullnamename;
126
127     struct rrddim *rrddim;
128
129     struct rrddimvar *next;
130 } RRDDIMVAR;
131
132 // calculated variables (defined in health configuration)
133 // These aggregate time-series data at fixed intervals
134 // (defined in their update_every member below)
135 // These increase the overhead of netdata.
136 //
137 // These calculations are allocated and linked (->next)
138 // under RRDHOST.
139 // Then are also linked to RRDSET (of course only when the
140 // chart is found, via ->rrdset_next and ->rrdset_prev).
141 // This double-linked list is maintained sorted at all times
142 // having as RRDSET.calculations the RRDCALC to be processed
143 // next.
144 typedef struct rrdcalc {
145     char *name;
146     uint32_t hash;
147
148     char *exec;
149
150     char *chart;        // the chart name
151     uint32_t hash_chart;
152
153     char *source;       // the source of this calculation
154
155     char *dimensions;   // the chart dimensions
156
157     int group;          // grouping method: average, max, etc.
158     int before;         // ending point in time-series
159     int after;          // starting point in time-series
160     uint32_t options;   // calculation options
161     int update_every;   // update frequency for the calculation
162
163     time_t last_updated;
164     time_t next_update;
165
166     EVAL_EXPRESSION *warning;
167     EVAL_EXPRESSION *critical;
168
169     calculated_number value;
170
171     calculated_number green;
172     calculated_number red;
173
174     RRDVAR *local;
175     RRDVAR *context;
176     RRDVAR *host;
177
178     struct rrdset *rrdset;
179     struct rrdcalc *rrdset_next;
180     struct rrdcalc *rrdset_prev;
181
182     struct rrdcalc *next;
183 } RRDCALC;
184
185 #define RRDCALC_HAS_CALCULATION(rc) ((rc)->after && (rc)->update_every)
186
187 // RRDCALCTEMPLATE
188 // these are to be applied to charts found dynamically
189 // based on their context.
190 typedef struct rrdcalctemplate {
191     char *name;
192     uint32_t hash_name;
193
194     char *exec;
195
196     char *context;
197     uint32_t hash_context;
198
199     char *source;       // the source of this template
200
201     char *dimensions;
202
203     int group;          // grouping method: average, max, etc.
204     int before;         // ending point in time-series
205     int after;          // starting point in time-series
206     uint32_t options;   // calculation options
207     int update_every;   // update frequency for the calculation
208
209     EVAL_EXPRESSION *warning;
210     EVAL_EXPRESSION *critical;
211
212     calculated_number green;
213     calculated_number red;
214
215     struct rrdcalctemplate *next;
216 } RRDCALCTEMPLATE;
217
218 #define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after && (rt)->update_every)
219
220
221 #include "rrd.h"
222
223 extern void rrdsetvar_rename_all(RRDSET *st);
224 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
225 extern void rrdsetvar_free(RRDSETVAR *rs);
226
227 extern void rrddimvar_rename_all(RRDDIM *rd);
228 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
229 extern void rrddimvar_free(RRDDIMVAR *rs);
230
231 extern void rrdsetcalc_link_matching(RRDSET *st);
232 extern void rrdsetcalc_unlink(RRDCALC *rc);
233
234 extern void health_init(void);
235
236 #endif //NETDATA_HEALTH_H