4 #include "storage_number.h"
7 #define NETDATA_RRD_H 1
10 #define UPDATE_EVERY_MAX 3600
11 extern int update_every;
14 #define HISTORY_MAX (86400*10)
15 extern int save_history;
17 typedef long long total_number;
19 #define TOTAL_NUMBER_FORMAT "%lld"
21 #define RRD_STATS_NAME_MAX 1024
23 #define RRD_STATS_MAGIC "NETDATA CACHE STATS FILE V009"
24 #define RRD_DIMENSION_MAGIC "NETDATA CACHE DIMENSION FILE V009"
27 // ----------------------------------------------------------------------------
30 #define CHART_TYPE_LINE_NAME "line"
31 #define CHART_TYPE_AREA_NAME "area"
32 #define CHART_TYPE_STACKED_NAME "stacked"
34 #define CHART_TYPE_LINE 0
35 #define CHART_TYPE_AREA 1
36 #define CHART_TYPE_STACKED 2
38 int chart_type_id(const char *name);
39 const char *chart_type_name(int chart_type);
42 // ----------------------------------------------------------------------------
45 #define NETDATA_MEMORY_MODE_RAM_NAME "ram"
46 #define NETDATA_MEMORY_MODE_MAP_NAME "map"
47 #define NETDATA_MEMORY_MODE_SAVE_NAME "save"
49 #define NETDATA_MEMORY_MODE_RAM 0
50 #define NETDATA_MEMORY_MODE_MAP 1
51 #define NETDATA_MEMORY_MODE_SAVE 2
53 extern int memory_mode;
55 extern const char *memory_mode_name(int id);
56 extern int memory_mode_id(const char *name);
59 // ----------------------------------------------------------------------------
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"
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
72 extern int algorithm_id(const char *name);
73 extern const char *algorithm_name(int chart_type);
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];
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
84 long entries; // how many entries this dimension has
85 // this should be the same to the entries of the data set
87 long current_entry; // the entry that is currently being updated
88 int update_every; // every how many seconds is this updated?
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
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
102 calculated_number calculated_value;
103 calculated_number last_calculated_value;
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
108 struct rrd_dimension *next; // linking of dimensions within the same data set
110 storage_number values[]; // the array of values - THIS HAS TO BE THE LAST MEMBER
112 typedef struct rrd_dimension RRD_DIMENSION;
115 char magic[sizeof(RRD_STATS_MAGIC) + 1]; // our magic
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];
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
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
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)
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
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
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;
150 total_number collected_total;
151 total_number last_collected_total;
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)
159 RRD_DIMENSION *dimensions; // the actual data for every dimension
161 struct rrd_stats *next; // linking of rrd stats
163 typedef struct rrd_stats RRD_STATS;
165 extern RRD_STATS *root;
166 extern pthread_rwlock_t root_rwlock;
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);
171 extern char *rrd_stats_cache_dir(const char *id);
173 extern void rrd_stats_reset(RRD_STATS *st);
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);
177 extern RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
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);
182 extern void rrd_stats_free_all(void);
183 extern void rrd_stats_save_all(void);
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);
189 extern RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id);
191 extern int rrd_stats_dimension_hide(RRD_STATS *st, const char *id);
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);
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);
200 extern unsigned long long rrd_stats_done(RRD_STATS *st);
202 extern time_t rrd_stats_first_entry_t(RRD_STATS *st);
204 #endif /* NETDATA_RRD_H */