summaryrefslogtreecommitdiffstats
path: root/src/health.h
blob: 760cee4fe10527751b38ada2b01184f7d311104f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef NETDATA_HEALTH_H
#define NETDATA_HEALTH_H

extern int rrdvar_compare(void *a, void *b);

/*
 * RRDVAR
 * a variable
 *
 * There are 4 scopes: local (chart), context, host and global variables
 *
 * Standard global variables:
 *  $now
 *
 * Standard host variables:
 *  - none -
 *
 * Standard context variables:
 *  - none -
 *
 * Standard local variables:
 *  $last_updated
 *  $last_collected_value
 *  $last_value
 *
 */

#define RRDVAR_TYPE_CALCULATED 1
#define RRDVAR_TYPE_TIME_T     2
#define RRDVAR_TYPE_COLLECTED  3
#define RRDVAR_TYPE_TOTAL      4

// the variables as stored in the variables indexes
typedef struct rrdvar {
    avl avl;

    char *name;
    uint32_t hash;

    int type;
    void *value;

    time_t last_updated;
} RRDVAR;

// variables linked to charts
// We link variables to point the values that are already
// calculated / processed by the normal data collection process
// This means, there will be no speed penalty for using
// these variables
typedef struct rrdsetvar {
    char *fullid;               // chart type.chart id.variable
    uint32_t hash_fullid;

    char *fullname;             // chart type.chart name.variable
    uint32_t hash_fullname;

    char *variable;             // variable
    uint32_t hash_variable;

    int type;
    void *value;

    uint32_t options;

    RRDVAR *local;
    RRDVAR *context;
    RRDVAR *host;
    RRDVAR *context_name;
    RRDVAR *host_name;

    struct rrdset *rrdset;

    struct rrdsetvar *next;
} RRDSETVAR;


// variables linked to dimensions
// We link variables to point the values that are already
// calculated / processed by the normal data collection process
// This means, there will be no speed penalty for using
// these variables
typedef struct rrddimvar {
    char *prefix;
    char *suffix;

    char *id;                   // dimension id
    uint32_t hash;

    char *name;                 // dimension name
    uint32_t hash_name;

    char *fullidid;             // chart type.chart id.dimension id
    uint32_t hash_fullidid;

    char *fullidname;           // chart type.chart id.dimension name
    uint32_t hash_fullidname;

    char *fullnameid;           // chart type.chart name.dimension id
    uint32_t hash_fullnameid;

    char *fullnamename;         // chart type.chart name.dimension name
    uint32_t hash_fullnamename;

    int type;
    void *value;

    uint32_t options;

    RRDVAR *local_id;
    RRDVAR *local_name;

    RRDVAR *context_fullidid;
    RRDVAR *context_fullidname;
    RRDVAR *context_fullnameid;
    RRDVAR *context_fullnamename;

    RRDVAR *host_fullidid;
    RRDVAR *host_fullidname;
    RRDVAR *host_fullnameid;
    RRDVAR *host_fullnamename;

    struct rrddim *rrddim;

    struct rrddimvar *next;
} RRDDIMVAR;

// additional calculated variables
// These aggregate time-series data at fixed intervals
// (defined in their update_every member below)
// These increase the overhead of netdata.
//
// These calculations are allocated and linked (->next)
// to RRDHOST.
// Then are also linked to RRDSET (of course only when the
// chart is found, via ->rrdset_next and ->rrdset_prev).
// This double-linked list is maintained sorted at all times
// having as RRDSET->calculations the RRDCALC to be processed
// next.
typedef struct rrdcalc {
    char *name;
    uint32_t hash;

    char *chart;        // the chart name
    uint32_t hash_chart;

    char *dimensions;   // the chart dimensions

    int group;          // grouping method: average, max, etc.
    int before;         // ending point in time-series
    int after;          // starting point in time-series
    uint32_t options;   // calculation options
    int update_every;   // update frequency for the calculation

    time_t last_updated;
    time_t next_update;

    calculated_number value;

    RRDVAR *local;
    RRDVAR *context;
    RRDVAR *host;

    struct rrdset *rrdset;
    struct rrdcalc *rrdset_next;
    struct rrdcalc *rrdset_prev;

    struct rrdcalc *next;
} RRDCALC;


// RRDCALCTEMPLATE
// these are to be applied to charts found dynamically
// based on their context.
typedef struct rrdcalctemplate {
    char *name;
    uint32_t hash_name;

    char *context;
    uint32_t hash_context;

    char *dimensions;

    int group;          // grouping method: average, max, etc.
    int before;         // ending point in time-series
    int after;          // starting point in time-series
    uint32_t options;   // calculation options
    int update_every;   // update frequency for the calculation

    struct rrdcalctemplate *next;
} RRDCALCTEMPLATE;

#include "rrd.h"

extern void rrdsetvar_rename_all(RRDSET *st);
extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options);
extern void rrdsetvar_free(RRDSETVAR *rs);

extern void rrddimvar_rename_all(RRDDIM *rd);
extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, int type, const char *prefix, const char *suffix, void *value, uint32_t options);
extern void rrddimvar_free(RRDDIMVAR *rs);

extern void rrdsetcalc_link_matching(RRDSET *st);
extern void rrdsetcalc_unlink(RRDCALC *rc);

#endif //NETDATA_HEALTH_H