]> arthur.barton.de Git - netdata.git/blob - src/rrd.h
added nfacct charts (disabled for the moment - they must be made an external plugin...
[netdata.git] / src / rrd.h
1 #include <sys/time.h>
2 #include <pthread.h>
3
4 #include "storage_number.h"
5
6 #ifndef NETDATA_RRD_H
7 #define NETDATA_RRD_H 1
8
9 #define UPDATE_EVERY 1
10 #define UPDATE_EVERY_MAX 3600
11 extern int update_every;
12
13 #define HISTORY 3600
14 #define HISTORY_MAX (86400*10)
15 extern int save_history;
16
17 typedef long long total_number;
18
19 #define TOTAL_NUMBER_FORMAT "%lld"
20
21 #define RRD_STATS_NAME_MAX 1024
22
23 #define RRD_STATS_MAGIC     "NETDATA CACHE STATS FILE V009"
24 #define RRD_DIMENSION_MAGIC "NETDATA CACHE DIMENSION FILE V009"
25
26
27 // ----------------------------------------------------------------------------
28 // chart types
29
30 #define CHART_TYPE_LINE_NAME "line"
31 #define CHART_TYPE_AREA_NAME "area"
32 #define CHART_TYPE_STACKED_NAME "stacked"
33
34 #define CHART_TYPE_LINE 0
35 #define CHART_TYPE_AREA 1
36 #define CHART_TYPE_STACKED 2
37
38 int chart_type_id(const char *name);
39 const char *chart_type_name(int chart_type);
40
41
42 // ----------------------------------------------------------------------------
43 // memory mode
44
45 #define NETDATA_MEMORY_MODE_RAM_NAME "ram"
46 #define NETDATA_MEMORY_MODE_MAP_NAME "map"
47 #define NETDATA_MEMORY_MODE_SAVE_NAME "save"
48
49 #define NETDATA_MEMORY_MODE_RAM 0
50 #define NETDATA_MEMORY_MODE_MAP 1
51 #define NETDATA_MEMORY_MODE_SAVE 2
52
53 extern int memory_mode;
54
55 extern const char *memory_mode_name(int id);
56 extern int memory_mode_id(const char *name);
57
58
59 // ----------------------------------------------------------------------------
60 // algorithms types
61
62 #define RRD_DIMENSION_ABSOLUTE_NAME                     "absolute"
63 #define RRD_DIMENSION_INCREMENTAL_NAME                  "incremental"
64 #define RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL_NAME        "percentage-of-incremental-row"
65 #define RRD_DIMENSION_PCENT_OVER_ROW_TOTAL_NAME         "percentage-of-absolute-row"
66
67 #define RRD_DIMENSION_ABSOLUTE                  0
68 #define RRD_DIMENSION_INCREMENTAL               1
69 #define RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL     2
70 #define RRD_DIMENSION_PCENT_OVER_ROW_TOTAL      3
71
72 extern int algorithm_id(const char *name);
73 extern const char *algorithm_name(int chart_type);
74
75 struct rrd_dimension {
76         char magic[sizeof(RRD_DIMENSION_MAGIC) + 1];    // our magic
77         char id[RRD_STATS_NAME_MAX + 1];                                // the id of this dimension (for internal identification)
78         char *name;                                                                             // the name of this dimension (as presented to user)
79         char cache_file[FILENAME_MAX+1];
80         
81         unsigned long hash;                                                             // a simple hash on the id, to speed up searching
82                                                                                                         // we first compare hashes, and only if the hashes are equal we do string comparisons
83
84         long entries;                                                                   // how many entries this dimension has
85                                                                                                         // this should be the same to the entries of the data set
86
87         long current_entry;                                                             // the entry that is currently being updated
88         int update_every;                                                               // every how many seconds is this updated?
89
90         int hidden;                                                                             // if set to non zero, this dimension will not be sent to the client
91         int mapped;                                                                             // 1 if the file is mapped
92         unsigned long memsize;                                                  // the memory allocated for this dimension
93
94         int algorithm;
95         long multiplier;
96         long divisor;
97
98         struct timeval last_collected_time;                             // when was this dimension last updated
99                                                                                                         // this is only used to detect un-updated dimensions
100                                                                                                         // which are removed after some time
101
102         calculated_number calculated_value;
103         calculated_number last_calculated_value;
104
105         collected_number collected_value;                               // the value collected at this round
106         collected_number last_collected_value;                  // the value that was collected at the last round
107
108         struct rrd_dimension *next;                                             // linking of dimensions within the same data set
109
110         storage_number values[];                                                // the array of values - THIS HAS TO BE THE LAST MEMBER
111 };
112 typedef struct rrd_dimension RRD_DIMENSION;
113
114 struct rrd_stats {
115         char magic[sizeof(RRD_STATS_MAGIC) + 1];                // our magic
116
117         char id[RRD_STATS_NAME_MAX + 1];                                // id of the data set
118         char *name;                                                                             // name of the data set
119         char *cache_dir;                                                                // the directory to store dimension maps
120         char cache_file[FILENAME_MAX+1];
121
122         char *type;                                                                             // the type of graph RRD_TYPE_* (a category, for determining graphing options)
123         char *family;                                                                   // the family of this data set (for grouping them together)
124         char *title;                                                                    // title shown to user
125         char *units;                                                                    // units of measurement
126
127         pthread_rwlock_t rwlock;
128         unsigned long counter;                                                  // the number of times we added values to this rrd
129         unsigned long counter_done;                                             // the number of times we added values to this rrd
130
131         int mapped;                                                                             // if set to 1, this is memory mapped
132         unsigned long memsize;                                                  // how much mem we have allocated for this (without dimensions)
133
134         unsigned long hash_name;                                                // a simple hash on the name
135         unsigned long hash;                                                             // a simple hash on the id, to speed up searching
136                                                                                                         // we first compare hashes, and only if the hashes are equal we do string comparisons
137
138         long priority;
139
140         long entries;                                                                   // total number of entries in the data set
141         long current_entry;                                                             // the entry that is currently being updated
142                                                                                                         // it goes around in a round-robin fashion
143
144         int update_every;                                                               // every how many seconds is this updated?
145         unsigned long long first_entry_t;                               // the timestamp (in microseconds) of the oldest entry in the db
146         struct timeval last_updated;                                    // when this data set was last updated (updated every time the rrd_stats_done() function)
147         struct timeval last_collected_time;                             // 
148         unsigned long long usec_since_last_update;
149
150         total_number collected_total;
151         total_number last_collected_total;
152
153         int chart_type;
154         int debug;
155         int enabled;
156         int isdetail;                                                                   // if set, the data set should be considered as a detail of another
157                                                                                                         // (the master data set should be the one that has the same family and is not detail)
158
159         RRD_DIMENSION *dimensions;                                              // the actual data for every dimension
160
161         struct rrd_stats *next;                                                 // linking of rrd stats
162 };
163 typedef struct rrd_stats RRD_STATS;
164
165 extern RRD_STATS *root;
166 extern pthread_rwlock_t root_rwlock;
167
168 extern char *rrd_stats_strncpy_name(char *to, const char *from, int length);
169 extern void rrd_stats_set_name(RRD_STATS *st, const char *name);
170
171 extern char *rrd_stats_cache_dir(const char *id);
172
173 extern void rrd_stats_reset(RRD_STATS *st);
174
175 extern RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name, const char *family, const char *title, const char *units, long priority, int update_every, int chart_type);
176
177 extern RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
178
179 extern void rrd_stats_dimension_set_name(RRD_STATS *st, RRD_DIMENSION *rd, const char *name);
180 extern void rrd_stats_dimension_free(RRD_DIMENSION *rd);
181
182 extern void rrd_stats_free_all(void);
183 extern void rrd_stats_save_all(void);
184
185 extern RRD_STATS *rrd_stats_find(const char *id);
186 extern RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id);
187 extern RRD_STATS *rrd_stats_find_byname(const char *name);
188
189 extern RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id);
190
191 extern int rrd_stats_dimension_hide(RRD_STATS *st, const char *id);
192
193 extern void rrd_stats_dimension_set_by_pointer(RRD_STATS *st, RRD_DIMENSION *rd, collected_number value);
194 extern int rrd_stats_dimension_set(RRD_STATS *st, const char *id, collected_number value);
195
196 extern void rrd_stats_next_usec(RRD_STATS *st, unsigned long long microseconds);
197 extern void rrd_stats_next(RRD_STATS *st);
198 extern void rrd_stats_next_plugins(RRD_STATS *st);
199
200 extern unsigned long long rrd_stats_done(RRD_STATS *st);
201
202 extern time_t rrd_stats_first_entry_t(RRD_STATS *st);
203
204 #endif /* NETDATA_RRD_H */