5 #include "storage_number.h"
8 #define NETDATA_RRD_H 1
10 #define UPDATE_EVERY 1
11 #define UPDATE_EVERY_MAX 3600
12 extern int rrd_update_every;
14 #define RRD_DEFAULT_HISTORY_ENTRIES 3600
15 #define RRD_HISTORY_ENTRIES_MAX (86400*10)
16 extern int rrd_default_history_entries;
18 #define RRD_DEFAULT_GAP_INTERPOLATIONS 10
20 typedef long long total_number;
21 #define TOTAL_NUMBER_FORMAT "%lld"
23 #define RRD_ID_LENGTH_MAX 1024
25 #define RRDSET_MAGIC "NETDATA CACHE STATS FILE V011"
26 #define RRDDIMENSION_MAGIC "NETDATA CACHE DIMENSION FILE V011"
28 // ----------------------------------------------------------------------------
31 #define RRDSET_TYPE_LINE_NAME "line"
32 #define RRDSET_TYPE_AREA_NAME "area"
33 #define RRDSET_TYPE_STACKED_NAME "stacked"
35 #define RRDSET_TYPE_LINE 0
36 #define RRDSET_TYPE_AREA 1
37 #define RRDSET_TYPE_STACKED 2
39 int rrdset_type_id(const char *name);
40 const char *rrdset_type_name(int chart_type);
43 // ----------------------------------------------------------------------------
46 #define RRD_MEMORY_MODE_RAM_NAME "ram"
47 #define RRD_MEMORY_MODE_MAP_NAME "map"
48 #define RRD_MEMORY_MODE_SAVE_NAME "save"
50 #define RRD_MEMORY_MODE_RAM 0
51 #define RRD_MEMORY_MODE_MAP 1
52 #define RRD_MEMORY_MODE_SAVE 2
54 extern int rrd_memory_mode;
56 extern const char *rrd_memory_mode_name(int id);
57 extern int rrd_memory_mode_id(const char *name);
60 // ----------------------------------------------------------------------------
63 #define RRDDIM_ABSOLUTE_NAME "absolute"
64 #define RRDDIM_INCREMENTAL_NAME "incremental"
65 #define RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME "percentage-of-incremental-row"
66 #define RRDDIM_PCENT_OVER_ROW_TOTAL_NAME "percentage-of-absolute-row"
68 #define RRDDIM_ABSOLUTE 0
69 #define RRDDIM_INCREMENTAL 1
70 #define RRDDIM_PCENT_OVER_DIFF_TOTAL 2
71 #define RRDDIM_PCENT_OVER_ROW_TOTAL 3
73 extern int rrddim_algorithm_id(const char *name);
74 extern const char *rrddim_algorithm_name(int chart_type);
77 // ----------------------------------------------------------------------------
83 char magic[sizeof(RRDDIMENSION_MAGIC) + 1]; // our magic
84 char id[RRD_ID_LENGTH_MAX + 1]; // the id of this dimension (for internal identification)
85 const char *name; // the name of this dimension (as presented to user)
86 char cache_filename[FILENAME_MAX+1];
88 unsigned long hash; // a simple hash on the id, to speed up searching
89 // we first compare hashes, and only if the hashes are equal we do string comparisons
91 long entries; // how many entries this dimension has
92 // this should be the same to the entries of the data set
94 int update_every; // every how many seconds is this updated?
95 int updated; // set to 0 after each calculation, to 1 after each collected value
97 int hidden; // if set to non zero, this dimension will not be sent to the client
98 int mapped; // 1 if the file is mapped
99 unsigned long memsize; // the memory allocated for this dimension
105 struct timeval last_collected_time; // when was this dimension last updated
106 // this is actual date time we updated the last_collected_value
107 // THIS IS DIFFERENT FROM THE SAME MEMBER OF RRD_STATS
109 calculated_number calculated_value;
110 calculated_number last_calculated_value;
112 collected_number collected_value; // the value collected at this round
113 collected_number last_collected_value; // the value that was collected at the last round
115 calculated_number collected_volume;
116 calculated_number stored_volume;
118 struct rrddim *next; // linking of dimensions within the same data set
120 storage_number values[]; // the array of values - THIS HAS TO BE THE LAST MEMBER
122 typedef struct rrddim RRDDIM;
125 // ----------------------------------------------------------------------------
131 char magic[sizeof(RRDSET_MAGIC) + 1]; // our magic
133 char id[RRD_ID_LENGTH_MAX + 1]; // id of the data set
134 const char *name; // name of the data set
135 char *cache_dir; // the directory to store dimension maps
136 char cache_filename[FILENAME_MAX+1];
138 char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
139 char *family; // the family of this data set (for grouping them together)
140 char *title; // title shown to user
141 char *units; // units of measurement
143 pthread_rwlock_t rwlock;
144 unsigned long counter; // the number of times we added values to this rrd
145 unsigned long counter_done; // the number of times we added values to this rrd
147 int mapped; // if set to 1, this is memory mapped
148 unsigned long memsize; // how much mem we have allocated for this (without dimensions)
150 unsigned long hash_name; // a simple hash on the name
151 unsigned long hash; // a simple hash on the id, to speed up searching
152 // we first compare hashes, and only if the hashes are equal we do string comparisons
154 int gap_when_lost_iterations_above; // after how many lost iterations a gap should be stored
155 // netdata will interpolate values for gaps lower than this
159 long entries; // total number of entries in the data set
160 long current_entry; // the entry that is currently being updated
161 // it goes around in a round-robin fashion
163 int update_every; // every how many seconds is this updated?
164 unsigned long long first_entry_t; // the timestamp (in microseconds) of the oldest entry in the db
165 struct timeval last_updated; // when this data set was last updated (updated every time the rrd_stats_done() function)
166 struct timeval last_collected_time; //
167 unsigned long long usec_since_last_update;
169 total_number collected_total;
170 total_number last_collected_total;
175 int isdetail; // if set, the data set should be considered as a detail of another
176 // (the master data set should be the one that has the same family and is not detail)
178 RRDDIM *dimensions; // the actual data for every dimension
180 avl_tree dimensions_index;
182 struct rrdset *next; // linking of rrdsets
184 typedef struct rrdset RRDSET;
186 extern RRDSET *rrdset_root;
187 extern pthread_rwlock_t rrdset_root_rwlock;
189 // ----------------------------------------------------------------------------
192 extern char *rrdset_strncpy_name(char *to, const char *from, int length);
193 extern void rrdset_set_name(RRDSET *st, const char *name);
195 extern char *rrdset_cache_dir(const char *id);
197 extern void rrdset_reset(RRDSET *st);
199 extern RRDSET *rrdset_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);
201 extern void rrdset_free_all(void);
202 extern void rrdset_save_all(void);
204 extern RRDSET *rrdset_find(const char *id);
205 extern RRDSET *rrdset_find_bytype(const char *type, const char *id);
206 extern RRDSET *rrdset_find_byname(const char *name);
208 extern void rrdset_next_usec(RRDSET *st, unsigned long long microseconds);
209 extern void rrdset_next(RRDSET *st);
210 extern void rrdset_next_plugins(RRDSET *st);
212 extern unsigned long long rrdset_done(RRDSET *st);
214 extern time_t rrdset_first_entry_t(RRDSET *st);
217 // ----------------------------------------------------------------------------
218 // RRD DIMENSION functions
220 extern RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
222 extern void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name);
223 extern void rrddim_free(RRDSET *st, RRDDIM *rd);
225 extern RRDDIM *rrddim_find(RRDSET *st, const char *id);
227 extern int rrddim_hide(RRDSET *st, const char *id);
229 extern void rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value);
230 extern int rrddim_set(RRDSET *st, const char *id, collected_number value);
232 #endif /* NETDATA_RRD_H */