]> arthur.barton.de Git - netdata.git/blob - src/health.h
added RRDCALC management; preparation for expression evaluation
[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 typedef struct rrdvar {
35     avl avl;
36
37     char *name;
38     uint32_t hash;
39
40     int type;
41     void *value;
42
43     time_t last_updated;
44 } RRDVAR;
45
46 // variables linked to charts
47 // We link variables to point the values that are already
48 // calculated / processed by the normal data collection process
49 // This means, there will be no speed penalty for using
50 // these variables
51 typedef struct rrdsetvar {
52     char *fullid;               // chart type.chart id.variable
53     uint32_t hash_fullid;
54
55     char *fullname;             // chart type.chart name.variable
56     uint32_t hash_fullname;
57
58     char *variable;             // variable
59     uint32_t hash_variable;
60
61     int type;
62     void *value;
63
64     uint32_t options;
65
66     RRDVAR *local;
67     RRDVAR *context;
68     RRDVAR *host;
69     RRDVAR *context_name;
70     RRDVAR *host_name;
71
72     struct rrdset *rrdset;
73
74     struct rrdsetvar *next;
75 } RRDSETVAR;
76
77
78 // variables linked to dimensions
79 // We link variables to point the values that are already
80 // calculated / processed by the normal data collection process
81 // This means, there will be no speed penalty for using
82 // these variables
83 typedef struct rrddimvar {
84     char *prefix;
85     char *suffix;
86
87     char *id;                   // dimension id
88     uint32_t hash;
89
90     char *name;                 // dimension name
91     uint32_t hash_name;
92
93     char *fullidid;             // chart type.chart id.dimension id
94     uint32_t hash_fullidid;
95
96     char *fullidname;           // chart type.chart id.dimension name
97     uint32_t hash_fullidname;
98
99     char *fullnameid;           // chart type.chart name.dimension id
100     uint32_t hash_fullnameid;
101
102     char *fullnamename;         // chart type.chart name.dimension name
103     uint32_t hash_fullnamename;
104
105     int type;
106     void *value;
107
108     uint32_t options;
109
110     RRDVAR *local_id;
111     RRDVAR *local_name;
112
113     RRDVAR *context_fullidid;
114     RRDVAR *context_fullidname;
115     RRDVAR *context_fullnameid;
116     RRDVAR *context_fullnamename;
117
118     RRDVAR *host_fullidid;
119     RRDVAR *host_fullidname;
120     RRDVAR *host_fullnameid;
121     RRDVAR *host_fullnamename;
122
123     struct rrddim *rrddim;
124
125     struct rrddimvar *next;
126 } RRDDIMVAR;
127
128 // additional calculated variables
129 // These aggregate time-series data at fixed intervals
130 // (defined in their update_every member below)
131 // These increase the overhead of netdata.
132 //
133 // These calculations are allocated and linked (->next)
134 // to RRDHOST.
135 // Then are also linked to RRDSET (of course only when the
136 // chart is found, via ->rrdset_next and ->rrdset_prev).
137 // This double-linked list is maintained sorted at all times
138 // having as RRDSET->calculations the RRDCALC to be processed
139 // next.
140 typedef struct rrdcalc {
141     char *name;
142     uint32_t hash;
143
144     char *chart;        // the chart name
145     uint32_t hash_chart;
146
147     char *dimensions;   // the chart dimensions
148
149     int group;          // grouping method: average, max, etc.
150     int before;         // ending point in time-series
151     int after;          // starting point in time-series
152     uint32_t options;   // calculation options
153     int update_every;   // update frequency for the calculation
154
155     time_t last_updated;
156     time_t next_update;
157
158     calculated_number value;
159
160     RRDVAR *local;
161     RRDVAR *context;
162     RRDVAR *host;
163
164     struct rrdset *rrdset;
165     struct rrdcalc *rrdset_next;
166     struct rrdcalc *rrdset_prev;
167
168     struct rrdcalc *next;
169 } RRDCALC;
170
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 *context;
180     uint32_t hash_context;
181
182     char *dimensions;
183
184     int group;          // grouping method: average, max, etc.
185     int before;         // ending point in time-series
186     int after;          // starting point in time-series
187     uint32_t options;   // calculation options
188     int update_every;   // update frequency for the calculation
189
190     struct rrdcalctemplate *next;
191 } RRDCALCTEMPLATE;
192
193 #include "rrd.h"
194
195 extern void rrdsetvar_rename_all(RRDSET *st);
196 extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
197 extern void rrdsetvar_free(RRDSETVAR *rs);
198
199 extern void rrddimvar_rename_all(RRDDIM *rd);
200 extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
201 extern void rrddimvar_free(RRDDIMVAR *rs);
202
203 extern void rrdsetcalc_link_matching(RRDSET *st);
204 extern void rrdsetcalc_unlink(RRDCALC *rc);
205
206 #endif //NETDATA_HEALTH_H