@cryptotaxi247 / netdata-1 / commits / 6a9c3d217

added libavl for supporting balanced binary trees - this improves search performance in config, chart updates, etc. refactored several class names and global variables

Costa Tsaousis (ktsaou) committed Mar 22, 2015 at 20:48 UTC 6a9c3d217fc1a249fd12286d76387ef3a9f63163
33 files changed +1894 -1307
src/Makefile
+11 -11
@@ -1,5 +1,5 @@
1 ifndef BIN_DIR
2 -BIN_DIR = "$(PWD)"
2 +BIN_DIR = "."
3 endif
4
5 ifndef CONFIG_DIR
@@ -20,19 +20,21 @@ endif
20
21 COMMON_FLAGS = BIN_DIR='$(BIN_DIR)' CONFIG_DIR='$(CONFIG_DIR)' LOG_DIR='$(LOG_DIR)' PLUGINS_DIR='$(PLUGINS_DIR)'
22
23 +proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c
24 +sources = avl.c procfile.c common.c log.c popen.c url.c config.c web_buffer.c storage_number.c web_client.c global_statistics.c rrd.c rrd2json.c web_server.c plugins_d.c daemon.c plugin_tc.c plugin_checks.c plugin_idlejitter.c plugin_proc.c unit_test.c main.c
25 +libs = -pthread -lz
26 +
27 ifdef debug
28 COMMON_FLAGS += debug=1
25 -CFLAGS = -Wall -Wextra -ggdb -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)'
29 +CFLAGS = -Wall -Wextra -O -ggdb -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fno-omit-frame-pointer
30 +# CFLAGS := -Wall -Wextra -O -g -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fsanitize=thread -fno-omit-frame-pointer -fPIE
31 +# libs += -pie -ltsan
32 else
27 -CFLAGS = -Wall -Wextra -O3 -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)'
33 +CFLAGS := -Wall -Wextra -O3 -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fomit-frame-pointer
34 endif
35
36 CC = gcc
37
32 -proc_sources = proc_net_dev.c proc_net_ip_vs_stats.c proc_diskstats.c proc_meminfo.c proc_net_netstat.c proc_net_snmp.c proc_net_stat_conntrack.c proc_stat.c proc_vmstat.c proc_net_rpc_nfsd.c
33 -sources = procfile.c common.c log.c popen.c url.c config.c web_buffer.c storage_number.c web_client.c global_statistics.c rrd.c rrd2json.c web_server.c plugins_d.c daemon.c plugin_tc.c plugin_checks.c plugin_idlejitter.c plugin_proc.c unit_test.c main.c
34 -libs = -pthread -lz
35 -
38 ifdef STORAGE_WITH_MATH
39 CFLAGS += -DSTORAGE_WITH_MATH=1
40 libs += -lm
@@ -51,12 +53,10 @@ objects = $(patsubst %.c,%.o,$(sources) $(proc_sources))
53 all: show_options netdata plugins
54
55 %.o: %.c ${headers}
54 - @echo " $(CC) $<"
55 - @$(CC) $(CFLAGS) -c $< -o $@
56 + $(CC) $(CFLAGS) -c $< -o $@
57
58 netdata: $(objects)
58 - @echo " $(CC) netdata"
59 - @$(CC) -o netdata $(objects) $(libs)
59 + $(CC) -o netdata $(objects) $(libs)
60
61 show_options:
62 @echo " COMPILING WITH OPTIONS: $(CFLAGS)"
src/avl.c new
+316
@@ -0,0 +1,316 @@
1 +/*
2 + * ANSI C Library for maintainance of AVL Balanced Trees
3 + *
4 + * ref.:
5 + * G. M. Adelson-Velskij & E. M. Landis
6 + * Doklady Akad. Nauk SSSR 146 (1962), 263-266
7 + *
8 + * see also:
9 + * D. E. Knuth: The Art of Computer Programming Vol.3 (Sorting and Searching)
10 + *
11 + * (C) 2000 Daniel Nagy, Budapest University of Technology and Economics
12 + * Released under GNU General Public License (GPL) version 2
13 + *
14 + */
15 +
16 +#include "avl.h"
17 +
18 +/* Private methods */
19 +
20 +/* Swing to the left
21 + * Warning: no balance maintainance
22 + */
23 +void avl_swl(avl** root) {
24 + avl* a = *root;
25 + avl* b = a->right;
26 + *root = b;
27 + a->right = b->left;
28 + b->left = a;
29 +}
30 +
31 +/* Swing to the right
32 + * Warning: no balance maintainance
33 + */
34 +void avl_swr(avl** root) {
35 + avl* a = *root;
36 + avl* b = a->left;
37 + *root = b;
38 + a->left = b->right;
39 + b->right = a;
40 +}
41 +
42 +/* Balance maintainance after especially nasty swings
43 + */
44 +void avl_nasty(avl* root) {
45 + switch (root->balance) {
46 + case -1:
47 + root->left->balance = 0;
48 + root->right->balance = 1;
49 + break;
50 + case 1:
51 + root->left->balance = -1;
52 + root->right->balance = 0;
53 + break;
54 + case 0:
55 + root->left->balance = 0;
56 + root->right->balance = 0;
57 + }
58 + root->balance = 0;
59 +}
60 +
61 +/* Public methods */
62 +
63 +/* Insert element a into the AVL tree t
64 + * returns 1 if the depth of the tree has grown
65 + * Warning: do not insert elements already present
66 + */
67 +int avl_insert(avl_tree* t, avl* a) {
68 + /* initialize */
69 + a->left = 0;
70 + a->right = 0;
71 + a->balance = 0;
72 + /* insert into an empty tree */
73 + if (!t->root) {
74 + t->root = a;
75 + return 1;
76 + }
77 +
78 + if (t->compar(t->root, a) > 0) {
79 + /* insert into the left subtree */
80 + if (t->root->left) {
81 + avl_tree left_subtree;
82 + left_subtree.root = t->root->left;
83 + left_subtree.compar = t->compar;
84 + if (avl_insert(&left_subtree, a)) {
85 + switch (t->root->balance--) {
86 + case 1:
87 + return 0;
88 + case 0:
89 + return 1;
90 + }
91 + if (t->root->left->balance < 0) {
92 + avl_swr(&(t->root));
93 + t->root->balance = 0;
94 + t->root->right->balance = 0;
95 + } else {
96 + avl_swl(&(t->root->left));
97 + avl_swr(&(t->root));
98 + avl_nasty(t->root);
99 + }
100 + } else
101 + t->root->left = left_subtree.root;
102 + return 0;
103 + } else {
104 + t->root->left = a;
105 + if (t->root->balance--)
106 + return 0;
107 + return 1;
108 + }
109 + } else {
110 + /* insert into the right subtree */
111 + if (t->root->right) {
112 + avl_tree right_subtree;
113 + right_subtree.root = t->root->right;
114 + right_subtree.compar = t->compar;
115 + if (avl_insert(&right_subtree, a)) {
116 + switch (t->root->balance++) {
117 + case -1:
118 + return 0;
119 + case 0:
120 + return 1;
121 + }
122 + if (t->root->right->balance > 0) {
123 + avl_swl(&(t->root));
124 + t->root->balance = 0;
125 + t->root->left->balance = 0;
126 + } else {
127 + avl_swr(&(t->root->right));
128 + avl_swl(&(t->root));
129 + avl_nasty(t->root);
130 + }
131 + } else
132 + t->root->right = right_subtree.root;
133 + return 0;
134 + } else {
135 + t->root->right = a;
136 + if (t->root->balance++)
137 + return 0;
138 + return 1;
139 + }
140 + }
141 +}
142 +
143 +/* Remove an element a from the AVL tree t
144 + * returns -1 if the depth of the tree has shrunk
145 + * Warning: if the element is not present in the tree,
146 + * returns 0 as if it had been removed succesfully.
147 + */
148 +int avl_remove(avl_tree* t, avl* a) {
149 + int b;
150 + if (t->root == a)
151 + return avl_removeroot(t);
152 + b = t->compar(t->root, a);
153 + if (b >= 0) {
154 + /* remove from the left subtree */
155 + int ch;
156 + avl_tree left_subtree;
157 + if ((left_subtree.root = t->root->left)) {
158 + left_subtree.compar = t->compar;
159 + ch = avl_remove(&left_subtree, a);
160 + t->root->left = left_subtree.root;
161 + if (ch) {
162 + switch (t->root->balance++) {
163 + case -1:
164 + return -1;
165 + case 0:
166 + return 0;
167 + }
168 + switch (t->root->right->balance) {
169 + case 0:
170 + avl_swl(&(t->root));
171 + t->root->balance = -1;
172 + t->root->left->balance = 1;
173 + return 0;
174 + case 1:
175 + avl_swl(&(t->root));
176 + t->root->balance = 0;
177 + t->root->left->balance = 0;
178 + return -1;
179 + }
180 + avl_swr(&(t->root->right));
181 + avl_swl(&(t->root));
182 + avl_nasty(t->root);
183 + return -1;
184 + }
185 + }
186 + }
187 + if (b <= 0) {
188 + /* remove from the right subtree */
189 + int ch;
190 + avl_tree right_subtree;
191 + if ((right_subtree.root = t->root->right)) {
192 + right_subtree.compar = t->compar;
193 + ch = avl_remove(&right_subtree, a);
194 + t->root->right = right_subtree.root;
195 + if (ch) {
196 + switch (t->root->balance--) {
197 + case 1:
198 + return -1;
199 + case 0:
200 + return 0;
201 + }
202 + switch (t->root->left->balance) {
203 + case 0:
204 + avl_swr(&(t->root));
205 + t->root->balance = 1;
206 + t->root->right->balance = -1;
207 + return 0;
208 + case -1:
209 + avl_swr(&(t->root));
210 + t->root->balance = 0;
211 + t->root->right->balance = 0;
212 + return -1;
213 + }
214 + avl_swl(&(t->root->left));
215 + avl_swr(&(t->root));
216 + avl_nasty(t->root);
217 + return -1;
218 + }
219 + }
220 + }
221 + return 0;
222 +}
223 +
224 +/* Remove the root of the AVL tree t
225 + * Warning: dumps core if t is empty
226 + */
227 +int avl_removeroot(avl_tree* t) {
228 + int ch;
229 + avl* a;
230 + if (!t->root->left) {
231 + if (!t->root->right) {
232 + t->root = 0;
233 + return -1;
234 + }
235 + t->root = t->root->right;
236 + return -1;
237 + }
238 + if (!t->root->right) {
239 + t->root = t->root->left;
240 + return -1;
241 + }
242 + if (t->root->balance < 0) {
243 + /* remove from the left subtree */
244 + a = t->root->left;
245 + while (a->right)
246 + a = a->right;
247 + } else {
248 + /* remove from the right subtree */
249 + a = t->root->right;
250 + while (a->left)
251 + a = a->left;
252 + }
253 + ch = avl_remove(t, a);
254 + a->left = t->root->left;
255 + a->right = t->root->right;
256 + a->balance = t->root->balance;
257 + t->root = a;
258 + if (a->balance == 0)
259 + return ch;
260 + return 0;
261 +}
262 +
263 +/* Iterate through elements in t from a range between a and b (inclusive)
264 + * for each element calls iter(a) until it returns 0
265 + * returns the last value returned by iterator or 0 if there were no calls
266 + * Warning: a<=b must hold
267 + */
268 +int avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl* a), avl** ret) {
269 + int x, c = 0;
270 + if (!t->root)
271 + return 0;
272 + x = t->compar(t->root, a);
273 + if (a != b) {
274 + if (x < 0) {
275 + x = t->compar(t->root, b);
276 + if (x > 0)
277 + x = 0;
278 + }
279 + }
280 + if (x >= 0) {
281 + /* search in the left subtree */
282 + avl_tree left_subtree;
283 + if ((left_subtree.root = t->root->left)) {
284 + left_subtree.compar = t->compar;
285 + if (!(c = avl_range(&left_subtree, a, b, iter, ret)))
286 + if (x > 0)
287 + return 0;
288 + }
289 + }
290 + if (x == 0) {
291 + if (!(c = iter(t->root))) {
292 + if (ret)
293 + *ret = t->root;
294 + return 0;
295 + }
296 + }
297 + if (x <= 0) {
298 + /* search in the right subtree */
299 + avl_tree right_subtree;
300 + if ((right_subtree.root = t->root->right)) {
301 + right_subtree.compar = t->compar;
302 + if (!(c = avl_range(&right_subtree, a, b, iter, ret)))
303 + if (x < 0)
304 + return 0;
305 + }
306 + }
307 + return c;
308 +}
309 +
310 +/* Iterate through elements in t equal to a
311 + * for each element calls iter(a) until it returns 0
312 + * returns the last value returned by iterator or 0 if there were no calls
313 + */
314 +int avl_search(avl_tree* t, avl* a, int (*iter)(avl* a), avl** ret) {
315 + return avl_range(t, a, a, iter, ret);
316 +}
src/avl.h new
+67
@@ -0,0 +1,67 @@
1 +/*
2 + * ANSI C Library for maintainance of AVL Balanced Trees
3 + *
4 + * ref.:
5 + * G. M. Adelson-Velskij & E. M. Landis
6 + * Doklady Akad. Nauk SSSR 146 (1962), 263-266
7 + *
8 + * see also:
9 + * D. E. Knuth: The Art of Computer Programming Vol.3 (Sorting and Searching)
10 + *
11 + * (C) 2000 Daniel Nagy, Budapest University of Technology and Economics
12 + * Released under GNU General Public License (GPL) version 2
13 + *
14 + */
15 +
16 +#ifndef _AVL_H
17 +#define _AVL_H 1
18 +
19 +/* Data structures */
20 +
21 +/* One element of the AVL tree */
22 +typedef struct avl {
23 + struct avl* left;
24 + struct avl* right;
25 + signed char balance;
26 +} avl;
27 +
28 +/* An AVL tree */
29 +typedef struct avl_tree {
30 + avl* root;
31 + int (*compar)(void* a, void* b);
32 +} avl_tree;
33 +
34 +/* Public methods */
35 +
36 +/* Insert element a into the AVL tree t
37 + * returns 1 if the depth of the tree has grown
38 + * Warning: do not insert elements already present
39 + */
40 +int avl_insert(avl_tree* t, avl* a);
41 +
42 +/* Remove an element a from the AVL tree t
43 + * returns -1 if the depth of the tree has shrunk
44 + * Warning: if the element is not present in the tree,
45 + * returns 0 as if it had been removed succesfully.
46 + */
47 +int avl_remove(avl_tree* t, avl* a);
48 +
49 +/* Remove the root of the AVL tree t
50 + * Warning: dumps core if t is empty
51 + */
52 +int avl_removeroot(avl_tree* t);
53 +
54 +/* Iterate through elements in t from a range between a and b (inclusive)
55 + * for each element calls iter(a) until it returns 0
56 + * returns the last value returned by iterator or 0 if there were no calls
57 + * Warning: a<=b must hold
58 + */
59 +int avl_range(avl_tree* t, avl* a, avl* b, int (*iter)(avl* a), avl** ret);
60 +
61 +/* Iterate through elements in t equal to a
62 + * for each element calls iter(a) until it returns 0
63 + * returns the last value returned by iterator or 0 if there were no calls
64 + */
65 +int avl_search(avl_tree* t, avl* a, int (*iter)(avl* a), avl** ret);
66 +
67 +#endif /* avl.h */
src/common.c
-19
@@ -9,12 +9,10 @@
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <sys/mman.h>
12 -#include <malloc.h>
12
13
14 #include "log.h"
15 #include "common.h"
17 -#include "web_client.h"
16
17 // http://stackoverflow.com/questions/7666509/hash-function-for-string
18 unsigned long simple_hash(const char *name)
@@ -159,23 +157,6 @@ int savememory(const char *filename, void *mem, unsigned long size)
157 return ret;
158 }
159
162 -void log_allocations(void)
163 -{
164 - static int mem = 0;
165 -
166 - struct mallinfo mi;
167 -
168 - mi = mallinfo();
169 - if(mi.uordblks > mem) {
170 - int clients = 0;
171 - struct web_client *w;
172 - for(w = web_clients; w ; w = w->next) clients++;
173 -
174 - info("Allocated memory increased from %d to %d (increased by %d bytes). There are %d web clients connected.", mem, mi.uordblks, mi.uordblks - mem, clients);
175 - mem = mi.uordblks;
176 - }
177 -}
178 -
160 int fd_is_valid(int fd) {
161 return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
162 }
src/common.h
-2
@@ -13,8 +13,6 @@ extern char *trim(char *s);
13 extern void *mymmap(const char *filename, unsigned long size, int flags);
14 extern int savememory(const char *filename, void *mem, unsigned long size);
15
16 -extern void log_allocations(void);
17 -
16 extern int fd_is_valid(int fd);
17
18 #endif /* NETDATA_COMMON_H */
src/config.c
+96 -41
@@ -1,7 +1,9 @@
1 #include <pthread.h>
2 #include <stdlib.h>
3 #include <string.h>
4 +#include <inttypes.h>
5
6 +#include "avl.h"
7 #include "common.h"
8 #include "config.h"
9 #include "log.h"
@@ -10,31 +12,96 @@
12
13 pthread_rwlock_t config_rwlock = PTHREAD_RWLOCK_INITIALIZER;
14
15 +// ----------------------------------------------------------------------------
16 +// definitions
17 +
18 +#define CONFIG_VALUE_LOADED 0x01 // has been loaded from the config
19 +#define CONFIG_VALUE_USED 0x02 // has been accessed from the program
20 +#define CONFIG_VALUE_CHANGED 0x04 // has been changed from the loaded value
21 +#define CONFIG_VALUE_CHECKED 0x08 // has been checked if the value is different from the default
22 +
23 struct config_value {
14 - char name[CONFIG_MAX_NAME + 1];
15 - char value[CONFIG_MAX_VALUE + 1];
24 + avl avl;
25
26 unsigned long hash; // a simple hash to speed up searching
27 // we first compare hashes, and only if the hashes are equal we do string comparisons
28
20 - int loaded; // loaded from the user config
21 - int used; // has been accessed from the program
22 - int changed; // changed from the internal default
29 + char name[CONFIG_MAX_NAME + 1];
30 + char value[CONFIG_MAX_VALUE + 1];
31 +
32 + uint8_t flags;
33
34 struct config_value *next;
35 };
36
37 struct config {
28 - char name[CONFIG_MAX_NAME + 1];
38 + avl avl;
39
40 unsigned long hash; // a simple hash to speed up searching
41 // we first compare hashes, and only if the hashes are equal we do string comparisons
42
43 + char name[CONFIG_MAX_NAME + 1];
44 +
45 struct config_value *values;
46 + avl_tree values_index;
47
48 struct config *next;
49 } *config_root = NULL;
50
51 +
52 +// ----------------------------------------------------------------------------
53 +// config value
54 +
55 +static int config_value_iterator(avl *a) { if(a) {}; return 0; }
56 +
57 +static int config_value_compare(void* a, void* b) {
58 + if(((struct config_value *)a)->hash < ((struct config_value *)b)->hash) return -1;
59 + else if(((struct config_value *)a)->hash > ((struct config_value *)b)->hash) return 1;
60 + else return strcmp(((struct config_value *)a)->name, ((struct config_value *)b)->name);
61 +}
62 +
63 +#define config_value_index_add(co, cv) avl_insert(&((co)->values_index), (avl *)(cv))
64 +#define config_value_index_del(co, cv) avl_remove(&((co)->values_index), (avl *)(cv))
65 +
66 +static struct config_value *config_value_index_find(struct config *co, const char *name, unsigned long hash) {
67 + struct config_value *result = NULL, tmp;
68 + tmp.hash = (hash)?hash:simple_hash(name);
69 + strncpy(tmp.name, name, CONFIG_MAX_NAME);
70 + tmp.name[CONFIG_MAX_NAME] = '\0';
71 +
72 + avl_search(&(co->values_index), (avl *)&tmp, config_value_iterator, (avl **)&result);
73 + return result;
74 +}
75 +
76 +// ----------------------------------------------------------------------------
77 +// config
78 +
79 +static int config_iterator(avl *a) { if(a) {}; return 0; }
80 +
81 +static int config_compare(void* a, void* b) {
82 + if(((struct config *)a)->hash < ((struct config *)b)->hash) return -1;
83 + else if(((struct config *)a)->hash > ((struct config *)b)->hash) return 1;
84 + else return strcmp(((struct config *)a)->name, ((struct config *)b)->name);
85 +}
86 +
87 +avl_tree config_root_index = {
88 + NULL,
89 + config_compare
90 +};
91 +
92 +#define config_index_add(cfg) avl_insert(&config_root_index, (avl *)(cfg))
93 +#define config_index_del(cfg) avl_remove(&config_root_index, (avl *)(cfg))
94 +
95 +static struct config *config_index_find(const char *name, unsigned long hash) {
96 + struct config *result = NULL, tmp;
97 + tmp.hash = (hash)?hash:simple_hash(name);
98 + strncpy(tmp.name, name, CONFIG_MAX_NAME);
99 + tmp.name[CONFIG_MAX_NAME] = '\0';
100 +
101 + avl_search(&config_root_index, (avl *)&tmp, config_iterator, (avl **)&result);
102 + return result;
103 +}
104 +
105 struct config_value *config_value_create(struct config *co, const char *name, const char *value)
106 {
107 debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);
@@ -46,6 +113,8 @@ struct config_value *config_value_create(struct config *co, const char *name, co
113 strncpy(cv->value, value, CONFIG_MAX_VALUE);
114 cv->hash = simple_hash(cv->name);
115
116 + config_value_index_add(co, cv);
117 +
118 // no need for string termination, due to calloc()
119
120 struct config_value *cv2 = co->values;
@@ -67,6 +136,9 @@ struct config *config_create(const char *section)
136
137 strncpy(co->name, section, CONFIG_MAX_NAME);
138 co->hash = simple_hash(co->name);
139 + co->values_index.compar = config_value_compare;
140 +
141 + config_index_add(co);
142
143 // no need for string termination, due to calloc()
144
@@ -82,15 +154,7 @@ struct config *config_create(const char *section)
154
155 struct config *config_find_section(const char *section)
156 {
85 - struct config *co;
86 - unsigned long hash = simple_hash(section);
87 -
88 - for(co = config_root; co ; co = co->next)
89 - if(hash == co->hash)
90 - if(strcmp(co->name, section) == 0)
91 - break;
92 -
93 - return co;
157 + return config_index_find(section, 0);
158 }
159
160 int load_config(char *filename, int overwrite_used)
@@ -159,13 +223,11 @@ int load_config(char *filename, int overwrite_used)
223 continue;
224 }
225
162 - struct config_value *cv;
163 - for(cv = co->values; cv ; cv = cv->next)
164 - if(strcmp(cv->name, name) == 0) break;
226 + struct config_value *cv = config_value_index_find(co, name, 0);
227
228 if(!cv) cv = config_value_create(co, name, value);
229 else {
168 - if((cv->used && overwrite_used) || !cv->used) {
230 + if((cv->flags & CONFIG_VALUE_USED && overwrite_used) || !(cv->flags & CONFIG_VALUE_USED)) {
231 debug(D_CONFIG, "Overwriting '%s/%s'.", line, co->name, cv->name);
232 strncpy(cv->value, value, CONFIG_MAX_VALUE);
233 // termination is already there
@@ -173,7 +235,7 @@ int load_config(char *filename, int overwrite_used)
235 else
236 debug(D_CONFIG, "Ignoring line %d, '%s/%s' is already present and used.", line, co->name, cv->name);
237 }
176 - cv->loaded = 1;
238 + cv->flags |= CONFIG_VALUE_LOADED;
239 }
240
241 fclose(fp);
@@ -193,19 +255,17 @@ char *config_get(const char *section, const char *name, const char *default_valu
255 struct config *co = config_find_section(section);
256 if(!co) co = config_create(section);
257
196 - unsigned long hash = simple_hash(name);
197 - for(cv = co->values; cv ; cv = cv->next)
198 - if(hash == cv->hash)
199 - if(strcmp(cv->name, name) == 0)
200 - break;
201 -
258 + cv = config_value_index_find(co, name, 0);
259 if(!cv) cv = config_value_create(co, name, default_value);
203 - cv->used = 1;
260 + cv->flags |= CONFIG_VALUE_USED;
261
205 - if(cv->loaded || cv->changed) {
262 + if(cv->flags & CONFIG_VALUE_LOADED || cv->flags & CONFIG_VALUE_CHANGED) {
263 // this is a loaded value from the config file
264 // if it is different that the default, mark it
208 - if(strcmp(cv->value, default_value) != 0) cv->changed = 1;
265 + if(!(cv->flags & CONFIG_VALUE_CHECKED)) {
266 + if(strcmp(cv->value, default_value) != 0) cv->flags |= CONFIG_VALUE_CHANGED;
267 + cv->flags |= CONFIG_VALUE_CHECKED;
268 + }
269 }
270 else {
271 // this is not loaded from the config
@@ -255,16 +315,11 @@ const char *config_set(const char *section, const char *name, const char *value)
315 struct config *co = config_find_section(section);
316 if(!co) co = config_create(section);
317
258 - unsigned long hash = simple_hash(name);
259 - for(cv = co->values; cv ; cv = cv->next)
260 - if(hash == cv->hash)
261 - if(strcmp(cv->name, name) == 0)
262 - break;
263 -
318 + cv = config_value_index_find(co, name, 0);
319 if(!cv) cv = config_value_create(co, name, value);
265 - cv->used = 1;
320 + cv->flags |= CONFIG_VALUE_USED;
321
267 - if(strcmp(cv->value, value) != 0) cv->changed = 1;
322 + if(strcmp(cv->value, value) != 0) cv->flags |= CONFIG_VALUE_CHANGED;
323
324 strncpy(cv->value, value, CONFIG_MAX_VALUE);
325 // termination is already there
@@ -331,8 +386,8 @@ void generate_config(struct web_buffer *wb, int only_changed)
386 int changed = 0;
387 int count = 0;
388 for(cv = co->values; cv ; cv = cv->next) {
334 - used += cv->used;
335 - changed += cv->changed;
389 + used += (cv->flags && CONFIG_VALUE_USED)?1:0;
390 + changed += (cv->flags & CONFIG_VALUE_CHANGED)?1:0;
391 count++;
392 }
393
@@ -349,12 +404,12 @@ void generate_config(struct web_buffer *wb, int only_changed)
404
405 for(cv = co->values; cv ; cv = cv->next) {
406
352 - if(used && !cv->used) {
407 + if(used && !(cv->flags & CONFIG_VALUE_USED)) {
408 web_buffer_increase(wb, CONFIG_MAX_NAME + 200);
409 web_buffer_printf(wb, "\n\t# option '%s' is not used.\n", cv->name);
410 }
411 web_buffer_increase(wb, CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 5);
357 - web_buffer_printf(wb, "\t%s%s = %s\n", (!cv->changed && cv->used)?"# ":"", cv->name, cv->value);
412 + web_buffer_printf(wb, "\t%s%s = %s\n", ((!(cv->flags & CONFIG_VALUE_CHANGED)) && (cv->flags & CONFIG_VALUE_USED))?"# ":"", cv->name, cv->value);
413 }
414 }
415 }
src/daemon.c
+1 -1
@@ -39,7 +39,7 @@ void sig_handler(int signo)
39 signal(SIGINT, SIG_IGN);
40 kill_childs();
41 process_childs(0);
42 - rrd_stats_free_all();
42 + rrdset_free_all();
43 //unlink("/var/run/netdata.pid");
44 info("NetData exiting. Bye bye...");
45 exit(1);
src/main.c
+13 -13
@@ -131,7 +131,7 @@ int main(int argc, char **argv)
131 else if(strcmp(argv[i], "--unittest") == 0) {
132 if(unit_test_storage()) exit(1);
133 exit(0);
134 - update_every = 1;
134 + rrd_update_every = 1;
135 if(unit_test(1000000, 0)) exit(1);
136 if(unit_test(1000000, 500000)) exit(1);
137 if(unit_test(1000000, 100000)) exit(1);
@@ -151,7 +151,7 @@ int main(int argc, char **argv)
151 fprintf(stderr, "Cannot understand option '%s'.\n", argv[i]);
152 fprintf(stderr, "\nUSAGE: %s [-d] [-l LINES_TO_SAVE] [-u UPDATE_TIMER] [-p LISTEN_PORT] [-dl debug log file] [-df debug flags].\n\n", argv[0]);
153 fprintf(stderr, " -c CONFIG FILE the configuration file to load. Default: %s.\n", CONFIG_DIR "/" CONFIG_FILENAME);
154 - fprintf(stderr, " -l LINES_TO_SAVE can be from 5 to %d lines in JSON data. Default: %d.\n", HISTORY_MAX, HISTORY);
154 + fprintf(stderr, " -l LINES_TO_SAVE can be from 5 to %d lines in JSON data. Default: %d.\n", RRD_HISTORY_ENTRIES_MAX, RRD_DEFAULT_HISTORY_ENTRIES);
155 fprintf(stderr, " -t UPDATE_TIMER can be from 1 to %d seconds. Default: %d.\n", UPDATE_EVERY_MAX, UPDATE_EVERY);
156 fprintf(stderr, " -p LISTEN_PORT can be from 1 to %d. Default: %d.\n", 65535, LISTEN_PORT);
157 fprintf(stderr, " -u USERNAME can be any system username to run as. Default: none.\n");
@@ -219,7 +219,7 @@ int main(int argc, char **argv)
219
220 // --------------------------------------------------------------------
221
222 - memory_mode = memory_mode_id(config_get("global", "memory mode", memory_mode_name(memory_mode)));
222 + rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(rrd_memory_mode)));
223
224 // --------------------------------------------------------------------
225
@@ -230,23 +230,23 @@ int main(int argc, char **argv)
230
231 // --------------------------------------------------------------------
232
233 - save_history = config_get_number("global", "history", HISTORY);
234 - if(save_history < 5 || save_history > HISTORY_MAX) {
235 - fprintf(stderr, "Invalid save lines %d given. Defaulting to %d.\n", save_history, HISTORY);
236 - save_history = HISTORY;
233 + rrd_default_history_entries = config_get_number("global", "history", RRD_DEFAULT_HISTORY_ENTRIES);
234 + if(rrd_default_history_entries < 5 || rrd_default_history_entries > RRD_HISTORY_ENTRIES_MAX) {
235 + fprintf(stderr, "Invalid save lines %d given. Defaulting to %d.\n", rrd_default_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
236 + rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
237 }
238 else {
239 - debug(D_OPTIONS, "save lines set to %d.", save_history);
239 + debug(D_OPTIONS, "save lines set to %d.", rrd_default_history_entries);
240 }
241
242 // --------------------------------------------------------------------
243
244 - update_every = config_get_number("global", "update every", UPDATE_EVERY);
245 - if(update_every < 1 || update_every > 600) {
246 - fprintf(stderr, "Invalid update timer %d given. Defaulting to %d.\n", update_every, UPDATE_EVERY_MAX);
247 - update_every = UPDATE_EVERY;
244 + rrd_update_every = config_get_number("global", "update every", UPDATE_EVERY);
245 + if(rrd_update_every < 1 || rrd_update_every > 600) {
246 + fprintf(stderr, "Invalid update timer %d given. Defaulting to %d.\n", rrd_update_every, UPDATE_EVERY_MAX);
247 + rrd_update_every = UPDATE_EVERY;
248 }
249 - else debug(D_OPTIONS, "update timer set to %d.", update_every);
249 + else debug(D_OPTIONS, "update timer set to %d.", rrd_update_every);
250
251 // --------------------------------------------------------------------
252
src/plugin_checks.c
+28 -28
@@ -20,23 +20,23 @@ void *checks_main(void *ptr)
20 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
21 error("Cannot set pthread cancel state to ENABLE.");
22
23 - unsigned long long usec = 0, susec = update_every * 1000000ULL, loop_usec = 0, total_susec = 0;
23 + unsigned long long usec = 0, susec = rrd_update_every * 1000000ULL, loop_usec = 0, total_susec = 0;
24 struct timeval now, last, loop;
25
26 - RRD_STATS *check1, *check2, *check3, *apps_cpu = NULL;
26 + RRDSET *check1, *check2, *check3, *apps_cpu = NULL;
27
28 - check1 = rrd_stats_create("netdata", "check1", NULL, "netdata", "Caller gives microseconds", "a million !", 99999, update_every, CHART_TYPE_LINE);
29 - rrd_stats_dimension_add(check1, "absolute", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
30 - rrd_stats_dimension_add(check1, "incremental", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
28 + check1 = rrdset_create("netdata", "check1", NULL, "netdata", "Caller gives microseconds", "a million !", 99999, rrd_update_every, RRDSET_TYPE_LINE);
29 + rrddim_add(check1, "absolute", NULL, -1, 1, RRDDIM_ABSOLUTE);
30 + rrddim_add(check1, "incremental", NULL, 1, 1 * rrd_update_every, RRDDIM_INCREMENTAL);
31
32 - check2 = rrd_stats_create("netdata", "check2", NULL, "netdata", "Netdata calcs microseconds", "a million !", 99999, update_every, CHART_TYPE_LINE);
33 - rrd_stats_dimension_add(check2, "absolute", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
34 - rrd_stats_dimension_add(check2, "incremental", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
32 + check2 = rrdset_create("netdata", "check2", NULL, "netdata", "Netdata calcs microseconds", "a million !", 99999, rrd_update_every, RRDSET_TYPE_LINE);
33 + rrddim_add(check2, "absolute", NULL, -1, 1, RRDDIM_ABSOLUTE);
34 + rrddim_add(check2, "incremental", NULL, 1, 1 * rrd_update_every, RRDDIM_INCREMENTAL);
35
36 - check3 = rrd_stats_create("netdata", "checkdt", NULL, "netdata", "Clock difference", "microseconds diff", 99999, update_every, CHART_TYPE_LINE);
37 - rrd_stats_dimension_add(check3, "caller", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
38 - rrd_stats_dimension_add(check3, "netdata", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
39 - rrd_stats_dimension_add(check3, "apps.plugin", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
36 + check3 = rrdset_create("netdata", "checkdt", NULL, "netdata", "Clock difference", "microseconds diff", 99999, rrd_update_every, RRDSET_TYPE_LINE);
37 + rrddim_add(check3, "caller", NULL, 1, 1, RRDDIM_ABSOLUTE);
38 + rrddim_add(check3, "netdata", NULL, 1, 1, RRDDIM_ABSOLUTE);
39 + rrddim_add(check3, "apps.plugin", NULL, 1, 1, RRDDIM_ABSOLUTE);
40
41 gettimeofday(&last, NULL);
42 while(1) {
@@ -48,8 +48,8 @@ void *checks_main(void *ptr)
48 usec = loop_usec - susec;
49 debug(D_PROCNETDEV_LOOP, "CHECK: last loop took %llu usec (worked for %llu, sleeped for %llu).", loop_usec, usec, susec);
50
51 - if(usec < (update_every * 1000000ULL / 2ULL)) susec = (update_every * 1000000ULL) - usec;
52 - else susec = update_every * 1000000ULL / 2ULL;
51 + if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
52 + else susec = rrd_update_every * 1000000ULL / 2ULL;
53
54 // --------------------------------------------------------------------
55 // Calculate loop time
@@ -61,29 +61,29 @@ void *checks_main(void *ptr)
61 // --------------------------------------------------------------------
62 // check chart 1
63
64 - if(check1->counter_done) rrd_stats_next_usec(check1, loop_usec);
65 - rrd_stats_dimension_set(check1, "absolute", 1000000);
66 - rrd_stats_dimension_set(check1, "incremental", total_susec);
67 - rrd_stats_done(check1);
64 + if(check1->counter_done) rrdset_next_usec(check1, loop_usec);
65 + rrddim_set(check1, "absolute", 1000000);
66 + rrddim_set(check1, "incremental", total_susec);
67 + rrdset_done(check1);
68
69 // --------------------------------------------------------------------
70 // check chart 2
71
72 - if(check2->counter_done) rrd_stats_next(check2);
73 - rrd_stats_dimension_set(check2, "absolute", 1000000);
74 - rrd_stats_dimension_set(check2, "incremental", total_susec);
75 - rrd_stats_done(check2);
72 + if(check2->counter_done) rrdset_next(check2);
73 + rrddim_set(check2, "absolute", 1000000);
74 + rrddim_set(check2, "incremental", total_susec);
75 + rrdset_done(check2);
76
77 // --------------------------------------------------------------------
78 // check chart 3
79
80 - if(!apps_cpu) apps_cpu = rrd_stats_find("apps.cpu");
81 - if(check3->counter_done) rrd_stats_next_usec(check3, loop_usec);
80 + if(!apps_cpu) apps_cpu = rrdset_find("apps.cpu");
81 + if(check3->counter_done) rrdset_next_usec(check3, loop_usec);
82 gettimeofday(&loop, NULL);
83 - rrd_stats_dimension_set(check3, "caller", (long long)usecdiff(&loop, &check1->last_collected_time));
84 - rrd_stats_dimension_set(check3, "netdata", (long long)usecdiff(&loop, &check2->last_collected_time));
85 - if(apps_cpu) rrd_stats_dimension_set(check3, "apps.plugin", (long long)usecdiff(&loop, &apps_cpu->last_collected_time));
86 - rrd_stats_done(check3);
83 + rrddim_set(check3, "caller", (long long)usecdiff(&loop, &check1->last_collected_time));
84 + rrddim_set(check3, "netdata", (long long)usecdiff(&loop, &check2->last_collected_time));
85 + if(apps_cpu) rrddim_set(check3, "apps.plugin", (long long)usecdiff(&loop, &apps_cpu->last_collected_time));
86 + rrdset_done(check3);
87 }
88
89 return NULL;
src/plugin_idlejitter.c
+7 -7
@@ -29,10 +29,10 @@ void *cpuidlejitter_main(void *ptr)
29 sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS;
30 }
31
32 - RRD_STATS *st = rrd_stats_find("system.idlejitter");
32 + RRDSET *st = rrdset_find("system.idlejitter");
33 if(!st) {
34 - st = rrd_stats_create("system", "idlejitter", NULL, "cpu", "CPU Idle Jitter", "microseconds lost/s", 9999, update_every, CHART_TYPE_LINE);
35 - rrd_stats_dimension_add(st, "jitter", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
34 + st = rrdset_create("system", "idlejitter", NULL, "cpu", "CPU Idle Jitter", "microseconds lost/s", 9999, rrd_update_every, RRDSET_TYPE_LINE);
35 + rrddim_add(st, "jitter", NULL, 1, 1, RRDDIM_ABSOLUTE);
36 }
37
38 struct timeval before, after;
@@ -40,7 +40,7 @@ void *cpuidlejitter_main(void *ptr)
40 for(counter = 0; 1 ;counter++) {
41 unsigned long long usec = 0, susec = 0;
42
43 - while(susec < (update_every * 1000000ULL)) {
43 + while(susec < (rrd_update_every * 1000000ULL)) {
44
45 gettimeofday(&before, NULL);
46 usleep(sleep_ms * 1000);
@@ -52,9 +52,9 @@ void *cpuidlejitter_main(void *ptr)
52 }
53 usec -= (sleep_ms * 1000);
54
55 - if(counter) rrd_stats_next_usec(st, susec);
56 - rrd_stats_dimension_set(st, "jitter", usec);
57 - rrd_stats_done(st);
55 + if(counter) rrdset_next_usec(st, susec);
56 + rrddim_set(st, "jitter", usec);
57 + rrdset_done(st);
58 }
59
60 return NULL;
src/plugin_nfacct.c
+19 -19
@@ -106,7 +106,7 @@ void *nfacct_main(void *ptr) {
106
107 struct timeval last, now;
108 unsigned long long usec = 0, susec = 0;
109 - RRD_STATS *st = NULL;
109 + RRDSET *st = NULL;
110
111 gettimeofday(&last, NULL);
112
@@ -145,8 +145,8 @@ void *nfacct_main(void *ptr) {
145 usec = usecdiff(&now, &last) - susec;
146 debug(D_NFACCT_LOOP, "nfacct.plugin: last loop took %llu usec (worked for %llu, sleeped for %llu).", usec + susec, usec, susec);
147
148 - if(usec < (update_every * 1000000ULL / 2ULL)) susec = (update_every * 1000000ULL) - usec;
149 - else susec = update_every * 1000000ULL / 2ULL;
148 + if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
149 + else susec = rrd_update_every * 1000000ULL / 2ULL;
150
151
152 // --------------------------------------------------------------------
@@ -154,43 +154,43 @@ void *nfacct_main(void *ptr) {
154 if(nfacct_list && nfacct_list->len) {
155 int i;
156
157 - st = rrd_stats_find_bytype("nfacct", "packets");
157 + st = rrdset_find_bytype("nfacct", "packets");
158 if(!st) {
159 - st = rrd_stats_create("nfacct", "packets", NULL, "netfilter", "Netfilter Accounting Packets", "packets/s", 1006, update_every, CHART_TYPE_STACKED);
159 + st = rrdset_create("nfacct", "packets", NULL, "netfilter", "Netfilter Accounting Packets", "packets/s", 1006, rrd_update_every, RRDSET_TYPE_STACKED);
160
161 for(i = 0; i < nfacct_list->len ; i++)
162 - rrd_stats_dimension_add(st, nfacct_list->data[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
162 + rrddim_add(st, nfacct_list->data[i].name, NULL, 1, rrd_update_every, RRDDIM_INCREMENTAL);
163 }
164 - else rrd_stats_next(st);
164 + else rrdset_next(st);
165
166 for(i = 0; i < nfacct_list->len ; i++) {
167 - RRD_DIMENSION *rd = rrd_stats_dimension_find(st, nfacct_list->data[i].name);
167 + RRDDIM *rd = rrddim_find(st, nfacct_list->data[i].name);
168
169 - if(!rd) rd = rrd_stats_dimension_add(st, nfacct_list->data[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
170 - if(rd) rrd_stats_dimension_set_by_pointer(st, rd, nfacct_list->data[i].pkts);
169 + if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, rrd_update_every, RRDDIM_INCREMENTAL);
170 + if(rd) rrddim_set_by_pointer(st, rd, nfacct_list->data[i].pkts);
171 }
172
173 - rrd_stats_done(st);
173 + rrdset_done(st);
174
175 // ----------------------------------------------------------------
176
177 - st = rrd_stats_find_bytype("nfacct", "bytes");
177 + st = rrdset_find_bytype("nfacct", "bytes");
178 if(!st) {
179 - st = rrd_stats_create("nfacct", "bytes", NULL, "netfilter", "Netfilter Accounting Bandwidth", "kilobytes/s", 1007, update_every, CHART_TYPE_STACKED);
179 + st = rrdset_create("nfacct", "bytes", NULL, "netfilter", "Netfilter Accounting Bandwidth", "kilobytes/s", 1007, rrd_update_every, RRDSET_TYPE_STACKED);
180
181 for(i = 0; i < nfacct_list->len ; i++)
182 - rrd_stats_dimension_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
182 + rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
183 }
184 - else rrd_stats_next(st);
184 + else rrdset_next(st);
185
186 for(i = 0; i < nfacct_list->len ; i++) {
187 - RRD_DIMENSION *rd = rrd_stats_dimension_find(st, nfacct_list->data[i].name);
187 + RRDDIM *rd = rrddim_find(st, nfacct_list->data[i].name);
188
189 - if(!rd) rd = rrd_stats_dimension_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
190 - if(rd) rrd_stats_dimension_set_by_pointer(st, rd, nfacct_list->data[i].bytes);
189 + if(!rd) rd = rrddim_add(st, nfacct_list->data[i].name, NULL, 1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
190 + if(rd) rrddim_set_by_pointer(st, rd, nfacct_list->data[i].bytes);
191 }
192
193 - rrd_stats_done(st);
193 + rrdset_done(st);
194 }
195
196 // --------------------------------------------------------------------
src/plugin_proc.c
+42 -42
@@ -25,7 +25,7 @@ void *proc_main(void *ptr)
25 struct timeval last, now;
26
27 gettimeofday(&last, NULL);
28 - last.tv_sec -= update_every;
28 + last.tv_sec -= rrd_update_every;
29
30 // disable (by default) various interface that are not needed
31 config_get_boolean("plugin:proc:/proc/net/dev", "interface lo", 0);
@@ -44,7 +44,7 @@ void *proc_main(void *ptr)
44 int vdo_proc_net_rpc_nfsd = !config_get_boolean("plugin:proc", "/proc/net/rpc/nfsd", 1);
45 int vdo_cpu_netdata = !config_get_boolean("plugin:proc", "netdata server resources", 1);
46
47 - RRD_STATS *stcpu = NULL, *stclients = NULL, *streqs = NULL, *stbytes = NULL;
47 + RRDSET *stcpu = NULL, *stclients = NULL, *streqs = NULL, *stbytes = NULL;
48
49 gettimeofday(&last, NULL);
50 getrusage(RUSAGE_SELF, &me_last);
@@ -56,50 +56,50 @@ void *proc_main(void *ptr)
56
57 if(!vdo_proc_net_dev) {
58 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_net_dev().");
59 - vdo_proc_net_dev = do_proc_net_dev(update_every, usec+susec);
59 + vdo_proc_net_dev = do_proc_net_dev(rrd_update_every, usec+susec);
60 }
61 if(!vdo_proc_diskstats) {
62 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_diskstats().");
63 - vdo_proc_diskstats = do_proc_diskstats(update_every, usec+susec);
63 + vdo_proc_diskstats = do_proc_diskstats(rrd_update_every, usec+susec);
64 }
65 if(!vdo_proc_net_snmp) {
66 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_net_snmp().");
67 - vdo_proc_net_snmp = do_proc_net_snmp(update_every, usec+susec);
67 + vdo_proc_net_snmp = do_proc_net_snmp(rrd_update_every, usec+susec);
68 }
69
70 if(!vdo_proc_net_netstat) {
71 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_net_netstat().");
72 - vdo_proc_net_netstat = do_proc_net_netstat(update_every, usec+susec);
72 + vdo_proc_net_netstat = do_proc_net_netstat(rrd_update_every, usec+susec);
73 }
74
75 if(!vdo_proc_net_stat_conntrack) {
76 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_net_stat_conntrack().");
77 - vdo_proc_net_stat_conntrack = do_proc_net_stat_conntrack(update_every, usec+susec);
77 + vdo_proc_net_stat_conntrack = do_proc_net_stat_conntrack(rrd_update_every, usec+susec);
78 }
79
80 if(!vdo_proc_net_ip_vs_stats) {
81 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling vdo_proc_net_ip_vs_stats().");
82 - vdo_proc_net_ip_vs_stats = do_proc_net_ip_vs_stats(update_every, usec+susec);
82 + vdo_proc_net_ip_vs_stats = do_proc_net_ip_vs_stats(rrd_update_every, usec+susec);
83 }
84
85 if(!vdo_proc_stat) {
86 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_stat().");
87 - vdo_proc_stat = do_proc_stat(update_every, usec+susec);
87 + vdo_proc_stat = do_proc_stat(rrd_update_every, usec+susec);
88 }
89
90 if(!vdo_proc_meminfo) {
91 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling vdo_proc_meminfo().");
92 - vdo_proc_meminfo = do_proc_meminfo(update_every, usec+susec);
92 + vdo_proc_meminfo = do_proc_meminfo(rrd_update_every, usec+susec);
93 }
94
95 if(!vdo_proc_vmstat) {
96 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling vdo_proc_vmstat().");
97 - vdo_proc_vmstat = do_proc_vmstat(update_every, usec+susec);
97 + vdo_proc_vmstat = do_proc_vmstat(rrd_update_every, usec+susec);
98 }
99
100 if(!vdo_proc_net_rpc_nfsd) {
101 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_proc_net_rpc_nfsd().");
102 - vdo_proc_net_rpc_nfsd = do_proc_net_rpc_nfsd(update_every, usec+susec);
102 + vdo_proc_net_rpc_nfsd = do_proc_net_rpc_nfsd(rrd_update_every, usec+susec);
103 }
104
105 // END -- the job is done
@@ -109,8 +109,8 @@ void *proc_main(void *ptr)
109 usec = usecdiff(&now, &last) - susec;
110 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: last loop took %llu usec (worked for %llu, sleeped for %llu).", usec + susec, usec, susec);
111
112 - if(usec < (update_every * 1000000ULL / 2ULL)) susec = (update_every * 1000000ULL) - usec;
113 - else susec = update_every * 1000000ULL / 2ULL;
112 + if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
113 + else susec = rrd_update_every * 1000000ULL / 2ULL;
114
115 // --------------------------------------------------------------------
116
@@ -119,61 +119,61 @@ void *proc_main(void *ptr)
119 unsigned long long cpuuser = me.ru_utime.tv_sec * 1000000ULL + me.ru_utime.tv_usec;
120 unsigned long long cpusyst = me.ru_stime.tv_sec * 1000000ULL + me.ru_stime.tv_usec;
121
122 - if(!stcpu) stcpu = rrd_stats_find("netdata.server_cpu");
122 + if(!stcpu) stcpu = rrdset_find("netdata.server_cpu");
123 if(!stcpu) {
124 - stcpu = rrd_stats_create("netdata", "server_cpu", NULL, "netdata", "NetData CPU usage", "milliseconds/s", 9999, update_every, CHART_TYPE_STACKED);
124 + stcpu = rrdset_create("netdata", "server_cpu", NULL, "netdata", "NetData CPU usage", "milliseconds/s", 9999, rrd_update_every, RRDSET_TYPE_STACKED);
125
126 - rrd_stats_dimension_add(stcpu, "user", NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
127 - rrd_stats_dimension_add(stcpu, "system", NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
126 + rrddim_add(stcpu, "user", NULL, 1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
127 + rrddim_add(stcpu, "system", NULL, 1, 1000 * rrd_update_every, RRDDIM_INCREMENTAL);
128 }
129 - else rrd_stats_next(stcpu);
129 + else rrdset_next(stcpu);
130
131 - rrd_stats_dimension_set(stcpu, "user", cpuuser);
132 - rrd_stats_dimension_set(stcpu, "system", cpusyst);
133 - rrd_stats_done(stcpu);
131 + rrddim_set(stcpu, "user", cpuuser);
132 + rrddim_set(stcpu, "system", cpusyst);
133 + rrdset_done(stcpu);
134
135 bcopy(&me, &me_last, sizeof(struct rusage));
136
137 // ----------------------------------------------------------------
138
139 - if(!stclients) stclients = rrd_stats_find("netdata.clients");
139 + if(!stclients) stclients = rrdset_find("netdata.clients");
140 if(!stclients) {
141 - stclients = rrd_stats_create("netdata", "clients", NULL, "netdata", "NetData Web Clients", "connected clients", 11000, update_every, CHART_TYPE_LINE);
141 + stclients = rrdset_create("netdata", "clients", NULL, "netdata", "NetData Web Clients", "connected clients", 11000, rrd_update_every, RRDSET_TYPE_LINE);
142
143 - rrd_stats_dimension_add(stclients, "clients", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
143 + rrddim_add(stclients, "clients", NULL, 1, 1, RRDDIM_ABSOLUTE);
144 }
145 - else rrd_stats_next(stclients);
145 + else rrdset_next(stclients);
146
147 - rrd_stats_dimension_set(stclients, "clients", global_statistics.connected_clients);
148 - rrd_stats_done(stclients);
147 + rrddim_set(stclients, "clients", global_statistics.connected_clients);
148 + rrdset_done(stclients);
149
150 // ----------------------------------------------------------------
151
152 - if(!streqs) streqs = rrd_stats_find("netdata.requests");
152 + if(!streqs) streqs = rrdset_find("netdata.requests");
153 if(!streqs) {
154 - streqs = rrd_stats_create("netdata", "requests", NULL, "netdata", "NetData Web Requests", "requests/s", 12000, update_every, CHART_TYPE_LINE);
154 + streqs = rrdset_create("netdata", "requests", NULL, "netdata", "NetData Web Requests", "requests/s", 12000, rrd_update_every, RRDSET_TYPE_LINE);
155
156 - rrd_stats_dimension_add(streqs, "requests", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
156 + rrddim_add(streqs, "requests", NULL, 1, 1 * rrd_update_every, RRDDIM_INCREMENTAL);
157 }
158 - else rrd_stats_next(streqs);
158 + else rrdset_next(streqs);
159
160 - rrd_stats_dimension_set(streqs, "requests", global_statistics.web_requests);
161 - rrd_stats_done(streqs);
160 + rrddim_set(streqs, "requests", global_statistics.web_requests);
161 + rrdset_done(streqs);
162
163 // ----------------------------------------------------------------
164
165 - if(!stbytes) stbytes = rrd_stats_find("netdata.net");
165 + if(!stbytes) stbytes = rrdset_find("netdata.net");
166 if(!stbytes) {
167 - stbytes = rrd_stats_create("netdata", "net", NULL, "netdata", "NetData Network Traffic", "kilobits/s", 13000, update_every, CHART_TYPE_AREA);
167 + stbytes = rrdset_create("netdata", "net", NULL, "netdata", "NetData Network Traffic", "kilobits/s", 13000, rrd_update_every, RRDSET_TYPE_AREA);
168
169 - rrd_stats_dimension_add(stbytes, "in", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
170 - rrd_stats_dimension_add(stbytes, "out", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
169 + rrddim_add(stbytes, "in", NULL, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
170 + rrddim_add(stbytes, "out", NULL, -8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
171 }
172 - else rrd_stats_next(stbytes);
172 + else rrdset_next(stbytes);
173
174 - rrd_stats_dimension_set(stbytes, "in", global_statistics.bytes_received);
175 - rrd_stats_dimension_set(stbytes, "out", global_statistics.bytes_sent);
176 - rrd_stats_done(stbytes);
174 + rrddim_set(stbytes, "in", global_statistics.bytes_received);
175 + rrddim_set(stbytes, "out", global_statistics.bytes_sent);
176 + rrdset_done(stbytes);
177 }
178
179 usleep(susec);
src/plugin_tc.c
+27 -27
@@ -19,11 +19,11 @@
19 #define TC_LINE_MAX 1024
20
21 struct tc_class {
22 - char id[RRD_STATS_NAME_MAX + 1];
23 - char name[RRD_STATS_NAME_MAX + 1];
22 + char id[RRD_ID_LENGTH_MAX + 1];
23 + char name[RRD_ID_LENGTH_MAX + 1];
24
25 - char leafid[RRD_STATS_NAME_MAX + 1];
26 - char parentid[RRD_STATS_NAME_MAX + 1];
25 + char leafid[RRD_ID_LENGTH_MAX + 1];
26 + char parentid[RRD_ID_LENGTH_MAX + 1];
27
28 int hasparent;
29 int isleaf;
@@ -33,9 +33,9 @@ struct tc_class {
33 };
34
35 struct tc_device {
36 - char id[RRD_STATS_NAME_MAX + 1];
37 - char name[RRD_STATS_NAME_MAX + 1];
38 - char family[RRD_STATS_NAME_MAX + 1];
36 + char id[RRD_ID_LENGTH_MAX + 1];
37 + char name[RRD_ID_LENGTH_MAX + 1];
38 + char family[RRD_ID_LENGTH_MAX + 1];
39
40 struct tc_class *classes;
41 };
@@ -81,43 +81,43 @@ void tc_device_commit(struct tc_device *d)
81 char var_name[4096 + 1];
82 snprintf(var_name, 4096, "qos for %s", d->id);
83 if(config_get_boolean("plugin:tc", var_name, enable_new_interfaces)) {
84 - RRD_STATS *st = rrd_stats_find_bytype(RRD_TYPE_TC, d->id);
84 + RRDSET *st = rrdset_find_bytype(RRD_TYPE_TC, d->id);
85 if(!st) {
86 debug(D_TC_LOOP, "TC: Committing new TC device '%s'", d->name);
87
88 - st = rrd_stats_create(RRD_TYPE_TC, d->id, d->name, d->family, "Class Usage", "kilobits/s", 1000, update_every, CHART_TYPE_STACKED);
88 + st = rrdset_create(RRD_TYPE_TC, d->id, d->name, d->family, "Class Usage", "kilobits/s", 1000, rrd_update_every, RRDSET_TYPE_STACKED);
89
90 for ( c = d->classes ; c ; c = c->next) {
91 if(c->isleaf && c->hasparent)
92 - rrd_stats_dimension_add(st, c->id, c->name, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
92 + rrddim_add(st, c->id, c->name, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
93 }
94 }
95 else {
96 - rrd_stats_next_plugins(st);
96 + rrdset_next_plugins(st);
97
98 - if(strcmp(d->id, d->name) != 0) rrd_stats_set_name(st, d->name);
98 + if(strcmp(d->id, d->name) != 0) rrdset_set_name(st, d->name);
99 }
100
101 for ( c = d->classes ; c ; c = c->next) {
102 if(c->isleaf && c->hasparent) {
103 - if(rrd_stats_dimension_set(st, c->id, c->bytes) != 0) {
103 + if(rrddim_set(st, c->id, c->bytes) != 0) {
104
105 // new class, we have to add it
106 - rrd_stats_dimension_add(st, c->id, c->name, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
107 - rrd_stats_dimension_set(st, c->id, c->bytes);
106 + rrddim_add(st, c->id, c->name, 8, 1024 * rrd_update_every, RRDDIM_INCREMENTAL);
107 + rrddim_set(st, c->id, c->bytes);
108 }
109
110 // if it has a name, different to the id
111 if(strcmp(c->id, c->name) != 0) {
112 // update the rrd dimension with the new name
113 - RRD_DIMENSION *rd;
113 + RRDDIM *rd;
114 for(rd = st->dimensions ; rd ; rd = rd->next) {
115 - if(strcmp(rd->id, c->id) == 0) { rrd_stats_dimension_set_name(st, rd, c->name); break; }
115 + if(strcmp(rd->id, c->id) == 0) { rrddim_set_name(st, rd, c->name); break; }
116 }
117 }
118 }
119 }
120 - rrd_stats_done(st);
120 + rrdset_done(st);
121 }
122 }
123
@@ -126,7 +126,7 @@ void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
126 struct tc_class *c;
127 for ( c = d->classes ; c ; c = c->next) {
128 if(strcmp(c->id, id) == 0) {
129 - strncpy(c->name, name, RRD_STATS_NAME_MAX);
129 + strncpy(c->name, name, RRD_ID_LENGTH_MAX);
130 // no need for null termination - it is already null
131 break;
132 }
@@ -135,13 +135,13 @@ void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
135
136 void tc_device_set_device_name(struct tc_device *d, char *name)
137 {
138 - strncpy(d->name, name, RRD_STATS_NAME_MAX);
138 + strncpy(d->name, name, RRD_ID_LENGTH_MAX);
139 // no need for null termination - it is already null
140 }
141
142 void tc_device_set_device_family(struct tc_device *d, char *name)
143 {
144 - strncpy(d->family, name, RRD_STATS_NAME_MAX);
144 + strncpy(d->family, name, RRD_ID_LENGTH_MAX);
145 // no need for null termination - it is already null
146 }
147
@@ -155,7 +155,7 @@ struct tc_device *tc_device_create(char *name)
155 return NULL;
156 }
157
158 - strncpy(d->id, name, RRD_STATS_NAME_MAX);
158 + strncpy(d->id, name, RRD_ID_LENGTH_MAX);
159 strcpy(d->name, d->id);
160 strcpy(d->family, d->id);
161
@@ -177,10 +177,10 @@ struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, cha
177 c->next = n->classes;
178 n->classes = c;
179
180 - strncpy(c->id, id, RRD_STATS_NAME_MAX);
180 + strncpy(c->id, id, RRD_ID_LENGTH_MAX);
181 strcpy(c->name, c->id);
182 - if(parentid) strncpy(c->parentid, parentid, RRD_STATS_NAME_MAX);
183 - if(leafid) strncpy(c->leafid, leafid, RRD_STATS_NAME_MAX);
182 + if(parentid) strncpy(c->parentid, parentid, RRD_ID_LENGTH_MAX);
183 + if(leafid) strncpy(c->leafid, leafid, RRD_ID_LENGTH_MAX);
184
185 // no need for null termination on the strings, because of calloc()
186
@@ -217,7 +217,7 @@ void *tc_main(void *ptr)
217 struct tc_device *device = NULL;
218 struct tc_class *class = NULL;
219
220 - snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", PLUGINS_DIR "/tc-qos-helper.sh"), update_every);
220 + snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", PLUGINS_DIR "/tc-qos-helper.sh"), rrd_update_every);
221 debug(D_TC_LOOP, "executing '%s'", buffer);
222 // fp = popen(buffer, "r");
223 fp = mypopen(buffer, &tc_child_pid);
@@ -331,7 +331,7 @@ void *tc_main(void *ptr)
331 class = NULL;
332 }
333
334 - sleep(update_every);
334 + sleep(rrd_update_every);
335 }
336
337 return NULL;
src/plugins.d/Makefile
+8 -6
@@ -1,5 +1,5 @@
1 ifndef BIN_DIR
2 -BIN_DIR = "$(PWD)"
2 +BIN_DIR = "."
3 endif
4
5 ifndef CONFIG_DIR
@@ -16,13 +16,16 @@ endif
16
17 COMMON_FLAGS = BIN_DIR='$(BIN_DIR)' CONFIG_DIR='$(CONFIG_DIR)' LOG_DIR='$(LOG_DIR)' PLUGINS_DIR='$(PLUGINS_DIR)'
18
19 -CC = gcc
19 +CC := gcc
20 +libs :=
21
22 ifdef debug
23 COMMON_FLAGS += debug=1
23 -CFLAGS = -Wall -Wextra -ggdb -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)'
24 +# CFLAGS = -Wall -Wextra -ggdb -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fsanitize=address -fno-omit-frame-pointer
25 +CFLAGS := -Wall -Wextra -O -g -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fsanitize=address -fno-omit-frame-pointer
26 +#libs += -ltsan -lpie
27 else
25 -CFLAGS = -Wall -Wextra -O3 -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)'
28 +CFLAGS := -Wall -Wextra -O3 -DBIN_DIR='$(BIN_DIR)' -DCONFIG_DIR='$(CONFIG_DIR)' -DLOG_DIR='$(LOG_DIR)' -DPLUGINS_DIR='$(PLUGINS_DIR)' -fomit-frame-pointer
29 endif
30
31 all: options plugins
@@ -33,8 +36,7 @@ options:
36 plugins: apps.plugin
37
38 apps.plugin: apps_plugin.c
36 - @echo " $(CC) $@"
37 - @$(CC) $(CFLAGS) -o $@ apps_plugin.c
39 + $(CC) $(CFLAGS) -o $@ apps_plugin.c ../avl.o ../common.o ../log.o ../procfile.o $(libs)
40
41 clean:
42 -rm -f *.o apps.plugin core
src/plugins.d/apps_plugin.c
+193 -137
@@ -24,6 +24,11 @@
24 #include <dirent.h>
25 #include <arpa/inet.h>
26
27 +#include "../common.h"
28 +#include "../log.h"
29 +#include "../avl.h"
30 +#include "../procfile.h"
31 +
32 #define MAX_COMPARE_NAME 15
33 #define MAX_NAME 100
34
@@ -42,66 +47,47 @@ unsigned long long file_counter = 0;
47 // ----------------------------------------------------------------------------
48 // helper functions
49
45 -unsigned long long usecdiff(struct timeval *now, struct timeval *last) {
46 - return ((((now->tv_sec * 1000000ULL) + now->tv_usec) - ((last->tv_sec * 1000000ULL) + last->tv_usec)));
47 -}
48 -
49 -char *trim(char *s)
50 -{
51 - // skip leading spaces
52 - while(*s && isspace(*s)) s++;
53 - if(!*s) return NULL;
54 -
55 - // skip tailing spaces
56 - int c = strlen(s) - 1;
57 - while(c >= 0 && isspace(s[c])) {
58 - s[c] = '\0';
59 - c--;
60 - }
61 - if(c < 0) return NULL;
62 - if(!*s) return NULL;
63 - return s;
64 -}
65 -
66 -unsigned long simple_hash(const char *name)
67 -{
68 - int i, len = strlen(name);
69 - unsigned long hash = 0;
70 -
71 - for(i = 0; i < len ;i++) hash += (i * name[i]) + i + name[i];
50 +long get_processors(void) {
51 + int processors = 0;
52
73 - return hash;
74 -}
53 + procfile *ff = procfile_open("/proc/stat", O_RDONLY);
54 + if(!ff) return 1;
55
76 -long get_processors(void)
77 -{
78 - char buffer[1025], *s;
79 - int processors = 0;
56 + ff = procfile_readall(ff);
57 + if(!ff) {
58 + procfile_close(ff);
59 + return 1;
60 + }
61
81 - FILE *fp = fopen("/proc/stat", "r");
82 - if(!fp) return 1;
62 + unsigned int i;
63 + for(i = 0; i < procfile_lines(ff); i++) {
64 + if(!procfile_linewords(ff, i)) continue;
65
84 - while((s = fgets(buffer, 1024, fp))) {
85 - if(strncmp(buffer, "cpu", 3) == 0) processors++;
66 + if(strncmp(procfile_lineword(ff, i, 0), "cpu", 3) == 0) processors++;
67 }
87 - fclose(fp);
68 processors--;
69 if(processors < 1) processors = 1;
70 +
71 + procfile_close(ff);
72 return processors;
73 }
74
93 -long get_pid_max(void)
94 -{
95 - char buffer[1025], *s;
75 +long get_pid_max(void) {
76 long mpid = 32768;
77
98 - FILE *fp = fopen("/proc/sys/kernel/pid_max", "r");
99 - if(!fp) return 1;
78 + procfile *ff = procfile_open("/proc/sys/kernel/pid_max", O_RDONLY);
79 + if(!ff) return mpid;
80
101 - s = fgets(buffer, 1024, fp);
102 - if(s) mpid = atol(buffer);
103 - fclose(fp);
104 - if(mpid < 32768) mpid = 32768;
81 + ff = procfile_readall(ff);
82 + if(!ff) {
83 + procfile_close(ff);
84 + return mpid;
85 + }
86 +
87 + mpid = atol(procfile_lineword(ff, 0, 0));
88 + if(mpid) mpid = 32768;
89 +
90 + procfile_close(ff);
91 return mpid;
92 }
93
@@ -122,7 +108,7 @@ unsigned long long get_hertz(void)
108 hz = (sizeof(long)==sizeof(int) || htons(999)==999) ? 100UL : 1024UL;
109 #endif
110
125 - fprintf(stderr, "apps.plugin: ERROR: unknown HZ value. Assuming %llu.\n", hz);
111 + error("apps.plugin: ERROR: unknown HZ value. Assuming %llu.", hz);
112 return hz;
113 }
114
@@ -215,7 +201,7 @@ struct target *get_target(const char *id, struct target *target)
201
202 w = calloc(sizeof(struct target), 1);
203 if(!w) {
218 - fprintf(stderr, "apps.plugin: cannot allocate %lu bytes of memory\n", (unsigned long)sizeof(struct target));
204 + error("apps.plugin: cannot allocate %lu bytes of memory", (unsigned long)sizeof(struct target));
205 return NULL;
206 }
207
@@ -245,7 +231,7 @@ int read_process_groups(const char *name)
231 if(debug) fprintf(stderr, "apps.plugin: process groups file: '%s'\n", filename);
232 FILE *fp = fopen(filename, "r");
233 if(!fp) {
248 - fprintf(stderr, "apps.plugin: ERROR: cannot open file '%s' (%s)\n", filename, strerror(errno));
234 + error("apps.plugin: ERROR: cannot open file '%s' (%s)", filename, strerror(errno));
235 return 1;
236 }
237
@@ -306,7 +292,7 @@ int read_process_groups(const char *name)
292 }
293
294 if(w) strncpy(w->name, t, MAX_NAME);
309 - if(!count) fprintf(stderr, "apps.plugin: ERROR: the line %ld on file '%s', for group '%s' does not state any process names.\n", line, filename, t);
295 + if(!count) error("apps.plugin: ERROR: the line %ld on file '%s', for group '%s' does not state any process names.", line, filename, t);
296 }
297 fclose(fp);
298
@@ -429,13 +415,13 @@ struct pid_stat *get_entry(pid_t pid)
415
416 all_pids[pid] = calloc(sizeof(struct pid_stat), 1);
417 if(!all_pids[pid]) {
432 - fprintf(stderr, "apps.plugin: ERROR: Cannot allocate %lu bytes of memory", (unsigned long)sizeof(struct pid_stat));
418 + error("apps.plugin: ERROR: Cannot allocate %lu bytes of memory", (unsigned long)sizeof(struct pid_stat));
419 return NULL;
420 }
421
422 all_pids[pid]->fds = calloc(sizeof(int), 100);
423 if(!all_pids[pid]->fds)
438 - fprintf(stderr, "apps.plugin: ERROR: Cannot allocate %ld bytes of memory\n", (unsigned long)(sizeof(int) * 100));
424 + error("apps.plugin: ERROR: Cannot allocate %ld bytes of memory", (unsigned long)(sizeof(int) * 100));
425 else all_pids[pid]->fds_size = 100;
426
427 if(root) root->prev = all_pids[pid];
@@ -506,16 +492,53 @@ int walk_down(pid_t pid, int level) {
492 // this is used to keep a global list of all open files of the system
493 // it is needed in order to figure out the unique files a process tree has open
494
495 +#define FILE_DESCRIPTORS_INCREASE_STEP 100
496 +
497 struct file_descriptor {
498 + avl avl;
499 + unsigned long magic;
500 unsigned long hash;
511 - char *name;
501 + const char *name;
502 int type;
503 long count;
504 + long pos;
505 } *all_files = NULL;
506
507 int all_files_len = 0;
508 int all_files_size = 0;
509
510 +int file_descriptor_compare(void* a, void* b) {
511 + if(((struct file_descriptor *)a)->magic != 0x0BADCAFE || ((struct file_descriptor *)b)->magic != 0x0BADCAFE)
512 + error("Corrupted index data detected. Please report this.");
513 +
514 + if(((struct file_descriptor *)a)->hash < ((struct file_descriptor *)b)->hash)
515 + return -1;
516 + else if(((struct file_descriptor *)a)->hash > ((struct file_descriptor *)b)->hash)
517 + return 1;
518 + else return strcmp(((struct file_descriptor *)a)->name, ((struct file_descriptor *)b)->name);
519 +}
520 +int file_descriptor_iterator(avl *a) { if(a) {}; return 0; }
521 +
522 +avl_tree all_files_index = {
523 + NULL,
524 + file_descriptor_compare
525 +};
526 +
527 +static struct file_descriptor *file_descriptor_find(const char *name, unsigned long hash) {
528 + struct file_descriptor *result = NULL, tmp;
529 + tmp.hash = (hash)?hash:simple_hash(name);
530 + tmp.name = name;
531 + tmp.count = 0;
532 + tmp.pos = 0;
533 + tmp.magic = 0x0BADCAFE;
534 +
535 + avl_search(&all_files_index, (avl *)&tmp, file_descriptor_iterator, (avl **)&result);
536 + return result;
537 +}
538 +
539 +#define file_descriptor_add(fd) avl_insert(&all_files_index, (avl *)(fd))
540 +#define file_descriptor_remove(fd) avl_remove(&all_files_index, (avl *)(fd))
541 +
542 #define FILETYPE_OTHER 0
543 #define FILETYPE_FILE 1
544 #define FILETYPE_PIPE 2
@@ -528,19 +551,91 @@ int all_files_size = 0;
551
552 void file_descriptor_not_used(int id)
553 {
531 - if(id > 0 && id < all_files_len) {
532 - if(all_files[id].count > 0)
554 + if(id > 0 && id < all_files_size) {
555 + if(all_files[id].magic != 0x0BADCAFE) {
556 + error("Ignoring request to remove empty file id %d.", id);
557 + return;
558 + }
559 +
560 + if(all_files[id].count > 0) {
561 all_files[id].count--;
562 +
563 + if(!all_files[id].count) {
564 + file_descriptor_remove(&all_files[id]);
565 + all_files[id].magic = 0x00000000;
566 + all_files_len--;
567 + }
568 + }
569 else
535 - fprintf(stderr, "apps.plugin: ERROR: request to decrease counter of fd %d (%s), while the use counter is 0\n", id, all_files[id].name);
570 + error("apps.plugin: ERROR: request to decrease counter of fd %d (%s), while the use counter is 0", id, all_files[id].name);
571 }
537 - else fprintf(stderr, "apps.plugin: ERROR: request to decrease counter of fd %d, which is outside the array size (1 to %d)\n", id, all_files_len);
572 + else error("apps.plugin: ERROR: request to decrease counter of fd %d, which is outside the array size (1 to %d)", id, all_files_size);
573 }
574
575 unsigned long file_descriptor_find_or_add(const char *name)
576 {
542 - int type = FILETYPE_OTHER;
577 + static int last_pos = 0;
578 + unsigned long hash = simple_hash(name);
579
580 + if(debug) fprintf(stderr, "apps.plugin: adding or finding name '%s' with hash %lu\n", name, hash);
581 +
582 + struct file_descriptor *fd = file_descriptor_find(name, hash);
583 + if(fd) {
584 + // found
585 + fd->count++;
586 + return fd->pos;
587 + }
588 + // not found
589 +
590 + // check we have enough memory to add it
591 + if(!all_files || all_files_len == all_files_size) {
592 + void *old = all_files;
593 +
594 + // there is no empty slot
595 + if(debug) fprintf(stderr, "apps.plugin: extending fd array to %d entries\n", all_files_size + FILE_DESCRIPTORS_INCREASE_STEP);
596 + all_files = realloc(all_files, (all_files_size + FILE_DESCRIPTORS_INCREASE_STEP) * sizeof(struct file_descriptor));
597 +
598 + // if the address changed, we have to rebuild the index
599 + // since all pointers are now invalid
600 + if(old && old != (void *)all_files) {
601 + if(debug) fprintf(stderr, "apps.plugin: re-indexing.\n");
602 + all_files_index.root = NULL;
603 + int i;
604 + for(i = 0; i < all_files_size; i++) {
605 + if(!all_files[i].count) continue;
606 + file_descriptor_add(&all_files[i]);
607 + }
608 + }
609 +
610 + if(!all_files_size) all_files_len = 1;
611 + all_files_size += FILE_DESCRIPTORS_INCREASE_STEP;
612 + }
613 +
614 + // search for an empty slot
615 + int i, c;
616 + for(i = 0, c = last_pos ; i < all_files_size ; i++, c++) {
617 + if(c >= all_files_size) c = 0;
618 + if(c == 0) continue;
619 +
620 + if(!all_files[c].count) {
621 + if(all_files[c].magic == 0x0BADCAFE && all_files[c].name && file_descriptor_find(all_files[c].name, all_files[c].hash))
622 + error("apps.plugin: fd on position %d is not cleared properly. It still has %s in it.\n", c, all_files[c].name);
623 +
624 + if(debug) fprintf(stderr, "apps.plugin: re-using fd position %d for %s (last name: %s)\n", c, name, all_files[c].name);
625 + if(all_files[c].name) free((void *)all_files[c].name);
626 + all_files[c].name = NULL;
627 + break;
628 + }
629 + }
630 + if(i == all_files_size) {
631 + error("We should find an empty slot, but there isn't any");
632 + return 0;
633 + }
634 + all_files_len++;
635 +
636 + // else we have an empty slot in 'c'
637 +
638 + int type = FILETYPE_OTHER;
639 if(name[0] == '/') type = FILETYPE_FILE;
640 else if(strncmp(name, "pipe:", 5) == 0) type = FILETYPE_PIPE;
641 else if(strncmp(name, "socket:", 7) == 0) type = FILETYPE_SOCKET;
@@ -558,55 +653,14 @@ unsigned long file_descriptor_find_or_add(const char *name)
653 type = FILETYPE_OTHER;
654 }
655
561 - // init
562 - if(!all_files) {
563 - all_files = malloc(1024 * sizeof(struct file_descriptor));
564 - if(!all_files) return 0;
565 -
566 - all_files_size = 1024;
567 - all_files_len = 1; // start from 1, skip 0
568 - if(debug) fprintf(stderr, "apps.plugin: initialized fd array to %d entries\n", all_files_size);
569 - }
570 -
571 - // try to find it
572 - unsigned long hash = simple_hash(name);
573 - int c;
574 - for( c = 0 ; c < all_files_len ; c++) {
575 - if(all_files[c].hash == hash && strcmp(all_files[c].name, name) == 0) break;
576 - }
577 -
578 - // found it
579 - if(c < all_files_len) {
580 - all_files[c].count++;
581 - return c;
582 - }
583 -
584 - // not found, search for an empty slot
585 - for(c = 0 ; c < all_files_len ; c++) {
586 - if(!all_files[c].count) {
587 - if(debug) fprintf(stderr, "apps.plugin: re-using fd position %d (last name: %s)\n", c, all_files[c].name);
588 - if(all_files[c].name) free(all_files[c].name);
589 - break;
590 - }
591 - }
592 -
593 - if(c == all_files_len) {
594 - // not found any emtpty slot
595 - all_files_len++;
596 -
597 - if(c >= all_files_size) {
598 - // not enough memory - extend it
599 - if(debug) fprintf(stderr, "apps.plugin: extending fd array to %d entries\n", all_files_size + 1024);
600 - all_files = realloc(all_files, (all_files_size + 1024) * sizeof(struct file_descriptor));
601 - all_files_size += 1024;
602 - }
603 - }
604 - // else we have the slot in 'c'
605 -
656 all_files[c].name = strdup(name);
657 all_files[c].hash = hash;
658 all_files[c].type = type;
609 - all_files[c].count++;
659 + all_files[c].pos = c;
660 + all_files[c].count = 1;
661 + all_files[c].magic = 0x0BADCAFE;
662 +
663 + file_descriptor_add(&all_files[c]);
664
665 if(debug) fprintf(stderr, "apps.plugin: using fd position %d (name: %s)\n", c, all_files[c].name);
666
@@ -671,7 +725,7 @@ int update_from_proc(void)
725 if(fd == -1) {
726 if(errno != ENOENT && errno != ESRCH) {
727 if(!count_errors++ || debug)
674 - fprintf(stderr, "apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).\n", filename, errno, strerror(errno));
728 + error("apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).", filename, errno, strerror(errno));
729 }
730 continue;
731 }
@@ -682,7 +736,7 @@ int update_from_proc(void)
736
737 if(bytes == -1) {
738 if(!count_errors++ || debug)
685 - fprintf(stderr, "apps.plugin: ERROR: cannot read from file '%s' (%s).\n", filename, strerror(errno));
739 + error("apps.plugin: ERROR: cannot read from file '%s' (%s).", filename, strerror(errno));
740 continue;
741 }
742
@@ -734,7 +788,7 @@ int update_from_proc(void)
788
789 if(parsed < 39) {
790 if(!count_errors++ || debug || (p->target && p->target->debug))
737 - fprintf(stderr, "apps.plugin: ERROR: file %s gave %d results (expected 44)\n", filename, parsed);
791 + error("apps.plugin: ERROR: file %s gave %d results (expected 44)\n", filename, parsed);
792 }
793
794 // check if it is target
@@ -767,7 +821,7 @@ int update_from_proc(void)
821 if(fd == -1) {
822 if(errno != ENOENT && errno != ESRCH) {
823 if(!count_errors++ || debug || (p->target && p->target->debug))
770 - fprintf(stderr, "apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).\n", filename, errno, strerror(errno));
824 + error("apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).", filename, errno, strerror(errno));
825 }
826 }
827 else {
@@ -777,7 +831,7 @@ int update_from_proc(void)
831
832 if(bytes == -1) {
833 if(!count_errors++ || debug || (p->target && p->target->debug))
780 - fprintf(stderr, "apps.plugin: ERROR: cannot read from file '%s' (%s).\n", filename, strerror(errno));
834 + error("apps.plugin: ERROR: cannot read from file '%s' (%s).", filename, strerror(errno));
835 }
836 else if(bytes > 10) {
837 buffer[bytes] = '\0';
@@ -797,7 +851,7 @@ int update_from_proc(void)
851
852 if(parsed < 7) {
853 if(!count_errors++ || debug || (p->target && p->target->debug))
800 - fprintf(stderr, "apps.plugin: ERROR: file %s gave %d results (expected 7)\n", filename, parsed);
854 + error("apps.plugin: ERROR: file %s gave %d results (expected 7)", filename, parsed);
855 }
856 }
857 }
@@ -810,7 +864,7 @@ int update_from_proc(void)
864 if(fd == -1) {
865 if(errno != ENOENT && errno != ESRCH) {
866 if(!count_errors++ || debug || (p->target && p->target->debug))
813 - fprintf(stderr, "apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).\n", filename, errno, strerror(errno));
867 + error("apps.plugin: ERROR: cannot open file '%s' for reading (%d, %s).", filename, errno, strerror(errno));
868 }
869 }
870 else {
@@ -820,7 +874,7 @@ int update_from_proc(void)
874
875 if(bytes == -1) {
876 if(!count_errors++ || debug || (p->target && p->target->debug))
823 - fprintf(stderr, "apps.plugin: ERROR: cannot read from file '%s' (%s).\n", filename, strerror(errno));
877 + error("apps.plugin: ERROR: cannot read from file '%s' (%s).", filename, strerror(errno));
878 }
879 else if(bytes > 10) {
880 buffer[bytes] = '\0';
@@ -839,7 +893,7 @@ int update_from_proc(void)
893
894 if(parsed < 7) {
895 if(!count_errors++ || debug || (p->target && p->target->debug))
842 - fprintf(stderr, "apps.plugin: ERROR: file %s gave %d results (expected 7)\n", filename, parsed);
896 + error("apps.plugin: ERROR: file %s gave %d results (expected 7)", filename, parsed);
897 }
898 }
899 }
@@ -869,7 +923,7 @@ int update_from_proc(void)
923 if(debug) fprintf(stderr, "apps.plugin: extending fd memory slots for %s from %d to %d\n", p->comm, p->fds_size, fdid + 100);
924 p->fds = realloc(p->fds, (fdid + 100) * sizeof(int));
925 if(!p->fds) {
872 - fprintf(stderr, "apps.plugin: ERROR: cannot re-allocate fds for %s\n", p->comm);
926 + error("apps.plugin: ERROR: cannot re-allocate fds for %s", p->comm);
927 break;
928 }
929
@@ -886,7 +940,7 @@ int update_from_proc(void)
940 if(l == -1) {
941 if(debug || (p->target && p->target->debug)) {
942 if(!count_errors++ || debug || (p->target && p->target->debug))
889 - fprintf(stderr, "apps.plugin: ERROR: cannot read link %s\n", fdname);
943 + error("apps.plugin: ERROR: cannot read link %s", fdname);
944 }
945 continue;
946 }
@@ -919,7 +973,7 @@ int update_from_proc(void)
973 p->updated = 1;
974 }
975 if(count_errors > 1000) {
922 - fprintf(stderr, "apps.plugin: ERROR: %ld more errors encountered\n", count_errors - 1);
976 + error("apps.plugin: ERROR: %ld more errors encountered\n", count_errors - 1);
977 count_errors = 0;
978 }
979
@@ -957,7 +1011,7 @@ void update_statistics(void)
1011 p->parent = all_pids[p->ppid];
1012 p->parent->childs++;
1013 }
960 - else if(p->ppid != 0) fprintf(stderr, "apps.plugin: \t\tWRONG! pid %d %s states parent %d, but the later does not exist.\n", p->pid, p->comm, p->ppid);
1014 + else if(p->ppid != 0) error("apps.plugin: \t\tWRONG! pid %d %s states parent %d, but the later does not exist.", p->pid, p->comm, p->ppid);
1015 }
1016
1017 // find all the procs with 0 childs and merge them to their parents
@@ -1025,7 +1079,7 @@ void update_statistics(void)
1079 for(p = root; p ; p = p->next) {
1080 if(p->updated) continue;
1081
1028 - fprintf(stderr, "apps.plugin: UNMERGING %d %s\n", p->pid, p->comm);
1082 + if(debug) fprintf(stderr, "apps.plugin: UNMERGING %d %s\n", p->pid, p->comm);
1083
1084 unsigned long long diff_utime = p->utime + p->cutime + p->fix_cutime;
1085 unsigned long long diff_stime = p->stime + p->cstime + p->fix_cstime;
@@ -1042,35 +1096,35 @@ void update_statistics(void)
1096 diff_utime -= x;
1097 t->diff_cutime -= x;
1098 t->fix_cutime += x;
1045 - fprintf(stderr, "apps.plugin: \t cutime %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1099 + if(debug) fprintf(stderr, "apps.plugin: \t cutime %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1100 }
1101 if(diff_stime && t->diff_cstime) {
1102 x = (t->diff_cstime < diff_stime)?t->diff_cstime:diff_stime;
1103 diff_stime -= x;
1104 t->diff_cstime -= x;
1105 t->fix_cstime += x;
1052 - fprintf(stderr, "apps.plugin: \t cstime %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1106 + if(debug) fprintf(stderr, "apps.plugin: \t cstime %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1107 }
1108 if(diff_minflt && t->diff_cminflt) {
1109 x = (t->diff_cminflt < diff_minflt)?t->diff_cminflt:diff_minflt;
1110 diff_minflt -= x;
1111 t->diff_cminflt -= x;
1112 t->fix_cminflt += x;
1059 - fprintf(stderr, "apps.plugin: \t cminflt %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1113 + if(debug) fprintf(stderr, "apps.plugin: \t cminflt %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1114 }
1115 if(diff_majflt && t->diff_cmajflt) {
1116 x = (t->diff_cmajflt < diff_majflt)?t->diff_cmajflt:diff_majflt;
1117 diff_majflt -= x;
1118 t->diff_cmajflt -= x;
1119 t->fix_cmajflt += x;
1066 - fprintf(stderr, "apps.plugin: \t cmajflt %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1120 + if(debug) fprintf(stderr, "apps.plugin: \t cmajflt %llu from %d %s %s\n", x, t->pid, t->comm, t->target->name);
1121 }
1122 }
1123
1070 - if(diff_utime) fprintf(stderr, "apps.plugin: \t cannot fix up utime %llu\n", diff_utime);
1071 - if(diff_stime) fprintf(stderr, "apps.plugin: \t cannot fix up stime %llu\n", diff_stime);
1072 - if(diff_minflt) fprintf(stderr, "apps.plugin: \t cannot fix up minflt %llu\n", diff_minflt);
1073 - if(diff_majflt) fprintf(stderr, "apps.plugin: \t cannot fix up majflt %llu\n", diff_majflt);
1124 + if(diff_utime) error("apps.plugin: \t cannot fix up utime %llu", diff_utime);
1125 + if(diff_stime) error("apps.plugin: \t cannot fix up stime %llu", diff_stime);
1126 + if(diff_minflt) error("apps.plugin: \t cannot fix up minflt %llu", diff_minflt);
1127 + if(diff_majflt) error("apps.plugin: \t cannot fix up majflt %llu", diff_majflt);
1128 }
1129 #endif
1130
@@ -1080,9 +1134,9 @@ void update_statistics(void)
1134 for (w = target_root; w ; w = w->next) {
1135 targets++;
1136
1083 - w->fds = calloc(sizeof(int), all_files_len);
1137 + w->fds = calloc(sizeof(int), all_files_size);
1138 if(!w->fds)
1085 - fprintf(stderr, "apps.plugin: ERROR: cannot allocate memory for fds in %s\n", w->name);
1139 + error("apps.plugin: ERROR: cannot allocate memory for fds in %s", w->name);
1140
1141 w->minflt = 0;
1142 w->majflt = 0;
@@ -1120,7 +1174,7 @@ void update_statistics(void)
1174 // concentrate everything on the targets
1175 for(p = root; p ; p = p->next) {
1176 if(!p->target) {
1123 - fprintf(stderr, "apps.plugin: ERROR: pid %d %s was left without a target!\n", p->pid, p->comm);
1177 + error("apps.plugin: ERROR: pid %d %s was left without a target!", p->pid, p->comm);
1178 continue;
1179 }
1180
@@ -1158,11 +1212,11 @@ void update_statistics(void)
1212
1213 for(c = 0; c < p->fds_size ;c++) {
1214 if(p->fds[c] == 0) continue;
1161 - if(p->fds[c] > 0 && p->fds[c] < all_files_len) {
1215 + if(p->fds[c] < all_files_size) {
1216 if(p->target->fds) p->target->fds[p->fds[c]]++;
1217 }
1218 else
1165 - fprintf(stderr, "apps.plugin: ERROR: invalid fd number %d\n", p->fds[c]);
1219 + error("apps.plugin: ERROR: invalid fd number %d", p->fds[c]);
1220 }
1221
1222 if(debug || p->target->debug) fprintf(stderr, "apps.plugin: \tAgregating %s pid %d on %s utime=%llu, stime=%llu, cutime=%llu, cstime=%llu, minflt=%llu, majflt=%llu, cminflt=%llu, cmajflt=%llu\n", p->comm, p->pid, p->target->name, p->utime, p->stime, p->cutime, p->cstime, p->minflt, p->majflt, p->cminflt, p->cmajflt);
@@ -1242,7 +1296,7 @@ void update_statistics(void)
1296 w->openeventpolls = 0;
1297 w->openother = 0;
1298
1245 - for(c = 1; c < all_files_len ;c++) {
1299 + for(c = 1; c < all_files_size ;c++) {
1300 if(w->fds && w->fds[c] > 0) switch(all_files[c].type) {
1301 case FILETYPE_FILE:
1302 w->openfiles++;
@@ -1627,7 +1681,7 @@ void parse_args(int argc, char **argv)
1681 continue;
1682 }
1683
1630 - fprintf(stderr, "apps.plugin: ERROR: cannot understand option %s\n", argv[i]);
1684 + error("apps.plugin: ERROR: cannot understand option %s", argv[i]);
1685 exit(1);
1686 }
1687
@@ -1635,13 +1689,15 @@ void parse_args(int argc, char **argv)
1689 if(!name) name = "groups";
1690
1691 if(read_process_groups(name)) {
1638 - fprintf(stderr, "apps.plugin: ERROR: cannot read process groups %s\n", name);
1692 + error("apps.plugin: ERROR: cannot read process groups %s", name);
1693 exit(1);
1694 }
1695 }
1696
1697 int main(int argc, char **argv)
1698 {
1699 + // debug_flags = D_PROCFILE;
1700 +
1701 unsigned long started_t = time(NULL), current_t;
1702 Hertz = get_hertz();
1703 pid_max = get_pid_max();
@@ -1651,7 +1707,7 @@ int main(int argc, char **argv)
1707
1708 all_pids = calloc(sizeof(struct pid_stat *), pid_max);
1709 if(!all_pids) {
1654 - fprintf(stderr, "apps.plugin: ERROR: cannot allocate %lu bytes of memory.\n", sizeof(struct pid_stat *) * pid_max);
1710 + error("apps.plugin: ERROR: cannot allocate %lu bytes of memory.", sizeof(struct pid_stat *) * pid_max);
1711 printf("DISABLE\n");
1712 exit(1);
1713 }
@@ -1663,7 +1719,7 @@ int main(int argc, char **argv)
1719
1720 for(;1; counter++) {
1721 if(!update_from_proc()) {
1666 - fprintf(stderr, "apps.plugin: ERROR: cannot allocate %lu bytes of memory.\n", sizeof(struct pid_stat *) * pid_max);
1722 + error("apps.plugin: ERROR: cannot allocate %lu bytes of memory.", sizeof(struct pid_stat *) * pid_max);
1723 printf("DISABLE\n");
1724 exit(1);
1725 }
src/plugins_d.c
+18 -18
@@ -32,7 +32,7 @@ void *pluginsd_worker_thread(void *arg)
32 break;
33 }
34
35 - RRD_STATS *st = NULL;
35 + RRDSET *st = NULL;
36
37 unsigned long long count = 0;
38 while(fgets(line, PLUGINSD_LINE_MAX, fp) != NULL) {
@@ -64,7 +64,7 @@ void *pluginsd_worker_thread(void *arg)
64 }
65
66 if(st->debug) debug(D_PLUGINSD, "PLUGINSD: '%s' is setting dimension %s/%s to %s", cd->fullfilename, st->id, dimension, value);
67 - rrd_stats_dimension_set(st, dimension, atoll(value));
67 + rrddim_set(st, dimension, atoll(value));
68
69 count++;
70 }
@@ -79,7 +79,7 @@ void *pluginsd_worker_thread(void *arg)
79 break;
80 }
81
82 - st = rrd_stats_find(id);
82 + st = rrdset_find(id);
83 if(!st) {
84 error("PLUGINSD: '%s' is requesting a BEGIN on chart '%s', which does not exist. Disabling it.", cd->fullfilename, id);
85 cd->enabled = 0;
@@ -90,8 +90,8 @@ void *pluginsd_worker_thread(void *arg)
90 if(st->counter_done) {
91 unsigned long long microseconds = 0;
92 if(microseconds_txt && *microseconds_txt) microseconds = strtoull(microseconds_txt, NULL, 10);
93 - if(microseconds) rrd_stats_next_usec(st, microseconds);
94 - else rrd_stats_next_plugins(st);
93 + if(microseconds) rrdset_next_usec(st, microseconds);
94 + else rrdset_next_plugins(st);
95 }
96 }
97 else if(!strcmp(s, "END")) {
@@ -104,7 +104,7 @@ void *pluginsd_worker_thread(void *arg)
104
105 if(st->debug) debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a END on chart %s", cd->fullfilename, st->id);
106
107 - rrd_stats_done(st);
107 + rrdset_done(st);
108 st = NULL;
109 }
110 else if(!strcmp(s, "FLUSH")) {
@@ -143,26 +143,26 @@ void *pluginsd_worker_thread(void *arg)
143 if(update_every_s) update_every = atoi(update_every_s);
144 if(!update_every) update_every = cd->update_every;
145
146 - int chart_type = CHART_TYPE_LINE;
147 - if(chart) chart_type = chart_type_id(chart);
146 + int chart_type = RRDSET_TYPE_LINE;
147 + if(chart) chart_type = rrdset_type_id(chart);
148
149 if(!name || !*name) name = NULL;
150 if(!family || !*family) family = id;
151 if(!category || !*category) category = type;
152
153 - st = rrd_stats_find_bytype(type, id);
153 + st = rrdset_find_bytype(type, id);
154 if(!st) {
155 debug(D_PLUGINSD, "PLUGINSD: Creating chart type='%s', id='%s', name='%s', family='%s', category='%s', chart='%s', priority=%d, update_every=%d"
156 , type, id
157 , name?name:""
158 , family?family:""
159 , category?category:""
160 - , chart_type_name(chart_type)
160 + , rrdset_type_name(chart_type)
161 , priority
162 , update_every
163 );
164
165 - st = rrd_stats_create(type, id, name, family, title, units, priority, update_every, chart_type);
165 + st = rrdset_create(type, id, name, family, title, units, priority, update_every, chart_type);
166 cd->update_every = update_every;
167
168 if(strcmp(category, "none") == 0) st->isdetail = 1;
@@ -205,15 +205,15 @@ void *pluginsd_worker_thread(void *arg)
205 , st->id
206 , id
207 , name?name:""
208 - , algorithm_name(algorithm_id(algorithm))
208 + , rrddim_algorithm_name(rrddim_algorithm_id(algorithm))
209 , multiplier
210 , divisor
211 , hidden?hidden:""
212 );
213
214 - RRD_DIMENSION *rd = rrd_stats_dimension_find(st, id);
214 + RRDDIM *rd = rrddim_find(st, id);
215 if(!rd) {
216 - rd = rrd_stats_dimension_add(st, id, name, multiplier, divisor, algorithm_id(algorithm));
216 + rd = rrddim_add(st, id, name, multiplier, divisor, rrddim_algorithm_id(algorithm));
217 if(hidden && strcmp(hidden, "hidden") == 0) rd->hidden = 1;
218 }
219 else if(st->debug) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
@@ -238,14 +238,14 @@ void *pluginsd_worker_thread(void *arg)
238 gettimeofday(&now, NULL);
239 if(!usec && !susec) {
240 // our first run
241 - susec = cd->update_every * 1000000ULL;
241 + susec = cd->rrd_update_every * 1000000ULL;
242 }
243 else {
244 // second+ run
245 usec = usecdiff(&now, &last) - susec;
246 error("PLUGINSD: %s last loop took %llu usec (worked for %llu, sleeped for %llu).\n", cd->fullfilename, usec + susec, usec, susec);
247 - if(usec < (update_every * 1000000ULL / 2ULL)) susec = (update_every * 1000000ULL) - usec;
248 - else susec = update_every * 1000000ULL / 2ULL;
247 + if(usec < (rrd_update_every * 1000000ULL / 2ULL)) susec = (rrd_update_every * 1000000ULL) - usec;
248 + else susec = rrd_update_every * 1000000ULL / 2ULL;
249 }
250
251 error("PLUGINSD: %s sleeping for %llu. Will kill with SIGCONT pid %d to wake it up.\n", cd->fullfilename, susec, cd->pid);
@@ -351,7 +351,7 @@ void *pluginsd_main(void *ptr)
351 snprintf(cd->fullfilename, FILENAME_MAX, "%s/%s", dir_name, cd->filename);
352
353 cd->enabled = enabled;
354 - cd->update_every = config_get_number(cd->id, "update every", update_every);
354 + cd->update_every = config_get_number(cd->id, "update every", rrd_update_every);
355 cd->started_t = time(NULL);
356
357 char *def = "";
src/proc_diskstats.c
+43 -43
@@ -186,12 +186,12 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
186 if(!config_get_boolean("plugin:proc:/proc/diskstats", var_name, def_enabled)) continue;
187 }
188
189 - RRD_STATS *st;
189 + RRDSET *st;
190
191 // --------------------------------------------------------------------
192
193 if(do_io) {
194 - st = rrd_stats_find_bytype(RRD_TYPE_DISK, disk);
194 + st = rrdset_find_bytype(RRD_TYPE_DISK, disk);
195 if(!st) {
196 char tf[FILENAME_MAX + 1], *t;
197 char ssfilename[FILENAME_MAX + 1];
@@ -222,90 +222,90 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
222 }
223 else error("Cannot read sector size for device %s from %s. Assuming 512.", disk, ssfilename);
224
225 - st = rrd_stats_create(RRD_TYPE_DISK, disk, NULL, disk, "Disk I/O", "kilobytes/s", 2000, update_every, CHART_TYPE_AREA);
225 + st = rrdset_create(RRD_TYPE_DISK, disk, NULL, disk, "Disk I/O", "kilobytes/s", 2000, update_every, RRDSET_TYPE_AREA);
226
227 - rrd_stats_dimension_add(st, "reads", NULL, sector_size, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
228 - rrd_stats_dimension_add(st, "writes", NULL, sector_size * -1, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
227 + rrddim_add(st, "reads", NULL, sector_size, 1024 * update_every, RRDDIM_INCREMENTAL);
228 + rrddim_add(st, "writes", NULL, sector_size * -1, 1024 * update_every, RRDDIM_INCREMENTAL);
229 }
230 - else rrd_stats_next(st);
230 + else rrdset_next(st);
231
232 - rrd_stats_dimension_set(st, "reads", readsectors);
233 - rrd_stats_dimension_set(st, "writes", writesectors);
234 - rrd_stats_done(st);
232 + rrddim_set(st, "reads", readsectors);
233 + rrddim_set(st, "writes", writesectors);
234 + rrdset_done(st);
235 }
236
237 // --------------------------------------------------------------------
238
239 if(do_ops) {
240 - st = rrd_stats_find_bytype("disk_ops", disk);
240 + st = rrdset_find_bytype("disk_ops", disk);
241 if(!st) {
242 - st = rrd_stats_create("disk_ops", disk, NULL, disk, "Disk Operations", "operations/s", 2001, update_every, CHART_TYPE_LINE);
242 + st = rrdset_create("disk_ops", disk, NULL, disk, "Disk Operations", "operations/s", 2001, update_every, RRDSET_TYPE_LINE);
243 st->isdetail = 1;
244
245 - rrd_stats_dimension_add(st, "reads", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
246 - rrd_stats_dimension_add(st, "writes", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
245 + rrddim_add(st, "reads", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
246 + rrddim_add(st, "writes", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
247 }
248 - else rrd_stats_next(st);
248 + else rrdset_next(st);
249
250 - rrd_stats_dimension_set(st, "reads", reads);
251 - rrd_stats_dimension_set(st, "writes", writes);
252 - rrd_stats_done(st);
250 + rrddim_set(st, "reads", reads);
251 + rrddim_set(st, "writes", writes);
252 + rrdset_done(st);
253 }
254
255 // --------------------------------------------------------------------
256
257 if(do_merged_ops) {
258 - st = rrd_stats_find_bytype("disk_merged_ops", disk);
258 + st = rrdset_find_bytype("disk_merged_ops", disk);
259 if(!st) {
260 - st = rrd_stats_create("disk_merged_ops", disk, NULL, disk, "Merged Disk Operations", "operations/s", 2010, update_every, CHART_TYPE_LINE);
260 + st = rrdset_create("disk_merged_ops", disk, NULL, disk, "Merged Disk Operations", "operations/s", 2010, update_every, RRDSET_TYPE_LINE);
261 st->isdetail = 1;
262
263 - rrd_stats_dimension_add(st, "reads", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
264 - rrd_stats_dimension_add(st, "writes", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
263 + rrddim_add(st, "reads", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
264 + rrddim_add(st, "writes", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
265 }
266 - else rrd_stats_next(st);
266 + else rrdset_next(st);
267
268 - rrd_stats_dimension_set(st, "reads", reads_merged);
269 - rrd_stats_dimension_set(st, "writes", writes_merged);
270 - rrd_stats_done(st);
268 + rrddim_set(st, "reads", reads_merged);
269 + rrddim_set(st, "writes", writes_merged);
270 + rrdset_done(st);
271 }
272
273 // --------------------------------------------------------------------
274
275 if(do_iotime) {
276 - st = rrd_stats_find_bytype("disk_iotime", disk);
276 + st = rrdset_find_bytype("disk_iotime", disk);
277 if(!st) {
278 - st = rrd_stats_create("disk_iotime", disk, NULL, disk, "Disk I/O Time", "milliseconds/s", 2005, update_every, CHART_TYPE_LINE);
278 + st = rrdset_create("disk_iotime", disk, NULL, disk, "Disk I/O Time", "milliseconds/s", 2005, update_every, RRDSET_TYPE_LINE);
279 st->isdetail = 1;
280
281 - rrd_stats_dimension_add(st, "reads", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
282 - rrd_stats_dimension_add(st, "writes", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
283 - rrd_stats_dimension_add(st, "latency", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
284 - rrd_stats_dimension_add(st, "weighted", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
281 + rrddim_add(st, "reads", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
282 + rrddim_add(st, "writes", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
283 + rrddim_add(st, "latency", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
284 + rrddim_add(st, "weighted", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
285 }
286 - else rrd_stats_next(st);
286 + else rrdset_next(st);
287
288 - rrd_stats_dimension_set(st, "reads", readms);
289 - rrd_stats_dimension_set(st, "writes", writems);
290 - rrd_stats_dimension_set(st, "latency", iosms);
291 - rrd_stats_dimension_set(st, "weighted", wiosms);
292 - rrd_stats_done(st);
288 + rrddim_set(st, "reads", readms);
289 + rrddim_set(st, "writes", writems);
290 + rrddim_set(st, "latency", iosms);
291 + rrddim_set(st, "weighted", wiosms);
292 + rrdset_done(st);
293 }
294
295 // --------------------------------------------------------------------
296
297 if(do_cur_ops) {
298 - st = rrd_stats_find_bytype("disk_cur_ops", disk);
298 + st = rrdset_find_bytype("disk_cur_ops", disk);
299 if(!st) {
300 - st = rrd_stats_create("disk_cur_ops", disk, NULL, disk, "Current Disk I/O operations", "operations", 2004, update_every, CHART_TYPE_LINE);
300 + st = rrdset_create("disk_cur_ops", disk, NULL, disk, "Current Disk I/O operations", "operations", 2004, update_every, RRDSET_TYPE_LINE);
301 st->isdetail = 1;
302
303 - rrd_stats_dimension_add(st, "operations", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
303 + rrddim_add(st, "operations", NULL, 1, 1, RRDDIM_ABSOLUTE);
304 }
305 - else rrd_stats_next(st);
305 + else rrdset_next(st);
306
307 - rrd_stats_dimension_set(st, "operations", currentios);
308 - rrd_stats_done(st);
307 + rrddim_set(st, "operations", currentios);
308 + rrdset_done(st);
309 }
310 }
311
src/proc_meminfo.c
+68 -68
@@ -98,7 +98,7 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
98 else if(!DirectMap2M && strcmp(name, "DirectMap2M") == 0) DirectMap2M = value;
99 }
100
101 - RRD_STATS *st;
101 + RRDSET *st;
102
103 // --------------------------------------------------------------------
104
@@ -106,22 +106,22 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
106 unsigned long long MemUsed = MemTotal - MemFree - Cached - Buffers;
107
108 if(do_ram) {
109 - st = rrd_stats_find("system.ram");
109 + st = rrdset_find("system.ram");
110 if(!st) {
111 - st = rrd_stats_create("system", "ram", NULL, "mem", "System RAM", "MB", 200, update_every, CHART_TYPE_STACKED);
111 + st = rrdset_create("system", "ram", NULL, "mem", "System RAM", "MB", 200, update_every, RRDSET_TYPE_STACKED);
112
113 - rrd_stats_dimension_add(st, "buffers", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
114 - rrd_stats_dimension_add(st, "used", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
115 - rrd_stats_dimension_add(st, "cached", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
116 - rrd_stats_dimension_add(st, "free", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
113 + rrddim_add(st, "buffers", NULL, 1, 1024, RRDDIM_ABSOLUTE);
114 + rrddim_add(st, "used", NULL, 1, 1024, RRDDIM_ABSOLUTE);
115 + rrddim_add(st, "cached", NULL, 1, 1024, RRDDIM_ABSOLUTE);
116 + rrddim_add(st, "free", NULL, 1, 1024, RRDDIM_ABSOLUTE);
117 }
118 - else rrd_stats_next(st);
118 + else rrdset_next(st);
119
120 - rrd_stats_dimension_set(st, "used", MemUsed);
121 - rrd_stats_dimension_set(st, "free", MemFree);
122 - rrd_stats_dimension_set(st, "cached", Cached);
123 - rrd_stats_dimension_set(st, "buffers", Buffers);
124 - rrd_stats_done(st);
120 + rrddim_set(st, "used", MemUsed);
121 + rrddim_set(st, "free", MemFree);
122 + rrddim_set(st, "cached", Cached);
123 + rrddim_set(st, "buffers", Buffers);
124 + rrdset_done(st);
125 }
126
127 // --------------------------------------------------------------------
@@ -129,115 +129,115 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
129 unsigned long long SwapUsed = SwapTotal - SwapFree;
130
131 if(do_swap) {
132 - st = rrd_stats_find("system.swap");
132 + st = rrdset_find("system.swap");
133 if(!st) {
134 - st = rrd_stats_create("system", "swap", NULL, "mem", "System Swap", "MB", 201, update_every, CHART_TYPE_STACKED);
134 + st = rrdset_create("system", "swap", NULL, "mem", "System Swap", "MB", 201, update_every, RRDSET_TYPE_STACKED);
135 st->isdetail = 1;
136
137 - rrd_stats_dimension_add(st, "free", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
138 - rrd_stats_dimension_add(st, "used", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
137 + rrddim_add(st, "free", NULL, 1, 1024, RRDDIM_ABSOLUTE);
138 + rrddim_add(st, "used", NULL, 1, 1024, RRDDIM_ABSOLUTE);
139 }
140 - else rrd_stats_next(st);
140 + else rrdset_next(st);
141
142 - rrd_stats_dimension_set(st, "used", SwapUsed);
143 - rrd_stats_dimension_set(st, "free", SwapFree);
144 - rrd_stats_done(st);
142 + rrddim_set(st, "used", SwapUsed);
143 + rrddim_set(st, "free", SwapFree);
144 + rrdset_done(st);
145 }
146
147 // --------------------------------------------------------------------
148
149 if(hwcorrupted && do_hwcorrupt) {
150 - st = rrd_stats_find("mem.hwcorrupt");
150 + st = rrdset_find("mem.hwcorrupt");
151 if(!st) {
152 - st = rrd_stats_create("mem", "hwcorrupt", NULL, "mem", "Hardware Corrupted ECC", "MB", 9000, update_every, CHART_TYPE_LINE);
152 + st = rrdset_create("mem", "hwcorrupt", NULL, "mem", "Hardware Corrupted ECC", "MB", 9000, update_every, RRDSET_TYPE_LINE);
153 st->isdetail = 1;
154
155 - rrd_stats_dimension_add(st, "HardwareCorrupted", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
155 + rrddim_add(st, "HardwareCorrupted", NULL, 1, 1024, RRDDIM_ABSOLUTE);
156 }
157 - else rrd_stats_next(st);
157 + else rrdset_next(st);
158
159 - rrd_stats_dimension_set(st, "HardwareCorrupted", HardwareCorrupted);
160 - rrd_stats_done(st);
159 + rrddim_set(st, "HardwareCorrupted", HardwareCorrupted);
160 + rrdset_done(st);
161 }
162
163 // --------------------------------------------------------------------
164
165 if(do_committed) {
166 - st = rrd_stats_find("mem.committed");
166 + st = rrdset_find("mem.committed");
167 if(!st) {
168 - st = rrd_stats_create("mem", "committed", NULL, "mem", "Committed (Allocated) Memory", "MB", 5000, update_every, CHART_TYPE_AREA);
168 + st = rrdset_create("mem", "committed", NULL, "mem", "Committed (Allocated) Memory", "MB", 5000, update_every, RRDSET_TYPE_AREA);
169 st->isdetail = 1;
170
171 - rrd_stats_dimension_add(st, "Committed_AS", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
171 + rrddim_add(st, "Committed_AS", NULL, 1, 1024, RRDDIM_ABSOLUTE);
172 }
173 - else rrd_stats_next(st);
173 + else rrdset_next(st);
174
175 - rrd_stats_dimension_set(st, "Committed_AS", Committed_AS);
176 - rrd_stats_done(st);
175 + rrddim_set(st, "Committed_AS", Committed_AS);
176 + rrdset_done(st);
177 }
178
179 // --------------------------------------------------------------------
180
181 if(do_writeback) {
182 - st = rrd_stats_find("mem.writeback");
182 + st = rrdset_find("mem.writeback");
183 if(!st) {
184 - st = rrd_stats_create("mem", "writeback", NULL, "mem", "Writeback Memory", "MB", 4000, update_every, CHART_TYPE_LINE);
184 + st = rrdset_create("mem", "writeback", NULL, "mem", "Writeback Memory", "MB", 4000, update_every, RRDSET_TYPE_LINE);
185 st->isdetail = 1;
186
187 - rrd_stats_dimension_add(st, "Dirty", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
188 - rrd_stats_dimension_add(st, "Writeback", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
189 - rrd_stats_dimension_add(st, "FuseWriteback", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
190 - rrd_stats_dimension_add(st, "NfsWriteback", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
191 - rrd_stats_dimension_add(st, "Bounce", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
187 + rrddim_add(st, "Dirty", NULL, 1, 1024, RRDDIM_ABSOLUTE);
188 + rrddim_add(st, "Writeback", NULL, 1, 1024, RRDDIM_ABSOLUTE);
189 + rrddim_add(st, "FuseWriteback", NULL, 1, 1024, RRDDIM_ABSOLUTE);
190 + rrddim_add(st, "NfsWriteback", NULL, 1, 1024, RRDDIM_ABSOLUTE);
191 + rrddim_add(st, "Bounce", NULL, 1, 1024, RRDDIM_ABSOLUTE);
192 }
193 - else rrd_stats_next(st);
194 -
195 - rrd_stats_dimension_set(st, "Dirty", Dirty);
196 - rrd_stats_dimension_set(st, "Writeback", Writeback);
197 - rrd_stats_dimension_set(st, "FuseWriteback", WritebackTmp);
198 - rrd_stats_dimension_set(st, "NfsWriteback", NFS_Unstable);
199 - rrd_stats_dimension_set(st, "Bounce", Bounce);
200 - rrd_stats_done(st);
193 + else rrdset_next(st);
194 +
195 + rrddim_set(st, "Dirty", Dirty);
196 + rrddim_set(st, "Writeback", Writeback);
197 + rrddim_set(st, "FuseWriteback", WritebackTmp);
198 + rrddim_set(st, "NfsWriteback", NFS_Unstable);
199 + rrddim_set(st, "Bounce", Bounce);
200 + rrdset_done(st);
201 }
202
203 // --------------------------------------------------------------------
204
205 if(do_kernel) {
206 - st = rrd_stats_find("mem.kernel");
206 + st = rrdset_find("mem.kernel");
207 if(!st) {
208 - st = rrd_stats_create("mem", "kernel", NULL, "mem", "Memory Used by Kernel", "MB", 6000, update_every, CHART_TYPE_STACKED);
208 + st = rrdset_create("mem", "kernel", NULL, "mem", "Memory Used by Kernel", "MB", 6000, update_every, RRDSET_TYPE_STACKED);
209 st->isdetail = 1;
210
211 - rrd_stats_dimension_add(st, "Slab", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
212 - rrd_stats_dimension_add(st, "KernelStack", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
213 - rrd_stats_dimension_add(st, "PageTables", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
214 - rrd_stats_dimension_add(st, "VmallocUsed", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
211 + rrddim_add(st, "Slab", NULL, 1, 1024, RRDDIM_ABSOLUTE);
212 + rrddim_add(st, "KernelStack", NULL, 1, 1024, RRDDIM_ABSOLUTE);
213 + rrddim_add(st, "PageTables", NULL, 1, 1024, RRDDIM_ABSOLUTE);
214 + rrddim_add(st, "VmallocUsed", NULL, 1, 1024, RRDDIM_ABSOLUTE);
215 }
216 - else rrd_stats_next(st);
216 + else rrdset_next(st);
217
218 - rrd_stats_dimension_set(st, "KernelStack", KernelStack);
219 - rrd_stats_dimension_set(st, "Slab", Slab);
220 - rrd_stats_dimension_set(st, "PageTables", PageTables);
221 - rrd_stats_dimension_set(st, "VmallocUsed", VmallocUsed);
222 - rrd_stats_done(st);
218 + rrddim_set(st, "KernelStack", KernelStack);
219 + rrddim_set(st, "Slab", Slab);
220 + rrddim_set(st, "PageTables", PageTables);
221 + rrddim_set(st, "VmallocUsed", VmallocUsed);
222 + rrdset_done(st);
223 }
224
225 // --------------------------------------------------------------------
226
227 if(do_slab) {
228 - st = rrd_stats_find("mem.slab");
228 + st = rrdset_find("mem.slab");
229 if(!st) {
230 - st = rrd_stats_create("mem", "slab", NULL, "mem", "Reclaimable Kernel Memory", "MB", 6500, update_every, CHART_TYPE_STACKED);
230 + st = rrdset_create("mem", "slab", NULL, "mem", "Reclaimable Kernel Memory", "MB", 6500, update_every, RRDSET_TYPE_STACKED);
231 st->isdetail = 1;
232
233 - rrd_stats_dimension_add(st, "reclaimable", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
234 - rrd_stats_dimension_add(st, "unreclaimable", NULL, 1, 1024, RRD_DIMENSION_ABSOLUTE);
233 + rrddim_add(st, "reclaimable", NULL, 1, 1024, RRDDIM_ABSOLUTE);
234 + rrddim_add(st, "unreclaimable", NULL, 1, 1024, RRDDIM_ABSOLUTE);
235 }
236 - else rrd_stats_next(st);
236 + else rrdset_next(st);
237
238 - rrd_stats_dimension_set(st, "reclaimable", SReclaimable);
239 - rrd_stats_dimension_set(st, "unreclaimable", SUnreclaim);
240 - rrd_stats_done(st);
238 + rrddim_set(st, "reclaimable", SReclaimable);
239 + rrddim_set(st, "unreclaimable", SUnreclaim);
240 + rrdset_done(st);
241 }
242
243 return 0;
src/proc_net_dev.c
+61 -61
@@ -67,135 +67,135 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
67 if(!config_get_boolean("plugin:proc:/proc/net/dev", var_name, enable_new_interfaces)) continue;
68 }
69
70 - RRD_STATS *st;
70 + RRDSET *st;
71
72 // --------------------------------------------------------------------
73
74 if(do_bandwidth) {
75 - st = rrd_stats_find_bytype("net", iface);
75 + st = rrdset_find_bytype("net", iface);
76 if(!st) {
77 - st = rrd_stats_create("net", iface, NULL, iface, "Bandwidth", "kilobits/s", 1000, update_every, CHART_TYPE_AREA);
77 + st = rrdset_create("net", iface, NULL, iface, "Bandwidth", "kilobits/s", 1000, update_every, RRDSET_TYPE_AREA);
78
79 - rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
80 - rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
79 + rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
80 + rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
81 }
82 - else rrd_stats_next(st);
82 + else rrdset_next(st);
83
84 - rrd_stats_dimension_set(st, "received", rbytes);
85 - rrd_stats_dimension_set(st, "sent", tbytes);
86 - rrd_stats_done(st);
84 + rrddim_set(st, "received", rbytes);
85 + rrddim_set(st, "sent", tbytes);
86 + rrdset_done(st);
87 }
88
89 // --------------------------------------------------------------------
90
91 if(do_packets) {
92 - st = rrd_stats_find_bytype("net_packets", iface);
92 + st = rrdset_find_bytype("net_packets", iface);
93 if(!st) {
94 - st = rrd_stats_create("net_packets", iface, NULL, iface, "Packets", "packets/s", 1001, update_every, CHART_TYPE_LINE);
94 + st = rrdset_create("net_packets", iface, NULL, iface, "Packets", "packets/s", 1001, update_every, RRDSET_TYPE_LINE);
95 st->isdetail = 1;
96
97 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
98 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
99 - rrd_stats_dimension_add(st, "multicast", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
97 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
98 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
99 + rrddim_add(st, "multicast", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
100 }
101 - else rrd_stats_next(st);
101 + else rrdset_next(st);
102
103 - rrd_stats_dimension_set(st, "received", rpackets);
104 - rrd_stats_dimension_set(st, "sent", tpackets);
105 - rrd_stats_dimension_set(st, "multicast", rmulticast);
106 - rrd_stats_done(st);
103 + rrddim_set(st, "received", rpackets);
104 + rrddim_set(st, "sent", tpackets);
105 + rrddim_set(st, "multicast", rmulticast);
106 + rrdset_done(st);
107 }
108
109 // --------------------------------------------------------------------
110
111 if(do_errors) {
112 - st = rrd_stats_find_bytype("net_errors", iface);
112 + st = rrdset_find_bytype("net_errors", iface);
113 if(!st) {
114 - st = rrd_stats_create("net_errors", iface, NULL, iface, "Interface Errors", "errors/s", 1002, update_every, CHART_TYPE_LINE);
114 + st = rrdset_create("net_errors", iface, NULL, iface, "Interface Errors", "errors/s", 1002, update_every, RRDSET_TYPE_LINE);
115 st->isdetail = 1;
116
117 - rrd_stats_dimension_add(st, "inbound", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
118 - rrd_stats_dimension_add(st, "outbound", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
117 + rrddim_add(st, "inbound", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
118 + rrddim_add(st, "outbound", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
119 }
120 - else rrd_stats_next(st);
120 + else rrdset_next(st);
121
122 - rrd_stats_dimension_set(st, "inbound", rerrors);
123 - rrd_stats_dimension_set(st, "outbound", terrors);
124 - rrd_stats_done(st);
122 + rrddim_set(st, "inbound", rerrors);
123 + rrddim_set(st, "outbound", terrors);
124 + rrdset_done(st);
125 }
126
127 // --------------------------------------------------------------------
128
129 if(do_drops) {
130 - st = rrd_stats_find_bytype("net_drops", iface);
130 + st = rrdset_find_bytype("net_drops", iface);
131 if(!st) {
132 - st = rrd_stats_create("net_drops", iface, NULL, iface, "Interface Drops", "drops/s", 1003, update_every, CHART_TYPE_LINE);
132 + st = rrdset_create("net_drops", iface, NULL, iface, "Interface Drops", "drops/s", 1003, update_every, RRDSET_TYPE_LINE);
133 st->isdetail = 1;
134
135 - rrd_stats_dimension_add(st, "inbound", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
136 - rrd_stats_dimension_add(st, "outbound", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
135 + rrddim_add(st, "inbound", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
136 + rrddim_add(st, "outbound", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
137 }
138 - else rrd_stats_next(st);
138 + else rrdset_next(st);
139
140 - rrd_stats_dimension_set(st, "inbound", rdrops);
141 - rrd_stats_dimension_set(st, "outbound", tdrops);
142 - rrd_stats_done(st);
140 + rrddim_set(st, "inbound", rdrops);
141 + rrddim_set(st, "outbound", tdrops);
142 + rrdset_done(st);
143 }
144
145 // --------------------------------------------------------------------
146
147 if(do_fifo) {
148 - st = rrd_stats_find_bytype("net_fifo", iface);
148 + st = rrdset_find_bytype("net_fifo", iface);
149 if(!st) {
150 - st = rrd_stats_create("net_fifo", iface, NULL, iface, "Interface Queue", "packets", 1100, update_every, CHART_TYPE_LINE);
150 + st = rrdset_create("net_fifo", iface, NULL, iface, "Interface Queue", "packets", 1100, update_every, RRDSET_TYPE_LINE);
151 st->isdetail = 1;
152
153 - rrd_stats_dimension_add(st, "receive", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
154 - rrd_stats_dimension_add(st, "transmit", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
153 + rrddim_add(st, "receive", NULL, 1, 1, RRDDIM_ABSOLUTE);
154 + rrddim_add(st, "transmit", NULL, -1, 1, RRDDIM_ABSOLUTE);
155 }
156 - else rrd_stats_next(st);
156 + else rrdset_next(st);
157
158 - rrd_stats_dimension_set(st, "receive", rfifo);
159 - rrd_stats_dimension_set(st, "transmit", tfifo);
160 - rrd_stats_done(st);
158 + rrddim_set(st, "receive", rfifo);
159 + rrddim_set(st, "transmit", tfifo);
160 + rrdset_done(st);
161 }
162
163 // --------------------------------------------------------------------
164
165 if(do_compressed) {
166 - st = rrd_stats_find_bytype("net_compressed", iface);
166 + st = rrdset_find_bytype("net_compressed", iface);
167 if(!st) {
168 - st = rrd_stats_create("net_compressed", iface, NULL, iface, "Compressed Packets", "packets/s", 1200, update_every, CHART_TYPE_LINE);
168 + st = rrdset_create("net_compressed", iface, NULL, iface, "Compressed Packets", "packets/s", 1200, update_every, RRDSET_TYPE_LINE);
169 st->isdetail = 1;
170
171 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
172 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
171 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
172 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
173 }
174 - else rrd_stats_next(st);
174 + else rrdset_next(st);
175
176 - rrd_stats_dimension_set(st, "received", rcompressed);
177 - rrd_stats_dimension_set(st, "sent", tcompressed);
178 - rrd_stats_done(st);
176 + rrddim_set(st, "received", rcompressed);
177 + rrddim_set(st, "sent", tcompressed);
178 + rrdset_done(st);
179 }
180
181 // --------------------------------------------------------------------
182
183 if(do_events) {
184 - st = rrd_stats_find_bytype("net_events", iface);
184 + st = rrdset_find_bytype("net_events", iface);
185 if(!st) {
186 - st = rrd_stats_create("net_events", iface, NULL, iface, "Network Interface Events", "events/s", 1200, update_every, CHART_TYPE_LINE);
186 + st = rrdset_create("net_events", iface, NULL, iface, "Network Interface Events", "events/s", 1200, update_every, RRDSET_TYPE_LINE);
187 st->isdetail = 1;
188
189 - rrd_stats_dimension_add(st, "frames", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
190 - rrd_stats_dimension_add(st, "collisions", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
191 - rrd_stats_dimension_add(st, "carrier", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
189 + rrddim_add(st, "frames", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
190 + rrddim_add(st, "collisions", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
191 + rrddim_add(st, "carrier", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
192 }
193 - else rrd_stats_next(st);
193 + else rrdset_next(st);
194
195 - rrd_stats_dimension_set(st, "frames", rframe);
196 - rrd_stats_dimension_set(st, "collisions", tcollisions);
197 - rrd_stats_dimension_set(st, "carrier", tcarrier);
198 - rrd_stats_done(st);
195 + rrddim_set(st, "frames", rframe);
196 + rrddim_set(st, "collisions", tcollisions);
197 + rrddim_set(st, "carrier", tcarrier);
198 + rrdset_done(st);
199 }
200 }
201
src/proc_net_ip_vs_stats.c
+23 -23
@@ -40,55 +40,55 @@ int do_proc_net_ip_vs_stats(int update_every, unsigned long long dt) {
40 InBytes = strtoull(procfile_lineword(ff, 2, 3), NULL, 16);
41 OutBytes = strtoull(procfile_lineword(ff, 2, 4), NULL, 16);
42
43 - RRD_STATS *st;
43 + RRDSET *st;
44
45 // --------------------------------------------------------------------
46
47 if(do_sockets) {
48 - st = rrd_stats_find(RRD_TYPE_NET_IPVS ".sockets");
48 + st = rrdset_find(RRD_TYPE_NET_IPVS ".sockets");
49 if(!st) {
50 - st = rrd_stats_create(RRD_TYPE_NET_IPVS, "sockets", NULL, RRD_TYPE_NET_IPVS, "IPVS New Connections", "connections/s", 1001, update_every, CHART_TYPE_LINE);
50 + st = rrdset_create(RRD_TYPE_NET_IPVS, "sockets", NULL, RRD_TYPE_NET_IPVS, "IPVS New Connections", "connections/s", 1001, update_every, RRDSET_TYPE_LINE);
51
52 - rrd_stats_dimension_add(st, "connections", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
52 + rrddim_add(st, "connections", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
53 }
54 - else rrd_stats_next(st);
54 + else rrdset_next(st);
55
56 - rrd_stats_dimension_set(st, "connections", entries);
57 - rrd_stats_done(st);
56 + rrddim_set(st, "connections", entries);
57 + rrdset_done(st);
58 }
59
60 // --------------------------------------------------------------------
61
62 if(do_packets) {
63 - st = rrd_stats_find(RRD_TYPE_NET_IPVS ".packets");
63 + st = rrdset_find(RRD_TYPE_NET_IPVS ".packets");
64 if(!st) {
65 - st = rrd_stats_create(RRD_TYPE_NET_IPVS, "packets", NULL, RRD_TYPE_NET_IPVS, "IPVS Packets", "packets/s", 1002, update_every, CHART_TYPE_LINE);
65 + st = rrdset_create(RRD_TYPE_NET_IPVS, "packets", NULL, RRD_TYPE_NET_IPVS, "IPVS Packets", "packets/s", 1002, update_every, RRDSET_TYPE_LINE);
66
67 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
68 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
67 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
68 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
69 }
70 - else rrd_stats_next(st);
70 + else rrdset_next(st);
71
72 - rrd_stats_dimension_set(st, "received", InPackets);
73 - rrd_stats_dimension_set(st, "sent", OutPackets);
74 - rrd_stats_done(st);
72 + rrddim_set(st, "received", InPackets);
73 + rrddim_set(st, "sent", OutPackets);
74 + rrdset_done(st);
75 }
76
77 // --------------------------------------------------------------------
78
79 if(do_bandwidth) {
80 - st = rrd_stats_find(RRD_TYPE_NET_IPVS ".net");
80 + st = rrdset_find(RRD_TYPE_NET_IPVS ".net");
81 if(!st) {
82 - st = rrd_stats_create(RRD_TYPE_NET_IPVS, "net", NULL, RRD_TYPE_NET_IPVS, "IPVS Bandwidth", "kilobits/s", 1000, update_every, CHART_TYPE_AREA);
82 + st = rrdset_create(RRD_TYPE_NET_IPVS, "net", NULL, RRD_TYPE_NET_IPVS, "IPVS Bandwidth", "kilobits/s", 1000, update_every, RRDSET_TYPE_AREA);
83
84 - rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
85 - rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
84 + rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
85 + rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
86 }
87 - else rrd_stats_next(st);
87 + else rrdset_next(st);
88
89 - rrd_stats_dimension_set(st, "received", InBytes);
90 - rrd_stats_dimension_set(st, "sent", OutBytes);
91 - rrd_stats_done(st);
89 + rrddim_set(st, "received", InBytes);
90 + rrddim_set(st, "sent", OutBytes);
91 + rrdset_done(st);
92 }
93
94 return 0;
src/proc_net_netstat.c
+49 -49
@@ -63,113 +63,113 @@ int do_proc_net_netstat(int update_every, unsigned long long dt) {
63 InBcastOctets = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
64 OutBcastOctets = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
65
66 - RRD_STATS *st;
66 + RRDSET *st;
67
68 // --------------------------------------------------------------------
69
70 if(do_bandwidth) {
71 - st = rrd_stats_find("system.ipv4");
71 + st = rrdset_find("system.ipv4");
72 if(!st) {
73 - st = rrd_stats_create("system", "ipv4", NULL, "ipv4", "IPv4 Bandwidth", "kilobits/s", 2000, update_every, CHART_TYPE_AREA);
73 + st = rrdset_create("system", "ipv4", NULL, "ipv4", "IPv4 Bandwidth", "kilobits/s", 2000, update_every, RRDSET_TYPE_AREA);
74
75 - rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
76 - rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
75 + rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
76 + rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
77 }
78 - else rrd_stats_next(st);
78 + else rrdset_next(st);
79
80 - rrd_stats_dimension_set(st, "sent", OutOctets);
81 - rrd_stats_dimension_set(st, "received", InOctets);
82 - rrd_stats_done(st);
80 + rrddim_set(st, "sent", OutOctets);
81 + rrddim_set(st, "received", InOctets);
82 + rrdset_done(st);
83 }
84
85 // --------------------------------------------------------------------
86
87 if(do_inerrors) {
88 - st = rrd_stats_find("ipv4.inerrors");
88 + st = rrdset_find("ipv4.inerrors");
89 if(!st) {
90 - st = rrd_stats_create("ipv4", "inerrors", NULL, "ipv4", "IPv4 Input Errors", "packets/s", 4000, update_every, CHART_TYPE_LINE);
90 + st = rrdset_create("ipv4", "inerrors", NULL, "ipv4", "IPv4 Input Errors", "packets/s", 4000, update_every, RRDSET_TYPE_LINE);
91 st->isdetail = 1;
92
93 - rrd_stats_dimension_add(st, "noroutes", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
94 - rrd_stats_dimension_add(st, "trunkated", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
93 + rrddim_add(st, "noroutes", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
94 + rrddim_add(st, "trunkated", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
95 }
96 - else rrd_stats_next(st);
96 + else rrdset_next(st);
97
98 - rrd_stats_dimension_set(st, "noroutes", InNoRoutes);
99 - rrd_stats_dimension_set(st, "trunkated", InTruncatedPkts);
100 - rrd_stats_done(st);
98 + rrddim_set(st, "noroutes", InNoRoutes);
99 + rrddim_set(st, "trunkated", InTruncatedPkts);
100 + rrdset_done(st);
101 }
102
103 // --------------------------------------------------------------------
104
105 if(do_mcast) {
106 - st = rrd_stats_find("ipv4.mcast");
106 + st = rrdset_find("ipv4.mcast");
107 if(!st) {
108 - st = rrd_stats_create("ipv4", "mcast", NULL, "ipv4", "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, CHART_TYPE_AREA);
108 + st = rrdset_create("ipv4", "mcast", NULL, "ipv4", "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, RRDSET_TYPE_AREA);
109 st->isdetail = 1;
110
111 - rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
112 - rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
111 + rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
112 + rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
113 }
114 - else rrd_stats_next(st);
114 + else rrdset_next(st);
115
116 - rrd_stats_dimension_set(st, "sent", OutMcastOctets);
117 - rrd_stats_dimension_set(st, "received", InMcastOctets);
118 - rrd_stats_done(st);
116 + rrddim_set(st, "sent", OutMcastOctets);
117 + rrddim_set(st, "received", InMcastOctets);
118 + rrdset_done(st);
119 }
120
121 // --------------------------------------------------------------------
122
123 if(do_bcast) {
124 - st = rrd_stats_find("ipv4.bcast");
124 + st = rrdset_find("ipv4.bcast");
125 if(!st) {
126 - st = rrd_stats_create("ipv4", "bcast", NULL, "ipv4", "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, CHART_TYPE_AREA);
126 + st = rrdset_create("ipv4", "bcast", NULL, "ipv4", "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, RRDSET_TYPE_AREA);
127 st->isdetail = 1;
128
129 - rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
130 - rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
129 + rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
130 + rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
131 }
132 - else rrd_stats_next(st);
132 + else rrdset_next(st);
133
134 - rrd_stats_dimension_set(st, "sent", OutBcastOctets);
135 - rrd_stats_dimension_set(st, "received", InBcastOctets);
136 - rrd_stats_done(st);
134 + rrddim_set(st, "sent", OutBcastOctets);
135 + rrddim_set(st, "received", InBcastOctets);
136 + rrdset_done(st);
137 }
138
139 // --------------------------------------------------------------------
140
141 if(do_mcast_p) {
142 - st = rrd_stats_find("ipv4.mcastpkts");
142 + st = rrdset_find("ipv4.mcastpkts");
143 if(!st) {
144 - st = rrd_stats_create("ipv4", "mcastpkts", NULL, "ipv4", "IPv4 Multicast Packets", "packets/s", 9500, update_every, CHART_TYPE_LINE);
144 + st = rrdset_create("ipv4", "mcastpkts", NULL, "ipv4", "IPv4 Multicast Packets", "packets/s", 9500, update_every, RRDSET_TYPE_LINE);
145 st->isdetail = 1;
146
147 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
148 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
147 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
148 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
149 }
150 - else rrd_stats_next(st);
150 + else rrdset_next(st);
151
152 - rrd_stats_dimension_set(st, "sent", OutMcastPkts);
153 - rrd_stats_dimension_set(st, "received", InMcastPkts);
154 - rrd_stats_done(st);
152 + rrddim_set(st, "sent", OutMcastPkts);
153 + rrddim_set(st, "received", InMcastPkts);
154 + rrdset_done(st);
155 }
156
157 // --------------------------------------------------------------------
158
159 if(do_bcast_p) {
160 - st = rrd_stats_find("ipv4.bcastpkts");
160 + st = rrdset_find("ipv4.bcastpkts");
161 if(!st) {
162 - st = rrd_stats_create("ipv4", "bcastpkts", NULL, "ipv4", "IPv4 Broadcast Packets", "packets/s", 8500, update_every, CHART_TYPE_LINE);
162 + st = rrdset_create("ipv4", "bcastpkts", NULL, "ipv4", "IPv4 Broadcast Packets", "packets/s", 8500, update_every, RRDSET_TYPE_LINE);
163 st->isdetail = 1;
164
165 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
166 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
165 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
166 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
167 }
168 - else rrd_stats_next(st);
168 + else rrdset_next(st);
169
170 - rrd_stats_dimension_set(st, "sent", OutBcastPkts);
171 - rrd_stats_dimension_set(st, "received", InBcastPkts);
172 - rrd_stats_done(st);
170 + rrddim_set(st, "sent", OutBcastPkts);
171 + rrddim_set(st, "received", InBcastPkts);
172 + rrdset_done(st);
173 }
174 }
175 }
src/proc_net_rpc_nfsd.c
+141 -141
@@ -406,280 +406,280 @@ int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
406 }
407 }
408
409 - RRD_STATS *st;
409 + RRDSET *st;
410
411 // --------------------------------------------------------------------
412
413 if(do_rc == 2) {
414 - st = rrd_stats_find_bytype("nfsd", "readcache");
414 + st = rrdset_find_bytype("nfsd", "readcache");
415 if(!st) {
416 - st = rrd_stats_create("nfsd", "readcache", NULL, "nfsd", "Read Cache", "reads/s", 5000, update_every, CHART_TYPE_STACKED);
416 + st = rrdset_create("nfsd", "readcache", NULL, "nfsd", "Read Cache", "reads/s", 5000, update_every, RRDSET_TYPE_STACKED);
417
418 - rrd_stats_dimension_add(st, "hits", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
419 - rrd_stats_dimension_add(st, "misses", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
420 - rrd_stats_dimension_add(st, "nocache", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
418 + rrddim_add(st, "hits", NULL, 1, update_every, RRDDIM_INCREMENTAL);
419 + rrddim_add(st, "misses", NULL, 1, update_every, RRDDIM_INCREMENTAL);
420 + rrddim_add(st, "nocache", NULL, 1, update_every, RRDDIM_INCREMENTAL);
421 }
422 - else rrd_stats_next(st);
422 + else rrdset_next(st);
423
424 - rrd_stats_dimension_set(st, "hits", rc_hits);
425 - rrd_stats_dimension_set(st, "misses", rc_misses);
426 - rrd_stats_dimension_set(st, "nocache", rc_nocache);
427 - rrd_stats_done(st);
424 + rrddim_set(st, "hits", rc_hits);
425 + rrddim_set(st, "misses", rc_misses);
426 + rrddim_set(st, "nocache", rc_nocache);
427 + rrdset_done(st);
428 }
429
430 // --------------------------------------------------------------------
431
432 if(do_fh == 2) {
433 - st = rrd_stats_find_bytype("nfsd", "filehandles");
433 + st = rrdset_find_bytype("nfsd", "filehandles");
434 if(!st) {
435 - st = rrd_stats_create("nfsd", "filehandles", NULL, "nfsd", "File Handles", "handles/s", 5001, update_every, CHART_TYPE_LINE);
435 + st = rrdset_create("nfsd", "filehandles", NULL, "nfsd", "File Handles", "handles/s", 5001, update_every, RRDSET_TYPE_LINE);
436 st->isdetail = 1;
437
438 - rrd_stats_dimension_add(st, "stale", NULL, 1, update_every, RRD_DIMENSION_ABSOLUTE);
439 - rrd_stats_dimension_add(st, "total_lookups", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
440 - rrd_stats_dimension_add(st, "anonymous_lookups", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
441 - rrd_stats_dimension_add(st, "dir_not_in_dcache", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
442 - rrd_stats_dimension_add(st, "non_dir_not_in_dcache", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
438 + rrddim_add(st, "stale", NULL, 1, update_every, RRDDIM_ABSOLUTE);
439 + rrddim_add(st, "total_lookups", NULL, 1, update_every, RRDDIM_INCREMENTAL);
440 + rrddim_add(st, "anonymous_lookups", NULL, 1, update_every, RRDDIM_INCREMENTAL);
441 + rrddim_add(st, "dir_not_in_dcache", NULL, -1, update_every, RRDDIM_INCREMENTAL);
442 + rrddim_add(st, "non_dir_not_in_dcache", NULL, -1, update_every, RRDDIM_INCREMENTAL);
443 }
444 - else rrd_stats_next(st);
445 -
446 - rrd_stats_dimension_set(st, "stale", fh_stale);
447 - rrd_stats_dimension_set(st, "total_lookups", fh_total_lookups);
448 - rrd_stats_dimension_set(st, "anonymous_lookups", fh_anonymous_lookups);
449 - rrd_stats_dimension_set(st, "dir_not_in_dcache", fh_dir_not_in_dcache);
450 - rrd_stats_dimension_set(st, "non_dir_not_in_dcache", fh_non_dir_not_in_dcache);
451 - rrd_stats_done(st);
444 + else rrdset_next(st);
445 +
446 + rrddim_set(st, "stale", fh_stale);
447 + rrddim_set(st, "total_lookups", fh_total_lookups);
448 + rrddim_set(st, "anonymous_lookups", fh_anonymous_lookups);
449 + rrddim_set(st, "dir_not_in_dcache", fh_dir_not_in_dcache);
450 + rrddim_set(st, "non_dir_not_in_dcache", fh_non_dir_not_in_dcache);
451 + rrdset_done(st);
452 }
453
454 // --------------------------------------------------------------------
455
456 if(do_io == 2) {
457 - st = rrd_stats_find_bytype("nfsd", "io");
457 + st = rrdset_find_bytype("nfsd", "io");
458 if(!st) {
459 - st = rrd_stats_create("nfsd", "io", NULL, "nfsd", "I/O", "kilobytes/s", 5002, update_every, CHART_TYPE_AREA);
459 + st = rrdset_create("nfsd", "io", NULL, "nfsd", "I/O", "kilobytes/s", 5002, update_every, RRDSET_TYPE_AREA);
460
461 - rrd_stats_dimension_add(st, "read", NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
462 - rrd_stats_dimension_add(st, "write", NULL, -1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
461 + rrddim_add(st, "read", NULL, 1, 1000 * update_every, RRDDIM_INCREMENTAL);
462 + rrddim_add(st, "write", NULL, -1, 1000 * update_every, RRDDIM_INCREMENTAL);
463 }
464 - else rrd_stats_next(st);
464 + else rrdset_next(st);
465
466 - rrd_stats_dimension_set(st, "read", io_read);
467 - rrd_stats_dimension_set(st, "write", io_write);
468 - rrd_stats_done(st);
466 + rrddim_set(st, "read", io_read);
467 + rrddim_set(st, "write", io_write);
468 + rrdset_done(st);
469 }
470
471 // --------------------------------------------------------------------
472
473 if(do_th == 2) {
474 - st = rrd_stats_find_bytype("nfsd", "threads");
474 + st = rrdset_find_bytype("nfsd", "threads");
475 if(!st) {
476 - st = rrd_stats_create("nfsd", "threads", NULL, "nfsd", "Threads", "threads", 5003, update_every, CHART_TYPE_LINE);
476 + st = rrdset_create("nfsd", "threads", NULL, "nfsd", "Threads", "threads", 5003, update_every, RRDSET_TYPE_LINE);
477
478 - rrd_stats_dimension_add(st, "threads", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
478 + rrddim_add(st, "threads", NULL, 1, 1, RRDDIM_ABSOLUTE);
479 }
480 - else rrd_stats_next(st);
480 + else rrdset_next(st);
481
482 - rrd_stats_dimension_set(st, "threads", th_threads);
483 - rrd_stats_done(st);
482 + rrddim_set(st, "threads", th_threads);
483 + rrdset_done(st);
484
485 - st = rrd_stats_find_bytype("nfsd", "threads_fullcnt");
485 + st = rrdset_find_bytype("nfsd", "threads_fullcnt");
486 if(!st) {
487 - st = rrd_stats_create("nfsd", "threads_fullcnt", NULL, "nfsd", "Threads Full Count", "ops/s", 5004, update_every, CHART_TYPE_LINE);
487 + st = rrdset_create("nfsd", "threads_fullcnt", NULL, "nfsd", "Threads Full Count", "ops/s", 5004, update_every, RRDSET_TYPE_LINE);
488
489 - rrd_stats_dimension_add(st, "full_count", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
489 + rrddim_add(st, "full_count", NULL, 1, update_every, RRDDIM_INCREMENTAL);
490 }
491 - else rrd_stats_next(st);
491 + else rrdset_next(st);
492
493 - rrd_stats_dimension_set(st, "full_count", th_fullcnt);
494 - rrd_stats_done(st);
493 + rrddim_set(st, "full_count", th_fullcnt);
494 + rrdset_done(st);
495
496 - st = rrd_stats_find_bytype("nfsd", "threads_histogram");
496 + st = rrdset_find_bytype("nfsd", "threads_histogram");
497 if(!st) {
498 - st = rrd_stats_create("nfsd", "threads_histogram", NULL, "nfsd", "Threads Usage Histogram", "percentage", 5005, update_every, CHART_TYPE_LINE);
499 -
500 - rrd_stats_dimension_add(st, "0%-10%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
501 - rrd_stats_dimension_add(st, "10%-20%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
502 - rrd_stats_dimension_add(st, "20%-30%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
503 - rrd_stats_dimension_add(st, "30%-40%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
504 - rrd_stats_dimension_add(st, "40%-50%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
505 - rrd_stats_dimension_add(st, "50%-60%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
506 - rrd_stats_dimension_add(st, "60%-70%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
507 - rrd_stats_dimension_add(st, "70%-80%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
508 - rrd_stats_dimension_add(st, "80%-90%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
509 - rrd_stats_dimension_add(st, "90%-100%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
498 + st = rrdset_create("nfsd", "threads_histogram", NULL, "nfsd", "Threads Usage Histogram", "percentage", 5005, update_every, RRDSET_TYPE_LINE);
499 +
500 + rrddim_add(st, "0%-10%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
501 + rrddim_add(st, "10%-20%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
502 + rrddim_add(st, "20%-30%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
503 + rrddim_add(st, "30%-40%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
504 + rrddim_add(st, "40%-50%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
505 + rrddim_add(st, "50%-60%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
506 + rrddim_add(st, "60%-70%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
507 + rrddim_add(st, "70%-80%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
508 + rrddim_add(st, "80%-90%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
509 + rrddim_add(st, "90%-100%", NULL, 1, 1000, RRDDIM_ABSOLUTE);
510 }
511 - else rrd_stats_next(st);
512 -
513 - rrd_stats_dimension_set(st, "0%-10%", th_hist10);
514 - rrd_stats_dimension_set(st, "10%-20%", th_hist20);
515 - rrd_stats_dimension_set(st, "20%-30%", th_hist30);
516 - rrd_stats_dimension_set(st, "30%-40%", th_hist40);
517 - rrd_stats_dimension_set(st, "40%-50%", th_hist50);
518 - rrd_stats_dimension_set(st, "50%-60%", th_hist60);
519 - rrd_stats_dimension_set(st, "60%-70%", th_hist70);
520 - rrd_stats_dimension_set(st, "70%-80%", th_hist80);
521 - rrd_stats_dimension_set(st, "80%-90%", th_hist90);
522 - rrd_stats_dimension_set(st, "90%-100%", th_hist100);
523 - rrd_stats_done(st);
511 + else rrdset_next(st);
512 +
513 + rrddim_set(st, "0%-10%", th_hist10);
514 + rrddim_set(st, "10%-20%", th_hist20);
515 + rrddim_set(st, "20%-30%", th_hist30);
516 + rrddim_set(st, "30%-40%", th_hist40);
517 + rrddim_set(st, "40%-50%", th_hist50);
518 + rrddim_set(st, "50%-60%", th_hist60);
519 + rrddim_set(st, "60%-70%", th_hist70);
520 + rrddim_set(st, "70%-80%", th_hist80);
521 + rrddim_set(st, "80%-90%", th_hist90);
522 + rrddim_set(st, "90%-100%", th_hist100);
523 + rrdset_done(st);
524 }
525
526 // --------------------------------------------------------------------
527
528 if(do_ra == 2) {
529 - st = rrd_stats_find_bytype("nfsd", "readahead");
529 + st = rrdset_find_bytype("nfsd", "readahead");
530 if(!st) {
531 - st = rrd_stats_create("nfsd", "readahead", NULL, "nfsd", "Read Ahead Depth", "percentage", 5005, update_every, CHART_TYPE_STACKED);
532 -
533 - rrd_stats_dimension_add(st, "10%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
534 - rrd_stats_dimension_add(st, "20%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
535 - rrd_stats_dimension_add(st, "30%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
536 - rrd_stats_dimension_add(st, "40%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
537 - rrd_stats_dimension_add(st, "50%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
538 - rrd_stats_dimension_add(st, "60%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
539 - rrd_stats_dimension_add(st, "70%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
540 - rrd_stats_dimension_add(st, "80%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
541 - rrd_stats_dimension_add(st, "90%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
542 - rrd_stats_dimension_add(st, "100%", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
543 - rrd_stats_dimension_add(st, "misses", NULL, 1, update_every, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
531 + st = rrdset_create("nfsd", "readahead", NULL, "nfsd", "Read Ahead Depth", "percentage", 5005, update_every, RRDSET_TYPE_STACKED);
532 +
533 + rrddim_add(st, "10%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
534 + rrddim_add(st, "20%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
535 + rrddim_add(st, "30%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
536 + rrddim_add(st, "40%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
537 + rrddim_add(st, "50%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
538 + rrddim_add(st, "60%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
539 + rrddim_add(st, "70%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
540 + rrddim_add(st, "80%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
541 + rrddim_add(st, "90%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
542 + rrddim_add(st, "100%", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
543 + rrddim_add(st, "misses", NULL, 1, update_every, RRDDIM_PCENT_OVER_DIFF_TOTAL);
544 }
545 - else rrd_stats_next(st);
545 + else rrdset_next(st);
546
547 // ignore ra_size
548 if(ra_size) {};
549
550 - rrd_stats_dimension_set(st, "10%", ra_hist10);
551 - rrd_stats_dimension_set(st, "20%", ra_hist20);
552 - rrd_stats_dimension_set(st, "30%", ra_hist30);
553 - rrd_stats_dimension_set(st, "40%", ra_hist40);
554 - rrd_stats_dimension_set(st, "50%", ra_hist50);
555 - rrd_stats_dimension_set(st, "60%", ra_hist60);
556 - rrd_stats_dimension_set(st, "70%", ra_hist70);
557 - rrd_stats_dimension_set(st, "80%", ra_hist80);
558 - rrd_stats_dimension_set(st, "90%", ra_hist90);
559 - rrd_stats_dimension_set(st, "100%", ra_hist100);
560 - rrd_stats_dimension_set(st, "misses", ra_none);
561 - rrd_stats_done(st);
550 + rrddim_set(st, "10%", ra_hist10);
551 + rrddim_set(st, "20%", ra_hist20);
552 + rrddim_set(st, "30%", ra_hist30);
553 + rrddim_set(st, "40%", ra_hist40);
554 + rrddim_set(st, "50%", ra_hist50);
555 + rrddim_set(st, "60%", ra_hist60);
556 + rrddim_set(st, "70%", ra_hist70);
557 + rrddim_set(st, "80%", ra_hist80);
558 + rrddim_set(st, "90%", ra_hist90);
559 + rrddim_set(st, "100%", ra_hist100);
560 + rrddim_set(st, "misses", ra_none);
561 + rrdset_done(st);
562 }
563
564 // --------------------------------------------------------------------
565
566 if(do_net == 2) {
567 - st = rrd_stats_find_bytype("nfsd", "net");
567 + st = rrdset_find_bytype("nfsd", "net");
568 if(!st) {
569 - st = rrd_stats_create("nfsd", "net", NULL, "nfsd", "Network Reads", "reads/s", 5007, update_every, CHART_TYPE_STACKED);
569 + st = rrdset_create("nfsd", "net", NULL, "nfsd", "Network Reads", "reads/s", 5007, update_every, RRDSET_TYPE_STACKED);
570 st->isdetail = 1;
571
572 - rrd_stats_dimension_add(st, "udp", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
573 - rrd_stats_dimension_add(st, "tcp", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
572 + rrddim_add(st, "udp", NULL, 1, update_every, RRDDIM_INCREMENTAL);
573 + rrddim_add(st, "tcp", NULL, 1, update_every, RRDDIM_INCREMENTAL);
574 }
575 - else rrd_stats_next(st);
575 + else rrdset_next(st);
576
577 // ignore net_count, net_tcp_connections
578 if(net_count) {};
579 if(net_tcp_connections) {};
580
581 - rrd_stats_dimension_set(st, "udp", net_udp_count);
582 - rrd_stats_dimension_set(st, "tcp", net_tcp_count);
583 - rrd_stats_done(st);
581 + rrddim_set(st, "udp", net_udp_count);
582 + rrddim_set(st, "tcp", net_tcp_count);
583 + rrdset_done(st);
584 }
585
586 // --------------------------------------------------------------------
587
588 if(do_rpc == 2) {
589 - st = rrd_stats_find_bytype("nfsd", "rpc");
589 + st = rrdset_find_bytype("nfsd", "rpc");
590 if(!st) {
591 - st = rrd_stats_create("nfsd", "rpc", NULL, "nfsd", "Remote Procedure Calls", "calls/s", 5008, update_every, CHART_TYPE_LINE);
591 + st = rrdset_create("nfsd", "rpc", NULL, "nfsd", "Remote Procedure Calls", "calls/s", 5008, update_every, RRDSET_TYPE_LINE);
592 st->isdetail = 1;
593
594 - rrd_stats_dimension_add(st, "all", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
595 - rrd_stats_dimension_add(st, "bad_format", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
596 - rrd_stats_dimension_add(st, "bad_auth", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
594 + rrddim_add(st, "all", NULL, 1, update_every, RRDDIM_INCREMENTAL);
595 + rrddim_add(st, "bad_format", NULL, -1, update_every, RRDDIM_INCREMENTAL);
596 + rrddim_add(st, "bad_auth", NULL, -1, update_every, RRDDIM_INCREMENTAL);
597 }
598 - else rrd_stats_next(st);
598 + else rrdset_next(st);
599
600 // ignore rpc_bad_client
601 if(rpc_bad_client) {};
602
603 - rrd_stats_dimension_set(st, "all", rpc_count);
604 - rrd_stats_dimension_set(st, "bad_format", rpc_bad_format);
605 - rrd_stats_dimension_set(st, "bad_auth", rpc_bad_auth);
606 - rrd_stats_done(st);
603 + rrddim_set(st, "all", rpc_count);
604 + rrddim_set(st, "bad_format", rpc_bad_format);
605 + rrddim_set(st, "bad_auth", rpc_bad_auth);
606 + rrdset_done(st);
607 }
608
609 // --------------------------------------------------------------------
610
611 if(do_proc2 == 2) {
612 unsigned int i;
613 - st = rrd_stats_find_bytype("nfsd", "proc2");
613 + st = rrdset_find_bytype("nfsd", "proc2");
614 if(!st) {
615 - st = rrd_stats_create("nfsd", "proc2", NULL, "nfsd", "NFS v2 Calls", "calls/s", 5009, update_every, CHART_TYPE_STACKED);
615 + st = rrdset_create("nfsd", "proc2", NULL, "nfsd", "NFS v2 Calls", "calls/s", 5009, update_every, RRDSET_TYPE_STACKED);
616
617 for(i = 0; nfsd_proc_values[i].present2 ; i++)
618 - rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
618 + rrddim_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRDDIM_INCREMENTAL);
619 }
620 - else rrd_stats_next(st);
620 + else rrdset_next(st);
621
622 for(i = 0; nfsd_proc_values[i].present2 ; i++)
623 - rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc2);
623 + rrddim_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc2);
624
625 - rrd_stats_done(st);
625 + rrdset_done(st);
626 }
627
628 // --------------------------------------------------------------------
629
630 if(do_proc3 == 2) {
631 unsigned int i;
632 - st = rrd_stats_find_bytype("nfsd", "proc3");
632 + st = rrdset_find_bytype("nfsd", "proc3");
633 if(!st) {
634 - st = rrd_stats_create("nfsd", "proc3", NULL, "nfsd", "NFS v3 Calls", "calls/s", 5010, update_every, CHART_TYPE_STACKED);
634 + st = rrdset_create("nfsd", "proc3", NULL, "nfsd", "NFS v3 Calls", "calls/s", 5010, update_every, RRDSET_TYPE_STACKED);
635
636 for(i = 0; nfsd_proc_values[i].present3 ; i++)
637 - rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
637 + rrddim_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRDDIM_INCREMENTAL);
638 }
639 - else rrd_stats_next(st);
639 + else rrdset_next(st);
640
641 for(i = 0; nfsd_proc_values[i].present3 ; i++)
642 - rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc3);
642 + rrddim_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc3);
643
644 - rrd_stats_done(st);
644 + rrdset_done(st);
645 }
646
647 // --------------------------------------------------------------------
648
649 if(do_proc4 == 2) {
650 unsigned int i;
651 - st = rrd_stats_find_bytype("nfsd", "proc4");
651 + st = rrdset_find_bytype("nfsd", "proc4");
652 if(!st) {
653 - st = rrd_stats_create("nfsd", "proc4", NULL, "nfsd", "NFS v4 Calls", "calls/s", 5011, update_every, CHART_TYPE_STACKED);
653 + st = rrdset_create("nfsd", "proc4", NULL, "nfsd", "NFS v4 Calls", "calls/s", 5011, update_every, RRDSET_TYPE_STACKED);
654
655 for(i = 0; nfsd_proc_values[i].present4 ; i++)
656 - rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
656 + rrddim_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRDDIM_INCREMENTAL);
657 }
658 - else rrd_stats_next(st);
658 + else rrdset_next(st);
659
660 for(i = 0; nfsd_proc_values[i].present4 ; i++)
661 - rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc4);
661 + rrddim_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc4);
662
663 - rrd_stats_done(st);
663 + rrdset_done(st);
664 }
665
666 // --------------------------------------------------------------------
667
668 if(do_proc4ops == 2) {
669 unsigned int i;
670 - st = rrd_stats_find_bytype("nfsd", "proc4ops");
670 + st = rrdset_find_bytype("nfsd", "proc4ops");
671 if(!st) {
672 - st = rrd_stats_create("nfsd", "proc4ops", NULL, "nfsd", "NFS v4 Operations", "operations/s", 5012, update_every, CHART_TYPE_STACKED);
672 + st = rrdset_create("nfsd", "proc4ops", NULL, "nfsd", "NFS v4 Operations", "operations/s", 5012, update_every, RRDSET_TYPE_STACKED);
673
674 for(i = 0; nfsd4_ops_values[i].present ; i++)
675 - rrd_stats_dimension_add(st, nfsd4_ops_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
675 + rrddim_add(st, nfsd4_ops_values[i].name, NULL, 1, update_every, RRDDIM_INCREMENTAL);
676 }
677 - else rrd_stats_next(st);
677 + else rrdset_next(st);
678
679 for(i = 0; nfsd4_ops_values[i].present ; i++)
680 - rrd_stats_dimension_set(st, nfsd4_ops_values[i].name, nfsd4_ops_values[i].value);
680 + rrddim_set(st, nfsd4_ops_values[i].name, nfsd4_ops_values[i].value);
681
682 - rrd_stats_done(st);
682 + rrdset_done(st);
683 }
684
685 return 0;
src/proc_net_snmp.c
+105 -105
@@ -40,7 +40,7 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
40 uint32_t lines = procfile_lines(ff), l;
41 uint32_t words;
42
43 - RRD_STATS *st;
43 + RRDSET *st;
44
45 for(l = 0; l < lines ;l++) {
46 if(strcmp(procfile_lineword(ff, l, 0), "Ip") == 0) {
@@ -92,88 +92,88 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
92 // --------------------------------------------------------------------
93
94 if(do_ip_packets) {
95 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".packets");
95 + st = rrdset_find(RRD_TYPE_NET_SNMP ".packets");
96 if(!st) {
97 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "packets", NULL, RRD_TYPE_NET_SNMP, "IPv4 Packets", "packets/s", 3000, update_every, CHART_TYPE_LINE);
97 + st = rrdset_create(RRD_TYPE_NET_SNMP, "packets", NULL, RRD_TYPE_NET_SNMP, "IPv4 Packets", "packets/s", 3000, update_every, RRDSET_TYPE_LINE);
98
99 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
100 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
101 - rrd_stats_dimension_add(st, "forwarded", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
99 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
100 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
101 + rrddim_add(st, "forwarded", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
102 }
103 - else rrd_stats_next(st);
103 + else rrdset_next(st);
104
105 - rrd_stats_dimension_set(st, "sent", OutRequests);
106 - rrd_stats_dimension_set(st, "received", InReceives);
107 - rrd_stats_dimension_set(st, "forwarded", ForwDatagrams);
108 - rrd_stats_done(st);
105 + rrddim_set(st, "sent", OutRequests);
106 + rrddim_set(st, "received", InReceives);
107 + rrddim_set(st, "forwarded", ForwDatagrams);
108 + rrdset_done(st);
109 }
110
111 // --------------------------------------------------------------------
112
113 if(do_ip_fragsout) {
114 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".fragsout");
114 + st = rrdset_find(RRD_TYPE_NET_SNMP ".fragsout");
115 if(!st) {
116 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "fragsout", NULL, RRD_TYPE_NET_SNMP, "IPv4 Fragments Sent", "packets/s", 3010, update_every, CHART_TYPE_LINE);
116 + st = rrdset_create(RRD_TYPE_NET_SNMP, "fragsout", NULL, RRD_TYPE_NET_SNMP, "IPv4 Fragments Sent", "packets/s", 3010, update_every, RRDSET_TYPE_LINE);
117 st->isdetail = 1;
118
119 - rrd_stats_dimension_add(st, "ok", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
120 - rrd_stats_dimension_add(st, "failed", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
121 - rrd_stats_dimension_add(st, "all", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
119 + rrddim_add(st, "ok", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
120 + rrddim_add(st, "failed", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
121 + rrddim_add(st, "all", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
122 }
123 - else rrd_stats_next(st);
123 + else rrdset_next(st);
124
125 - rrd_stats_dimension_set(st, "ok", FragOKs);
126 - rrd_stats_dimension_set(st, "failed", FragFails);
127 - rrd_stats_dimension_set(st, "all", FragCreates);
128 - rrd_stats_done(st);
125 + rrddim_set(st, "ok", FragOKs);
126 + rrddim_set(st, "failed", FragFails);
127 + rrddim_set(st, "all", FragCreates);
128 + rrdset_done(st);
129 }
130
131 // --------------------------------------------------------------------
132
133 if(do_ip_fragsin) {
134 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".fragsin");
134 + st = rrdset_find(RRD_TYPE_NET_SNMP ".fragsin");
135 if(!st) {
136 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "fragsin", NULL, RRD_TYPE_NET_SNMP, "IPv4 Fragments Reassembly", "packets/s", 3011, update_every, CHART_TYPE_LINE);
136 + st = rrdset_create(RRD_TYPE_NET_SNMP, "fragsin", NULL, RRD_TYPE_NET_SNMP, "IPv4 Fragments Reassembly", "packets/s", 3011, update_every, RRDSET_TYPE_LINE);
137 st->isdetail = 1;
138
139 - rrd_stats_dimension_add(st, "ok", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
140 - rrd_stats_dimension_add(st, "failed", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
141 - rrd_stats_dimension_add(st, "all", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
139 + rrddim_add(st, "ok", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
140 + rrddim_add(st, "failed", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
141 + rrddim_add(st, "all", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
142 }
143 - else rrd_stats_next(st);
143 + else rrdset_next(st);
144
145 - rrd_stats_dimension_set(st, "ok", ReasmOKs);
146 - rrd_stats_dimension_set(st, "failed", ReasmFails);
147 - rrd_stats_dimension_set(st, "all", ReasmReqds);
148 - rrd_stats_done(st);
145 + rrddim_set(st, "ok", ReasmOKs);
146 + rrddim_set(st, "failed", ReasmFails);
147 + rrddim_set(st, "all", ReasmReqds);
148 + rrdset_done(st);
149 }
150
151 // --------------------------------------------------------------------
152
153 if(do_ip_errors) {
154 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".errors");
154 + st = rrdset_find(RRD_TYPE_NET_SNMP ".errors");
155 if(!st) {
156 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "errors", NULL, RRD_TYPE_NET_SNMP, "IPv4 Errors", "packets/s", 3002, update_every, CHART_TYPE_LINE);
156 + st = rrdset_create(RRD_TYPE_NET_SNMP, "errors", NULL, RRD_TYPE_NET_SNMP, "IPv4 Errors", "packets/s", 3002, update_every, RRDSET_TYPE_LINE);
157 st->isdetail = 1;
158
159 - rrd_stats_dimension_add(st, "InDiscards", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
160 - rrd_stats_dimension_add(st, "OutDiscards", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
159 + rrddim_add(st, "InDiscards", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
160 + rrddim_add(st, "OutDiscards", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
161
162 - rrd_stats_dimension_add(st, "InHdrErrors", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
163 - rrd_stats_dimension_add(st, "InAddrErrors", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
164 - rrd_stats_dimension_add(st, "InUnknownProtos", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
162 + rrddim_add(st, "InHdrErrors", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
163 + rrddim_add(st, "InAddrErrors", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
164 + rrddim_add(st, "InUnknownProtos", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
165
166 - rrd_stats_dimension_add(st, "OutNoRoutes", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
166 + rrddim_add(st, "OutNoRoutes", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
167 }
168 - else rrd_stats_next(st);
169 -
170 - rrd_stats_dimension_set(st, "InDiscards", InDiscards);
171 - rrd_stats_dimension_set(st, "OutDiscards", OutDiscards);
172 - rrd_stats_dimension_set(st, "InHdrErrors", InHdrErrors);
173 - rrd_stats_dimension_set(st, "InAddrErrors", InAddrErrors);
174 - rrd_stats_dimension_set(st, "InUnknownProtos", InUnknownProtos);
175 - rrd_stats_dimension_set(st, "OutNoRoutes", OutNoRoutes);
176 - rrd_stats_done(st);
168 + else rrdset_next(st);
169 +
170 + rrddim_set(st, "InDiscards", InDiscards);
171 + rrddim_set(st, "OutDiscards", OutDiscards);
172 + rrddim_set(st, "InHdrErrors", InHdrErrors);
173 + rrddim_set(st, "InAddrErrors", InAddrErrors);
174 + rrddim_set(st, "InUnknownProtos", InUnknownProtos);
175 + rrddim_set(st, "OutNoRoutes", OutNoRoutes);
176 + rrdset_done(st);
177 }
178 }
179 else if(strcmp(procfile_lineword(ff, l, 0), "Tcp") == 0) {
@@ -218,75 +218,75 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
218
219 // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
220 if(do_tcp_sockets) {
221 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcpsock");
221 + st = rrdset_find(RRD_TYPE_NET_SNMP ".tcpsock");
222 if(!st) {
223 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcpsock", NULL, "tcp", "IPv4 TCP Connections", "active connections", 2500, update_every, CHART_TYPE_LINE);
223 + st = rrdset_create(RRD_TYPE_NET_SNMP, "tcpsock", NULL, "tcp", "IPv4 TCP Connections", "active connections", 2500, update_every, RRDSET_TYPE_LINE);
224
225 - rrd_stats_dimension_add(st, "connections", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
225 + rrddim_add(st, "connections", NULL, 1, 1, RRDDIM_ABSOLUTE);
226 }
227 - else rrd_stats_next(st);
227 + else rrdset_next(st);
228
229 - rrd_stats_dimension_set(st, "connections", CurrEstab);
230 - rrd_stats_done(st);
229 + rrddim_set(st, "connections", CurrEstab);
230 + rrdset_done(st);
231 }
232
233 // --------------------------------------------------------------------
234
235 if(do_tcp_packets) {
236 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcppackets");
236 + st = rrdset_find(RRD_TYPE_NET_SNMP ".tcppackets");
237 if(!st) {
238 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcppackets", NULL, "tcp", "IPv4 TCP Packets", "packets/s", 2600, update_every, CHART_TYPE_LINE);
238 + st = rrdset_create(RRD_TYPE_NET_SNMP, "tcppackets", NULL, "tcp", "IPv4 TCP Packets", "packets/s", 2600, update_every, RRDSET_TYPE_LINE);
239
240 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
241 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
240 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
241 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
242 }
243 - else rrd_stats_next(st);
243 + else rrdset_next(st);
244
245 - rrd_stats_dimension_set(st, "received", InSegs);
246 - rrd_stats_dimension_set(st, "sent", OutSegs);
247 - rrd_stats_done(st);
245 + rrddim_set(st, "received", InSegs);
246 + rrddim_set(st, "sent", OutSegs);
247 + rrdset_done(st);
248 }
249
250 // --------------------------------------------------------------------
251
252 if(do_tcp_errors) {
253 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcperrors");
253 + st = rrdset_find(RRD_TYPE_NET_SNMP ".tcperrors");
254 if(!st) {
255 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcperrors", NULL, "tcp", "IPv4 TCP Errors", "packets/s", 2700, update_every, CHART_TYPE_LINE);
255 + st = rrdset_create(RRD_TYPE_NET_SNMP, "tcperrors", NULL, "tcp", "IPv4 TCP Errors", "packets/s", 2700, update_every, RRDSET_TYPE_LINE);
256 st->isdetail = 1;
257
258 - rrd_stats_dimension_add(st, "InErrs", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
259 - rrd_stats_dimension_add(st, "RetransSegs", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
258 + rrddim_add(st, "InErrs", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
259 + rrddim_add(st, "RetransSegs", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
260 }
261 - else rrd_stats_next(st);
261 + else rrdset_next(st);
262
263 - rrd_stats_dimension_set(st, "InErrs", InErrs);
264 - rrd_stats_dimension_set(st, "RetransSegs", RetransSegs);
265 - rrd_stats_done(st);
263 + rrddim_set(st, "InErrs", InErrs);
264 + rrddim_set(st, "RetransSegs", RetransSegs);
265 + rrdset_done(st);
266 }
267
268 // --------------------------------------------------------------------
269
270 if(do_tcp_handshake) {
271 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".tcphandshake");
271 + st = rrdset_find(RRD_TYPE_NET_SNMP ".tcphandshake");
272 if(!st) {
273 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "tcphandshake", NULL, "tcp", "IPv4 TCP Handshake Issues", "events/s", 2900, update_every, CHART_TYPE_LINE);
273 + st = rrdset_create(RRD_TYPE_NET_SNMP, "tcphandshake", NULL, "tcp", "IPv4 TCP Handshake Issues", "events/s", 2900, update_every, RRDSET_TYPE_LINE);
274 st->isdetail = 1;
275
276 - rrd_stats_dimension_add(st, "EstabResets", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
277 - rrd_stats_dimension_add(st, "OutRsts", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
278 - rrd_stats_dimension_add(st, "ActiveOpens", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
279 - rrd_stats_dimension_add(st, "PassiveOpens", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
280 - rrd_stats_dimension_add(st, "AttemptFails", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
276 + rrddim_add(st, "EstabResets", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
277 + rrddim_add(st, "OutRsts", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
278 + rrddim_add(st, "ActiveOpens", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
279 + rrddim_add(st, "PassiveOpens", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
280 + rrddim_add(st, "AttemptFails", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
281 }
282 - else rrd_stats_next(st);
283 -
284 - rrd_stats_dimension_set(st, "EstabResets", EstabResets);
285 - rrd_stats_dimension_set(st, "OutRsts", OutRsts);
286 - rrd_stats_dimension_set(st, "ActiveOpens", ActiveOpens);
287 - rrd_stats_dimension_set(st, "PassiveOpens", PassiveOpens);
288 - rrd_stats_dimension_set(st, "AttemptFails", AttemptFails);
289 - rrd_stats_done(st);
282 + else rrdset_next(st);
283 +
284 + rrddim_set(st, "EstabResets", EstabResets);
285 + rrddim_set(st, "OutRsts", OutRsts);
286 + rrddim_set(st, "ActiveOpens", ActiveOpens);
287 + rrddim_set(st, "PassiveOpens", PassiveOpens);
288 + rrddim_set(st, "AttemptFails", AttemptFails);
289 + rrdset_done(st);
290 }
291 }
292 else if(strcmp(procfile_lineword(ff, l, 0), "Udp") == 0) {
@@ -316,40 +316,40 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
316
317 // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
318 if(do_udp_packets) {
319 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".udppackets");
319 + st = rrdset_find(RRD_TYPE_NET_SNMP ".udppackets");
320 if(!st) {
321 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "udppackets", NULL, "udp", "IPv4 UDP Packets", "packets/s", 2601, update_every, CHART_TYPE_LINE);
321 + st = rrdset_create(RRD_TYPE_NET_SNMP, "udppackets", NULL, "udp", "IPv4 UDP Packets", "packets/s", 2601, update_every, RRDSET_TYPE_LINE);
322
323 - rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
324 - rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
323 + rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
324 + rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
325 }
326 - else rrd_stats_next(st);
326 + else rrdset_next(st);
327
328 - rrd_stats_dimension_set(st, "received", InDatagrams);
329 - rrd_stats_dimension_set(st, "sent", OutDatagrams);
330 - rrd_stats_done(st);
328 + rrddim_set(st, "received", InDatagrams);
329 + rrddim_set(st, "sent", OutDatagrams);
330 + rrdset_done(st);
331 }
332
333 // --------------------------------------------------------------------
334
335 if(do_udp_errors) {
336 - st = rrd_stats_find(RRD_TYPE_NET_SNMP ".udperrors");
336 + st = rrdset_find(RRD_TYPE_NET_SNMP ".udperrors");
337 if(!st) {
338 - st = rrd_stats_create(RRD_TYPE_NET_SNMP, "udperrors", NULL, "udp", "IPv4 UDP Errors", "events/s", 2701, update_every, CHART_TYPE_LINE);
338 + st = rrdset_create(RRD_TYPE_NET_SNMP, "udperrors", NULL, "udp", "IPv4 UDP Errors", "events/s", 2701, update_every, RRDSET_TYPE_LINE);
339 st->isdetail = 1;
340
341 - rrd_stats_dimension_add(st, "RcvbufErrors", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
342 - rrd_stats_dimension_add(st, "SndbufErrors", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
343 - rrd_stats_dimension_add(st, "InErrors", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
344 - rrd_stats_dimension_add(st, "NoPorts", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
341 + rrddim_add(st, "RcvbufErrors", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
342 + rrddim_add(st, "SndbufErrors", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
343 + rrddim_add(st, "InErrors", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
344 + rrddim_add(st, "NoPorts", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
345 }
346 - else rrd_stats_next(st);
346 + else rrdset_next(st);
347
348 - rrd_stats_dimension_set(st, "InErrors", InErrors);
349 - rrd_stats_dimension_set(st, "NoPorts", NoPorts);
350 - rrd_stats_dimension_set(st, "RcvbufErrors", RcvbufErrors);
351 - rrd_stats_dimension_set(st, "SndbufErrors", SndbufErrors);
352 - rrd_stats_done(st);
348 + rrddim_set(st, "InErrors", InErrors);
349 + rrddim_set(st, "NoPorts", NoPorts);
350 + rrddim_set(st, "RcvbufErrors", RcvbufErrors);
351 + rrddim_set(st, "SndbufErrors", SndbufErrors);
352 + rrdset_done(st);
353 }
354 }
355 }
src/proc_net_stat_conntrack.c
+59 -59
@@ -85,122 +85,122 @@ int do_proc_net_stat_conntrack(int update_every, unsigned long long dt) {
85 asearch_restart += tsearch_restart; // conntrack.search
86 }
87
88 - RRD_STATS *st;
88 + RRDSET *st;
89
90 // --------------------------------------------------------------------
91
92 if(do_sockets) {
93 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".sockets");
93 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".sockets");
94 if(!st) {
95 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "sockets", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connections", "active connections", 1000, update_every, CHART_TYPE_LINE);
95 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "sockets", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connections", "active connections", 1000, update_every, RRDSET_TYPE_LINE);
96
97 - rrd_stats_dimension_add(st, "connections", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
97 + rrddim_add(st, "connections", NULL, 1, 1, RRDDIM_ABSOLUTE);
98 }
99 - else rrd_stats_next(st);
99 + else rrdset_next(st);
100
101 - rrd_stats_dimension_set(st, "connections", aentries);
102 - rrd_stats_done(st);
101 + rrddim_set(st, "connections", aentries);
102 + rrdset_done(st);
103 }
104
105 // --------------------------------------------------------------------
106
107 if(do_new) {
108 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".new");
108 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".new");
109 if(!st) {
110 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "new", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter New Connections", "connections/s", 1001, update_every, CHART_TYPE_LINE);
110 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "new", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter New Connections", "connections/s", 1001, update_every, RRDSET_TYPE_LINE);
111
112 - rrd_stats_dimension_add(st, "new", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
113 - rrd_stats_dimension_add(st, "ignore", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
114 - rrd_stats_dimension_add(st, "invalid", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
112 + rrddim_add(st, "new", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
113 + rrddim_add(st, "ignore", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
114 + rrddim_add(st, "invalid", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
115 }
116 - else rrd_stats_next(st);
116 + else rrdset_next(st);
117
118 - rrd_stats_dimension_set(st, "new", anew);
119 - rrd_stats_dimension_set(st, "ignore", aignore);
120 - rrd_stats_dimension_set(st, "invalid", ainvalid);
121 - rrd_stats_done(st);
118 + rrddim_set(st, "new", anew);
119 + rrddim_set(st, "ignore", aignore);
120 + rrddim_set(st, "invalid", ainvalid);
121 + rrdset_done(st);
122 }
123
124 // --------------------------------------------------------------------
125
126 if(do_changes) {
127 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".changes");
127 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".changes");
128 if(!st) {
129 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "changes", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Changes", "changes/s", 1002, update_every, CHART_TYPE_LINE);
129 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "changes", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Changes", "changes/s", 1002, update_every, RRDSET_TYPE_LINE);
130 st->isdetail = 1;
131
132 - rrd_stats_dimension_add(st, "inserted", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
133 - rrd_stats_dimension_add(st, "deleted", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
134 - rrd_stats_dimension_add(st, "delete_list", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
132 + rrddim_add(st, "inserted", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
133 + rrddim_add(st, "deleted", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
134 + rrddim_add(st, "delete_list", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
135 }
136 - else rrd_stats_next(st);
136 + else rrdset_next(st);
137
138 - rrd_stats_dimension_set(st, "inserted", ainsert);
139 - rrd_stats_dimension_set(st, "deleted", adelete);
140 - rrd_stats_dimension_set(st, "delete_list", adelete_list);
141 - rrd_stats_done(st);
138 + rrddim_set(st, "inserted", ainsert);
139 + rrddim_set(st, "deleted", adelete);
140 + rrddim_set(st, "delete_list", adelete_list);
141 + rrdset_done(st);
142 }
143
144 // --------------------------------------------------------------------
145
146 if(do_expect) {
147 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".expect");
147 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".expect");
148 if(!st) {
149 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "expect", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Expectations", "expectations/s", 1003, update_every, CHART_TYPE_LINE);
149 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "expect", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Expectations", "expectations/s", 1003, update_every, RRDSET_TYPE_LINE);
150 st->isdetail = 1;
151
152 - rrd_stats_dimension_add(st, "created", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
153 - rrd_stats_dimension_add(st, "deleted", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
154 - rrd_stats_dimension_add(st, "new", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
152 + rrddim_add(st, "created", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
153 + rrddim_add(st, "deleted", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
154 + rrddim_add(st, "new", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
155 }
156 - else rrd_stats_next(st);
156 + else rrdset_next(st);
157
158 - rrd_stats_dimension_set(st, "created", aexpect_create);
159 - rrd_stats_dimension_set(st, "deleted", aexpect_delete);
160 - rrd_stats_dimension_set(st, "new", aexpect_new);
161 - rrd_stats_done(st);
158 + rrddim_set(st, "created", aexpect_create);
159 + rrddim_set(st, "deleted", aexpect_delete);
160 + rrddim_set(st, "new", aexpect_new);
161 + rrdset_done(st);
162 }
163
164 // --------------------------------------------------------------------
165
166 if(do_search) {
167 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".search");
167 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".search");
168 if(!st) {
169 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "search", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Searches", "searches/s", 1010, update_every, CHART_TYPE_LINE);
169 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "search", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Connection Searches", "searches/s", 1010, update_every, RRDSET_TYPE_LINE);
170 st->isdetail = 1;
171
172 - rrd_stats_dimension_add(st, "searched", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
173 - rrd_stats_dimension_add(st, "restarted", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
174 - rrd_stats_dimension_add(st, "found", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
172 + rrddim_add(st, "searched", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
173 + rrddim_add(st, "restarted", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
174 + rrddim_add(st, "found", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
175 }
176 - else rrd_stats_next(st);
176 + else rrdset_next(st);
177
178 - rrd_stats_dimension_set(st, "searched", asearched);
179 - rrd_stats_dimension_set(st, "restarted", asearch_restart);
180 - rrd_stats_dimension_set(st, "found", afound);
181 - rrd_stats_done(st);
178 + rrddim_set(st, "searched", asearched);
179 + rrddim_set(st, "restarted", asearch_restart);
180 + rrddim_set(st, "found", afound);
181 + rrdset_done(st);
182 }
183
184 // --------------------------------------------------------------------
185
186 if(do_errors) {
187 - st = rrd_stats_find(RRD_TYPE_NET_STAT_CONNTRACK ".errors");
187 + st = rrdset_find(RRD_TYPE_NET_STAT_CONNTRACK ".errors");
188 if(!st) {
189 - st = rrd_stats_create(RRD_TYPE_NET_STAT_CONNTRACK, "errors", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Errors", "events/s", 1005, update_every, CHART_TYPE_LINE);
189 + st = rrdset_create(RRD_TYPE_NET_STAT_CONNTRACK, "errors", NULL, RRD_TYPE_NET_STAT_CONNTRACK, "Netfilter Errors", "events/s", 1005, update_every, RRDSET_TYPE_LINE);
190 st->isdetail = 1;
191
192 - rrd_stats_dimension_add(st, "icmp_error", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
193 - rrd_stats_dimension_add(st, "insert_failed", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
194 - rrd_stats_dimension_add(st, "drop", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
195 - rrd_stats_dimension_add(st, "early_drop", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
192 + rrddim_add(st, "icmp_error", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
193 + rrddim_add(st, "insert_failed", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
194 + rrddim_add(st, "drop", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
195 + rrddim_add(st, "early_drop", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
196 }
197 - else rrd_stats_next(st);
197 + else rrdset_next(st);
198
199 - rrd_stats_dimension_set(st, "icmp_error", aicmp_error);
200 - rrd_stats_dimension_set(st, "insert_failed", ainsert_failed);
201 - rrd_stats_dimension_set(st, "drop", adrop);
202 - rrd_stats_dimension_set(st, "early_drop", aearly_drop);
203 - rrd_stats_done(st);
199 + rrddim_set(st, "icmp_error", aicmp_error);
200 + rrddim_set(st, "insert_failed", ainsert_failed);
201 + rrddim_set(st, "drop", adrop);
202 + rrddim_set(st, "early_drop", aearly_drop);
203 + rrdset_done(st);
204 }
205
206 return 0;
src/proc_stat.c
+54 -54
@@ -35,7 +35,7 @@ int do_proc_stat(int update_every, unsigned long long dt) {
35 uint32_t words;
36
37 unsigned long long processes = 0, running = 0 , blocked = 0;
38 - RRD_STATS *st;
38 + RRDSET *st;
39
40 for(l = 0; l < lines ;l++) {
41 if(strncmp(procfile_lineword(ff, l, 0), "cpu", 3) == 0) {
@@ -72,39 +72,39 @@ int do_proc_stat(int update_every, unsigned long long dt) {
72 }
73
74 if((isthistotal && do_cpu) || (!isthistotal && do_cpu_cores)) {
75 - st = rrd_stats_find_bytype(type, id);
75 + st = rrdset_find_bytype(type, id);
76 if(!st) {
77 - st = rrd_stats_create(type, id, NULL, "cpu", title, "percentage", priority, update_every, CHART_TYPE_STACKED);
77 + st = rrdset_create(type, id, NULL, "cpu", title, "percentage", priority, update_every, RRDSET_TYPE_STACKED);
78
79 long multiplier = 1;
80 long divisor = 1; // sysconf(_SC_CLK_TCK);
81
82 - rrd_stats_dimension_add(st, "guest_nice", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
83 - rrd_stats_dimension_add(st, "guest", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
84 - rrd_stats_dimension_add(st, "steal", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
85 - rrd_stats_dimension_add(st, "softirq", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
86 - rrd_stats_dimension_add(st, "irq", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
87 - rrd_stats_dimension_add(st, "user", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
88 - rrd_stats_dimension_add(st, "system", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
89 - rrd_stats_dimension_add(st, "nice", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
90 - rrd_stats_dimension_add(st, "iowait", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
91 -
92 - rrd_stats_dimension_add(st, "idle", NULL, multiplier, divisor, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
93 - rrd_stats_dimension_hide(st, "idle");
82 + rrddim_add(st, "guest_nice", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
83 + rrddim_add(st, "guest", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
84 + rrddim_add(st, "steal", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
85 + rrddim_add(st, "softirq", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
86 + rrddim_add(st, "irq", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
87 + rrddim_add(st, "user", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
88 + rrddim_add(st, "system", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
89 + rrddim_add(st, "nice", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
90 + rrddim_add(st, "iowait", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
91 +
92 + rrddim_add(st, "idle", NULL, multiplier, divisor, RRDDIM_PCENT_OVER_DIFF_TOTAL);
93 + rrddim_hide(st, "idle");
94 }
95 - else rrd_stats_next(st);
96 -
97 - rrd_stats_dimension_set(st, "user", user);
98 - rrd_stats_dimension_set(st, "nice", nice);
99 - rrd_stats_dimension_set(st, "system", system);
100 - rrd_stats_dimension_set(st, "idle", idle);
101 - rrd_stats_dimension_set(st, "iowait", iowait);
102 - rrd_stats_dimension_set(st, "irq", irq);
103 - rrd_stats_dimension_set(st, "softirq", softirq);
104 - rrd_stats_dimension_set(st, "steal", steal);
105 - rrd_stats_dimension_set(st, "guest", guest);
106 - rrd_stats_dimension_set(st, "guest_nice", guest_nice);
107 - rrd_stats_done(st);
95 + else rrdset_next(st);
96 +
97 + rrddim_set(st, "user", user);
98 + rrddim_set(st, "nice", nice);
99 + rrddim_set(st, "system", system);
100 + rrddim_set(st, "idle", idle);
101 + rrddim_set(st, "iowait", iowait);
102 + rrddim_set(st, "irq", irq);
103 + rrddim_set(st, "softirq", softirq);
104 + rrddim_set(st, "steal", steal);
105 + rrddim_set(st, "guest", guest);
106 + rrddim_set(st, "guest_nice", guest_nice);
107 + rrdset_done(st);
108 }
109 }
110 else if(strcmp(procfile_lineword(ff, l, 0), "intr") == 0) {
@@ -113,17 +113,17 @@ int do_proc_stat(int update_every, unsigned long long dt) {
113 // --------------------------------------------------------------------
114
115 if(do_interrupts) {
116 - st = rrd_stats_find_bytype("system", "intr");
116 + st = rrdset_find_bytype("system", "intr");
117 if(!st) {
118 - st = rrd_stats_create("system", "intr", NULL, "cpu", "CPU Interrupts", "interrupts/s", 900, update_every, CHART_TYPE_LINE);
118 + st = rrdset_create("system", "intr", NULL, "cpu", "CPU Interrupts", "interrupts/s", 900, update_every, RRDSET_TYPE_LINE);
119 st->isdetail = 1;
120
121 - rrd_stats_dimension_add(st, "interrupts", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
121 + rrddim_add(st, "interrupts", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
122 }
123 - else rrd_stats_next(st);
123 + else rrdset_next(st);
124
125 - rrd_stats_dimension_set(st, "interrupts", value);
126 - rrd_stats_done(st);
125 + rrddim_set(st, "interrupts", value);
126 + rrdset_done(st);
127 }
128 }
129 else if(strcmp(procfile_lineword(ff, l, 0), "ctxt") == 0) {
@@ -132,16 +132,16 @@ int do_proc_stat(int update_every, unsigned long long dt) {
132 // --------------------------------------------------------------------
133
134 if(do_context) {
135 - st = rrd_stats_find_bytype("system", "ctxt");
135 + st = rrdset_find_bytype("system", "ctxt");
136 if(!st) {
137 - st = rrd_stats_create("system", "ctxt", NULL, "cpu", "CPU Context Switches", "context switches/s", 800, update_every, CHART_TYPE_LINE);
137 + st = rrdset_create("system", "ctxt", NULL, "cpu", "CPU Context Switches", "context switches/s", 800, update_every, RRDSET_TYPE_LINE);
138
139 - rrd_stats_dimension_add(st, "switches", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
139 + rrddim_add(st, "switches", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
140 }
141 - else rrd_stats_next(st);
141 + else rrdset_next(st);
142
143 - rrd_stats_dimension_set(st, "switches", value);
144 - rrd_stats_done(st);
143 + rrddim_set(st, "switches", value);
144 + rrdset_done(st);
145 }
146 }
147 else if(!processes && strcmp(procfile_lineword(ff, l, 0), "processes") == 0) {
@@ -158,34 +158,34 @@ int do_proc_stat(int update_every, unsigned long long dt) {
158 // --------------------------------------------------------------------
159
160 if(do_forks) {
161 - st = rrd_stats_find_bytype("system", "forks");
161 + st = rrdset_find_bytype("system", "forks");
162 if(!st) {
163 - st = rrd_stats_create("system", "forks", NULL, "cpu", "New Processes", "processes/s", 700, update_every, CHART_TYPE_LINE);
163 + st = rrdset_create("system", "forks", NULL, "cpu", "New Processes", "processes/s", 700, update_every, RRDSET_TYPE_LINE);
164 st->isdetail = 1;
165
166 - rrd_stats_dimension_add(st, "started", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
166 + rrddim_add(st, "started", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
167 }
168 - else rrd_stats_next(st);
168 + else rrdset_next(st);
169
170 - rrd_stats_dimension_set(st, "started", processes);
171 - rrd_stats_done(st);
170 + rrddim_set(st, "started", processes);
171 + rrdset_done(st);
172 }
173
174 // --------------------------------------------------------------------
175
176 if(do_processes) {
177 - st = rrd_stats_find_bytype("system", "processes");
177 + st = rrdset_find_bytype("system", "processes");
178 if(!st) {
179 - st = rrd_stats_create("system", "processes", NULL, "cpu", "Processes", "processes", 600, update_every, CHART_TYPE_LINE);
179 + st = rrdset_create("system", "processes", NULL, "cpu", "Processes", "processes", 600, update_every, RRDSET_TYPE_LINE);
180
181 - rrd_stats_dimension_add(st, "running", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
182 - rrd_stats_dimension_add(st, "blocked", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
181 + rrddim_add(st, "running", NULL, 1, 1, RRDDIM_ABSOLUTE);
182 + rrddim_add(st, "blocked", NULL, -1, 1, RRDDIM_ABSOLUTE);
183 }
184 - else rrd_stats_next(st);
184 + else rrdset_next(st);
185
186 - rrd_stats_dimension_set(st, "running", running);
187 - rrd_stats_dimension_set(st, "blocked", blocked);
188 - rrd_stats_done(st);
186 + rrddim_set(st, "running", running);
187 + rrddim_set(st, "blocked", blocked);
188 + rrdset_done(st);
189 }
190
191 return 0;
src/proc_vmstat.c
+25 -25
@@ -150,58 +150,58 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
150 else if(!thp_split && strcmp(name, "thp_split") == 0) thp_split = value;
151 }
152
153 - RRD_STATS *st;
153 + RRDSET *st;
154
155 // --------------------------------------------------------------------
156
157 if(do_swapio) {
158 - st = rrd_stats_find("system.swapio");
158 + st = rrdset_find("system.swapio");
159 if(!st) {
160 - st = rrd_stats_create("system", "swapio", NULL, "mem", "Swap I/O", "kilobytes/s", 250, update_every, CHART_TYPE_AREA);
160 + st = rrdset_create("system", "swapio", NULL, "mem", "Swap I/O", "kilobytes/s", 250, update_every, RRDSET_TYPE_AREA);
161
162 - rrd_stats_dimension_add(st, "in", NULL, sysconf(_SC_PAGESIZE), 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
163 - rrd_stats_dimension_add(st, "out", NULL, -sysconf(_SC_PAGESIZE), 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
162 + rrddim_add(st, "in", NULL, sysconf(_SC_PAGESIZE), 1024 * update_every, RRDDIM_INCREMENTAL);
163 + rrddim_add(st, "out", NULL, -sysconf(_SC_PAGESIZE), 1024 * update_every, RRDDIM_INCREMENTAL);
164 }
165 - else rrd_stats_next(st);
165 + else rrdset_next(st);
166
167 - rrd_stats_dimension_set(st, "in", pswpin);
168 - rrd_stats_dimension_set(st, "out", pswpout);
169 - rrd_stats_done(st);
167 + rrddim_set(st, "in", pswpin);
168 + rrddim_set(st, "out", pswpout);
169 + rrdset_done(st);
170 }
171
172 // --------------------------------------------------------------------
173
174 if(do_io) {
175 - st = rrd_stats_find("system.io");
175 + st = rrdset_find("system.io");
176 if(!st) {
177 - st = rrd_stats_create("system", "io", NULL, "disk", "Disk I/O", "kilobytes/s", 150, update_every, CHART_TYPE_AREA);
177 + st = rrdset_create("system", "io", NULL, "disk", "Disk I/O", "kilobytes/s", 150, update_every, RRDSET_TYPE_AREA);
178
179 - rrd_stats_dimension_add(st, "in", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
180 - rrd_stats_dimension_add(st, "out", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
179 + rrddim_add(st, "in", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
180 + rrddim_add(st, "out", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
181 }
182 - else rrd_stats_next(st);
182 + else rrdset_next(st);
183
184 - rrd_stats_dimension_set(st, "in", pgpgin);
185 - rrd_stats_dimension_set(st, "out", pgpgout);
186 - rrd_stats_done(st);
184 + rrddim_set(st, "in", pgpgin);
185 + rrddim_set(st, "out", pgpgout);
186 + rrdset_done(st);
187 }
188
189 // --------------------------------------------------------------------
190
191 if(do_pgfaults) {
192 - st = rrd_stats_find("system.pgfaults");
192 + st = rrdset_find("system.pgfaults");
193 if(!st) {
194 - st = rrd_stats_create("system", "pgfaults", NULL, "mem", "Memory Page Faults", "page faults/s", 500, update_every, CHART_TYPE_LINE);
194 + st = rrdset_create("system", "pgfaults", NULL, "mem", "Memory Page Faults", "page faults/s", 500, update_every, RRDSET_TYPE_LINE);
195 st->isdetail = 1;
196
197 - rrd_stats_dimension_add(st, "minor", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
198 - rrd_stats_dimension_add(st, "major", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
197 + rrddim_add(st, "minor", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
198 + rrddim_add(st, "major", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
199 }
200 - else rrd_stats_next(st);
200 + else rrdset_next(st);
201
202 - rrd_stats_dimension_set(st, "minor", pgfault);
203 - rrd_stats_dimension_set(st, "major", pgmajfault);
204 - rrd_stats_done(st);
202 + rrddim_set(st, "minor", pgfault);
203 + rrddim_set(st, "major", pgmajfault);
204 + rrdset_done(st);
205 }
206
207 return 0;
src/procfile.h
-3
@@ -26,9 +26,6 @@
26 #ifndef NETDATA_PROCFILE_H
27 #define NETDATA_PROCFILE_H 1
28
29 -// if enabled, procfile will output a lot of debug info
30 -extern int pfdebug;
31 -
29 // ----------------------------------------------------------------------------
30 // An array of words
31
src/rrd.c
+261 -184
@@ -16,58 +16,119 @@
16
17 #include "rrd.h"
18
19 -int update_every = UPDATE_EVERY;
20 -int save_history = HISTORY;
19 +// ----------------------------------------------------------------------------
20 +// globals
21 +
22 +int rrd_update_every = UPDATE_EVERY;
23 +int rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
24 +
25 +RRDSET *rrdset_root = NULL;
26 +pthread_rwlock_t rrdset_root_rwlock = PTHREAD_RWLOCK_INITIALIZER;
27 +
28 +int rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
29 +
30 +
31 +// ----------------------------------------------------------------------------
32 +// RRDSET index
33 +
34 +static int rrdset_iterator(avl *a) { if(a) {}; return 0; }
35 +
36 +static int rrdset_compare(void* a, void* b) {
37 + if(((RRDSET *)a)->hash < ((RRDSET *)b)->hash) return -1;
38 + else if(((RRDSET *)a)->hash > ((RRDSET *)b)->hash) return 1;
39 + else return strcmp(((RRDSET *)a)->id, ((RRDSET *)b)->id);
40 +}
41 +
42 +avl_tree rrdset_root_index = {
43 + NULL,
44 + rrdset_compare
45 +};
46 +
47 +#define rrdset_index_add(st) avl_insert(&rrdset_root_index, (avl *)(st))
48 +#define rrdset_index_del(st) avl_remove(&rrdset_root_index, (avl *)(st))
49 +
50 +static RRDSET *rrdset_index_find(const char *id, unsigned long hash) {
51 + RRDSET *result = NULL, tmp;
52 + strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
53 + tmp.id[RRD_ID_LENGTH_MAX] = '\0';
54 + tmp.hash = (hash)?hash:simple_hash(tmp.id);
55 +
56 + avl_search(&(rrdset_root_index), (avl *)&tmp, rrdset_iterator, (avl **)&result);
57 + return result;
58 +}
59 +
60 +// ----------------------------------------------------------------------------
61 +// RRDDIM index
62 +
63 +static int rrddim_iterator(avl *a) { if(a) {}; return 0; }
64 +
65 +static int rrddim_compare(void* a, void* b) {
66 + if(((RRDDIM *)a)->hash < ((RRDDIM *)b)->hash) return -1;
67 + else if(((RRDDIM *)a)->hash > ((RRDDIM *)b)->hash) return 1;
68 + else return strcmp(((RRDDIM *)a)->id, ((RRDDIM *)b)->id);
69 +}
70 +
71 +#define rrddim_index_add(st, rd) avl_insert(&((st)->dimensions_index), (avl *)(rd))
72 +#define rrddim_index_del(st,rd ) avl_remove(&((st)->dimensions_index), (avl *)(rd))
73 +
74 +static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, unsigned long hash) {
75 + RRDDIM *result = NULL, tmp;
76 + tmp.hash = (hash)?hash:simple_hash(id);
77 + strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
78 + tmp.id[RRD_ID_LENGTH_MAX] = '\0';
79 + tmp.hash = (hash)?hash:simple_hash(tmp.id);
80 +
81 + avl_search(&(st->dimensions_index), (avl *)&tmp, rrddim_iterator, (avl **)&result);
82 + return result;
83 +}
84
85 // ----------------------------------------------------------------------------
86 // chart types
87
25 -int chart_type_id(const char *name)
88 +int rrdset_type_id(const char *name)
89 {
27 - if(strcmp(name, CHART_TYPE_AREA_NAME) == 0) return CHART_TYPE_AREA;
28 - if(strcmp(name, CHART_TYPE_STACKED_NAME) == 0) return CHART_TYPE_STACKED;
29 - if(strcmp(name, CHART_TYPE_LINE_NAME) == 0) return CHART_TYPE_LINE;
30 - return CHART_TYPE_LINE;
90 + if(strcmp(name, RRDSET_TYPE_AREA_NAME) == 0) return RRDSET_TYPE_AREA;
91 + if(strcmp(name, RRDSET_TYPE_STACKED_NAME) == 0) return RRDSET_TYPE_STACKED;
92 + if(strcmp(name, RRDSET_TYPE_LINE_NAME) == 0) return RRDSET_TYPE_LINE;
93 + return RRDSET_TYPE_LINE;
94 }
95
33 -const char *chart_type_name(int chart_type)
96 +const char *rrdset_type_name(int chart_type)
97 {
35 - static char line[] = CHART_TYPE_LINE_NAME;
36 - static char area[] = CHART_TYPE_AREA_NAME;
37 - static char stacked[] = CHART_TYPE_STACKED_NAME;
98 + static char line[] = RRDSET_TYPE_LINE_NAME;
99 + static char area[] = RRDSET_TYPE_AREA_NAME;
100 + static char stacked[] = RRDSET_TYPE_STACKED_NAME;
101
102 switch(chart_type) {
40 - case CHART_TYPE_LINE:
103 + case RRDSET_TYPE_LINE:
104 return line;
105
43 - case CHART_TYPE_AREA:
106 + case RRDSET_TYPE_AREA:
107 return area;
108
46 - case CHART_TYPE_STACKED:
109 + case RRDSET_TYPE_STACKED:
110 return stacked;
111 }
112 return line;
113 }
114
115 // ----------------------------------------------------------------------------
53 -// mmap() wrapper
116 +// load / save
117
55 -int memory_mode = NETDATA_MEMORY_MODE_SAVE;
56 -
57 -const char *memory_mode_name(int id)
118 +const char *rrd_memory_mode_name(int id)
119 {
59 - static const char ram[] = NETDATA_MEMORY_MODE_RAM_NAME;
60 - static const char map[] = NETDATA_MEMORY_MODE_MAP_NAME;
61 - static const char save[] = NETDATA_MEMORY_MODE_SAVE_NAME;
120 + static const char ram[] = RRD_MEMORY_MODE_RAM_NAME;
121 + static const char map[] = RRD_MEMORY_MODE_MAP_NAME;
122 + static const char save[] = RRD_MEMORY_MODE_SAVE_NAME;
123
124 switch(id) {
64 - case NETDATA_MEMORY_MODE_RAM:
125 + case RRD_MEMORY_MODE_RAM:
126 return ram;
127
67 - case NETDATA_MEMORY_MODE_MAP:
128 + case RRD_MEMORY_MODE_MAP:
129 return map;
130
70 - case NETDATA_MEMORY_MODE_SAVE:
131 + case RRD_MEMORY_MODE_SAVE:
132 default:
133 return save;
134 }
@@ -75,55 +136,55 @@ const char *memory_mode_name(int id)
136 return save;
137 }
138
78 -int memory_mode_id(const char *name)
139 +int rrd_memory_mode_id(const char *name)
140 {
80 - if(!strcmp(name, NETDATA_MEMORY_MODE_RAM_NAME))
81 - return NETDATA_MEMORY_MODE_RAM;
82 - else if(!strcmp(name, NETDATA_MEMORY_MODE_MAP_NAME))
83 - return NETDATA_MEMORY_MODE_MAP;
141 + if(!strcmp(name, RRD_MEMORY_MODE_RAM_NAME))
142 + return RRD_MEMORY_MODE_RAM;
143 + else if(!strcmp(name, RRD_MEMORY_MODE_MAP_NAME))
144 + return RRD_MEMORY_MODE_MAP;
145
85 - return NETDATA_MEMORY_MODE_SAVE;
146 + return RRD_MEMORY_MODE_SAVE;
147 }
148
149 // ----------------------------------------------------------------------------
150 // algorithms types
151
91 -int algorithm_id(const char *name)
152 +int rrddim_algorithm_id(const char *name)
153 {
93 - if(strcmp(name, RRD_DIMENSION_ABSOLUTE_NAME) == 0) return RRD_DIMENSION_ABSOLUTE;
94 - if(strcmp(name, RRD_DIMENSION_INCREMENTAL_NAME) == 0) return RRD_DIMENSION_INCREMENTAL;
95 - if(strcmp(name, RRD_DIMENSION_PCENT_OVER_ROW_TOTAL_NAME) == 0) return RRD_DIMENSION_PCENT_OVER_ROW_TOTAL;
96 - if(strcmp(name, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL_NAME) == 0) return RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL;
97 - return RRD_DIMENSION_ABSOLUTE;
154 + if(strcmp(name, RRDDIM_ABSOLUTE_NAME) == 0) return RRDDIM_ABSOLUTE;
155 + if(strcmp(name, RRDDIM_INCREMENTAL_NAME) == 0) return RRDDIM_INCREMENTAL;
156 + if(strcmp(name, RRDDIM_PCENT_OVER_ROW_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_ROW_TOTAL;
157 + if(strcmp(name, RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_DIFF_TOTAL;
158 + return RRDDIM_ABSOLUTE;
159 }
160
100 -const char *algorithm_name(int chart_type)
161 +const char *rrddim_algorithm_name(int chart_type)
162 {
102 - static char absolute[] = RRD_DIMENSION_ABSOLUTE_NAME;
103 - static char incremental[] = RRD_DIMENSION_INCREMENTAL_NAME;
104 - static char percentage_of_absolute_row[] = RRD_DIMENSION_PCENT_OVER_ROW_TOTAL_NAME;
105 - static char percentage_of_incremental_row[] = RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL_NAME;
163 + static char absolute[] = RRDDIM_ABSOLUTE_NAME;
164 + static char incremental[] = RRDDIM_INCREMENTAL_NAME;
165 + static char percentage_of_absolute_row[] = RRDDIM_PCENT_OVER_ROW_TOTAL_NAME;
166 + static char percentage_of_incremental_row[] = RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME;
167
168 switch(chart_type) {
108 - case RRD_DIMENSION_ABSOLUTE:
169 + case RRDDIM_ABSOLUTE:
170 return absolute;
171
111 - case RRD_DIMENSION_INCREMENTAL:
172 + case RRDDIM_INCREMENTAL:
173 return incremental;
174
114 - case RRD_DIMENSION_PCENT_OVER_ROW_TOTAL:
175 + case RRDDIM_PCENT_OVER_ROW_TOTAL:
176 return percentage_of_absolute_row;
177
117 - case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
178 + case RRDDIM_PCENT_OVER_DIFF_TOTAL:
179 return percentage_of_incremental_row;
180 }
181 return absolute;
182 }
183
123 -RRD_STATS *root = NULL;
124 -pthread_rwlock_t root_rwlock = PTHREAD_RWLOCK_INITIALIZER;
184 +// ----------------------------------------------------------------------------
185 +// chart names
186
126 -char *rrd_stats_strncpy_name(char *to, const char *from, int length)
187 +char *rrdset_strncpy_name(char *to, const char *from, int length)
188 {
189 int i;
190 for(i = 0; i < length && from[i] ;i++) {
@@ -136,18 +197,21 @@ char *rrd_stats_strncpy_name(char *to, const char *from, int length)
197 return to;
198 }
199
139 -void rrd_stats_set_name(RRD_STATS *st, const char *name)
200 +void rrdset_set_name(RRDSET *st, const char *name)
201 {
202 char b[CONFIG_MAX_VALUE + 1];
142 - char n[RRD_STATS_NAME_MAX + 1];
203 + char n[RRD_ID_LENGTH_MAX + 1];
204
144 - snprintf(n, RRD_STATS_NAME_MAX, "%s.%s", st->type, name);
145 - rrd_stats_strncpy_name(b, n, CONFIG_MAX_VALUE);
205 + snprintf(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
206 + rrdset_strncpy_name(b, n, CONFIG_MAX_VALUE);
207 st->name = config_get(st->id, "name", b);
208 st->hash_name = simple_hash(st->name);
209 }
210
150 -char *rrd_stats_cache_dir(const char *id)
211 +// ----------------------------------------------------------------------------
212 +// cache directory
213 +
214 +char *rrdset_cache_dir(const char *id)
215 {
216 char *ret = NULL;
217
@@ -156,12 +220,12 @@ char *rrd_stats_cache_dir(const char *id)
220
221 char b[FILENAME_MAX + 1];
222 char n[FILENAME_MAX + 1];
159 - rrd_stats_strncpy_name(b, id, FILENAME_MAX);
223 + rrdset_strncpy_name(b, id, FILENAME_MAX);
224
225 snprintf(n, FILENAME_MAX, "%s/%s", cache_dir, b);
226 ret = config_get(id, "database directory", n);
227
164 - if(memory_mode == NETDATA_MEMORY_MODE_MAP || memory_mode == NETDATA_MEMORY_MODE_SAVE) {
228 + if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
229 int r = mkdir(ret, 0775);
230 if(r != 0 && errno != EEXIST)
231 error("Cannot create directory '%s'", ret);
@@ -170,7 +234,10 @@ char *rrd_stats_cache_dir(const char *id)
234 return ret;
235 }
236
173 -void rrd_stats_reset(RRD_STATS *st)
237 +// ----------------------------------------------------------------------------
238 +// core functions
239 +
240 +void rrdset_reset(RRDSET *st)
241 {
242 st->last_collected_time.tv_sec = 0;
243 st->last_collected_time.tv_usec = 0;
@@ -180,7 +247,7 @@ void rrd_stats_reset(RRD_STATS *st)
247 st->counter = 0;
248 st->counter_done = 0;
249
183 - RRD_DIMENSION *rd;
250 + RRDDIM *rd;
251 for(rd = st->dimensions; rd ; rd = rd->next) {
252 rd->last_collected_time.tv_sec = 0;
253 rd->last_collected_time.tv_usec = 0;
@@ -188,35 +255,35 @@ void rrd_stats_reset(RRD_STATS *st)
255 }
256 }
257
191 -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)
258 +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)
259 {
260 if(!id || !id[0]) {
261 fatal("Cannot create rrd stats without an id.");
262 return NULL;
263 }
264
198 - char fullid[RRD_STATS_NAME_MAX + 1];
265 + char fullid[RRD_ID_LENGTH_MAX + 1];
266 char fullfilename[FILENAME_MAX + 1];
200 - RRD_STATS *st = NULL;
267 + RRDSET *st = NULL;
268
202 - snprintf(fullid, RRD_STATS_NAME_MAX, "%s.%s", type, id);
269 + snprintf(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
270
204 - long entries = config_get_number(fullid, "history", save_history);
271 + long entries = config_get_number(fullid, "history", rrd_default_history_entries);
272 if(entries < 5) entries = config_set_number(fullid, "history", 5);
206 - if(entries > HISTORY_MAX) entries = config_set_number(fullid, "history", HISTORY_MAX);
273 + if(entries > RRD_HISTORY_ENTRIES_MAX) entries = config_set_number(fullid, "history", RRD_HISTORY_ENTRIES_MAX);
274
275 int enabled = config_get_boolean(fullid, "enabled", 1);
276 if(!enabled) entries = 5;
277
211 - unsigned long size = sizeof(RRD_STATS);
212 - char *cache_dir = rrd_stats_cache_dir(fullid);
278 + unsigned long size = sizeof(RRDSET);
279 + char *cache_dir = rrdset_cache_dir(fullid);
280
281 debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id);
282
283 snprintf(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
217 - if(memory_mode != NETDATA_MEMORY_MODE_RAM) st = (RRD_STATS *)mymmap(fullfilename, size, ((memory_mode == NETDATA_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE));
284 + if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE));
285 if(st) {
219 - if(strcmp(st->magic, RRD_STATS_MAGIC) != 0) {
286 + if(strcmp(st->magic, RRDSET_MAGIC) != 0) {
287 errno = 0;
288 info("Initializing file %s.", fullfilename);
289 bzero(st, size);
@@ -253,7 +320,7 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
320 st->units = NULL;
321 st->dimensions = NULL;
322 st->next = NULL;
256 - st->mapped = memory_mode;
323 + st->mapped = rrd_memory_mode;
324 }
325 else {
326 st = calloc(1, size);
@@ -261,14 +328,14 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
328 fatal("Cannot allocate memory for RRD_STATS %s.%s", type, id);
329 return NULL;
330 }
264 - st->mapped = NETDATA_MEMORY_MODE_RAM;
331 + st->mapped = RRD_MEMORY_MODE_RAM;
332 }
333 st->memsize = size;
334 st->entries = entries;
335 st->update_every = update_every;
336
270 - strcpy(st->cache_file, fullfilename);
271 - strcpy(st->magic, RRD_STATS_MAGIC);
337 + strcpy(st->cache_filename, fullfilename);
338 + strcpy(st->magic, RRDSET_MAGIC);
339
340 strcpy(st->id, fullid);
341 st->hash = simple_hash(st->id);
@@ -278,10 +345,10 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
345 st->family = config_get(st->id, "family", family?family:st->id);
346 st->units = config_get(st->id, "units", units?units:"");
347 st->type = config_get(st->id, "type", type);
281 - st->chart_type = chart_type_id(config_get(st->id, "chart type", chart_type_name(chart_type)));
348 + st->chart_type = rrdset_type_id(config_get(st->id, "chart type", rrdset_type_name(chart_type)));
349
283 - if(name && *name) rrd_stats_set_name(st, name);
284 - else rrd_stats_set_name(st, id);
350 + if(name && *name) rrdset_set_name(st, name);
351 + else rrdset_set_name(st, id);
352
353 {
354 char varvalue[CONFIG_MAX_VALUE + 1];
@@ -299,38 +366,43 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
366 st->last_collected_time.tv_usec = 0;
367 st->counter_done = 0;
368
302 - st->gap_when_lost_iterations = config_get_number(st->id, "gap when lost iterations above", DEFAULT_GAP_INTERPOLATIONS);
369 + st->gap_when_lost_iterations_above = config_get_number(st->id, "gap when lost iterations above", RRD_DEFAULT_GAP_INTERPOLATIONS);
370 +
371 + st->dimensions_index.root = NULL;
372 + st->dimensions_index.compar = rrddim_compare;
373
374 pthread_rwlock_init(&st->rwlock, NULL);
305 - pthread_rwlock_wrlock(&root_rwlock);
375 + pthread_rwlock_wrlock(&rrdset_root_rwlock);
376 +
377 + st->next = rrdset_root;
378 + rrdset_root = st;
379
307 - st->next = root;
308 - root = st;
380 + rrdset_index_add(st);
381
310 - pthread_rwlock_unlock(&root_rwlock);
382 + pthread_rwlock_unlock(&rrdset_root_rwlock);
383
384 return(st);
385 }
386
315 -RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char *name, long multiplier, long divisor, int algorithm)
387 +RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm)
388 {
389 char filename[FILENAME_MAX + 1];
390 char fullfilename[FILENAME_MAX + 1];
391
392 char varname[CONFIG_MAX_NAME + 1];
321 - RRD_DIMENSION *rd = NULL;
322 - unsigned long size = sizeof(RRD_DIMENSION) + (st->entries * sizeof(storage_number));
393 + RRDDIM *rd = NULL;
394 + unsigned long size = sizeof(RRDDIM) + (st->entries * sizeof(storage_number));
395
396 debug(D_RRD_CALLS, "Adding dimension '%s/%s'.", st->id, id);
397
326 - rrd_stats_strncpy_name(filename, id, FILENAME_MAX);
398 + rrdset_strncpy_name(filename, id, FILENAME_MAX);
399 snprintf(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
328 - if(memory_mode != NETDATA_MEMORY_MODE_RAM) rd = (RRD_DIMENSION *)mymmap(fullfilename, size, ((memory_mode == NETDATA_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE));
400 + if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE));
401 if(rd) {
402 struct timeval now;
403 gettimeofday(&now, NULL);
404
333 - if(strcmp(rd->magic, RRD_DIMENSION_MAGIC) != 0) {
405 + if(strcmp(rd->magic, RRDDIMENSION_MAGIC) != 0) {
406 errno = 0;
407 info("Initializing file %s.", fullfilename);
408 bzero(rd, size);
@@ -376,7 +448,7 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
448
449 if(rd) {
450 // we have a file mapped for rd
379 - rd->mapped = memory_mode;
451 + rd->mapped = rrd_memory_mode;
452 rd->hidden = 0;
453 rd->next = NULL;
454 rd->name = NULL;
@@ -390,20 +462,20 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
462 return NULL;
463 }
464
393 - rd->mapped = NETDATA_MEMORY_MODE_RAM;
465 + rd->mapped = RRD_MEMORY_MODE_RAM;
466 }
467 rd->memsize = size;
468
397 - strcpy(rd->magic, RRD_DIMENSION_MAGIC);
398 - strcpy(rd->cache_file, fullfilename);
399 - strncpy(rd->id, id, RRD_STATS_NAME_MAX);
469 + strcpy(rd->magic, RRDDIMENSION_MAGIC);
470 + strcpy(rd->cache_filename, fullfilename);
471 + strncpy(rd->id, id, RRD_ID_LENGTH_MAX);
472 rd->hash = simple_hash(rd->id);
473
474 snprintf(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
475 rd->name = config_get(st->id, varname, (name && *name)?name:rd->id);
476
477 snprintf(varname, CONFIG_MAX_NAME, "dim %s algorithm", rd->id);
406 - rd->algorithm = algorithm_id(config_get(st->id, varname, algorithm_name(algorithm)));
478 + rd->algorithm = rrddim_algorithm_id(config_get(st->id, varname, rrddim_algorithm_name(algorithm)));
479
480 snprintf(varname, CONFIG_MAX_NAME, "dim %s multiplier", rd->id);
481 rd->multiplier = config_get_number(st->id, varname, multiplier);
@@ -419,33 +491,47 @@ RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char
491 if(!st->dimensions)
492 st->dimensions = rd;
493 else {
422 - RRD_DIMENSION *td = st->dimensions;
494 + RRDDIM *td = st->dimensions;
495 for(; td->next; td = td->next) ;
496 td->next = rd;
497 }
498
499 + rrddim_index_add(st, rd);
500 +
501 return(rd);
502 }
503
430 -void rrd_stats_dimension_set_name(RRD_STATS *st, RRD_DIMENSION *rd, const char *name)
504 +void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name)
505 {
506 char varname[CONFIG_MAX_NAME + 1];
507 snprintf(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
508 config_get(st->id, varname, name);
509 }
510
437 -void rrd_stats_dimension_free(RRD_DIMENSION *rd)
511 +void rrddim_free(RRDSET *st, RRDDIM *rd)
512 {
439 - if(rd->next) rrd_stats_dimension_free(rd->next);
513 + RRDDIM *i = st->dimensions, *last = NULL;
514 + for(i = st->dimensions; i && i != rd ; i = i->next) last = i;
515 +
516 + if(!i) {
517 + error("Request to free dimension %s.%s but it is not linked.", st->id, rd->name);
518 + return;
519 + }
520 +
521 + if(last) last = i->next;
522 + else st->dimensions = i->next;
523 +
524 + rrddim_index_del(st, rd);
525 +
526 // free(rd->annotations);
441 - if(rd->mapped == NETDATA_MEMORY_MODE_SAVE) {
442 - debug(D_RRD_CALLS, "Saving dimension '%s' to '%s'.", rd->name, rd->cache_file);
443 - savememory(rd->cache_file, rd, rd->memsize);
527 + if(rd->mapped == RRD_MEMORY_MODE_SAVE) {
528 + debug(D_RRD_CALLS, "Saving dimension '%s' to '%s'.", rd->name, rd->cache_filename);
529 + savememory(rd->cache_filename, rd, rd->memsize);
530
531 debug(D_RRD_CALLS, "Unmapping dimension '%s'.", rd->name);
532 munmap(rd, rd->memsize);
533 }
448 - else if(rd->mapped == NETDATA_MEMORY_MODE_MAP) {
534 + else if(rd->mapped == RRD_MEMORY_MODE_MAP) {
535 debug(D_RRD_CALLS, "Unmapping dimension '%s'.", rd->name);
536 munmap(rd, rd->memsize);
537 }
@@ -455,25 +541,27 @@ void rrd_stats_dimension_free(RRD_DIMENSION *rd)
541 }
542 }
543
458 -void rrd_stats_free_all(void)
544 +void rrdset_free_all(void)
545 {
546 info("Freeing all memory...");
547
462 - RRD_STATS *st;
463 - for(st = root; st ;) {
464 - RRD_STATS *next = st->next;
548 + RRDSET *st;
549 + for(st = rrdset_root; st ;) {
550 + RRDSET *next = st->next;
551
466 - if(st->dimensions) rrd_stats_dimension_free(st->dimensions);
467 - st->dimensions = NULL;
552 + while(st->dimensions)
553 + rrddim_free(st, st->dimensions);
554
469 - if(st->mapped == NETDATA_MEMORY_MODE_SAVE) {
470 - debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_file);
471 - savememory(st->cache_file, st, st->memsize);
555 + rrdset_index_del(st);
556 +
557 + if(st->mapped == RRD_MEMORY_MODE_SAVE) {
558 + debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename);
559 + savememory(st->cache_filename, st, st->memsize);
560
561 debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name);
562 munmap(st, st->memsize);
563 }
476 - else if(st->mapped == NETDATA_MEMORY_MODE_MAP) {
564 + else if(st->mapped == RRD_MEMORY_MODE_MAP) {
565 debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name);
566 munmap(st, st->memsize);
567 }
@@ -482,111 +570,96 @@ void rrd_stats_free_all(void)
570
571 st = next;
572 }
485 - root = NULL;
573 + rrdset_root = NULL;
574
575 info("Memory cleanup completed...");
576 }
577
490 -void rrd_stats_save_all(void)
578 +void rrdset_save_all(void)
579 {
492 - RRD_STATS *st;
493 - RRD_DIMENSION *rd;
580 + RRDSET *st;
581 + RRDDIM *rd;
582
495 - pthread_rwlock_wrlock(&root_rwlock);
496 - for(st = root; st ; st = st->next) {
583 + pthread_rwlock_wrlock(&rrdset_root_rwlock);
584 + for(st = rrdset_root; st ; st = st->next) {
585 pthread_rwlock_wrlock(&st->rwlock);
586
499 - if(st->mapped == NETDATA_MEMORY_MODE_SAVE) {
500 - debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_file);
501 - savememory(st->cache_file, st, st->memsize);
587 + if(st->mapped == RRD_MEMORY_MODE_SAVE) {
588 + debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename);
589 + savememory(st->cache_filename, st, st->memsize);
590 }
591
592 for(rd = st->dimensions; rd ; rd = rd->next) {
505 - if(rd->mapped == NETDATA_MEMORY_MODE_SAVE) {
506 - debug(D_RRD_CALLS, "Saving dimension '%s' to '%s'.", rd->name, rd->cache_file);
507 - savememory(rd->cache_file, rd, rd->memsize);
593 + if(rd->mapped == RRD_MEMORY_MODE_SAVE) {
594 + debug(D_RRD_CALLS, "Saving dimension '%s' to '%s'.", rd->name, rd->cache_filename);
595 + savememory(rd->cache_filename, rd, rd->memsize);
596 }
597 }
598
599 pthread_rwlock_unlock(&st->rwlock);
600 }
513 - pthread_rwlock_unlock(&root_rwlock);
601 + pthread_rwlock_unlock(&rrdset_root_rwlock);
602 }
603
604
517 -RRD_STATS *rrd_stats_find(const char *id)
605 +RRDSET *rrdset_find(const char *id)
606 {
607 debug(D_RRD_CALLS, "rrd_stats_find() for chart %s", id);
608
521 - unsigned long hash = simple_hash(id);
522 -
523 - pthread_rwlock_rdlock(&root_rwlock);
524 - RRD_STATS *st = root;
525 - for ( ; st ; st = st->next )
526 - if(hash == st->hash)
527 - if(strcmp(st->id, id) == 0)
528 - break;
529 - pthread_rwlock_unlock(&root_rwlock);
609 + pthread_rwlock_rdlock(&rrdset_root_rwlock);
610 + RRDSET *st = rrdset_index_find(id, 0);
611 + pthread_rwlock_unlock(&rrdset_root_rwlock);
612
613 return(st);
614 }
615
534 -RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id)
616 +RRDSET *rrdset_find_bytype(const char *type, const char *id)
617 {
618 debug(D_RRD_CALLS, "rrd_stats_find_bytype() for chart %s.%s", type, id);
619
538 - char buf[RRD_STATS_NAME_MAX + 1];
620 + char buf[RRD_ID_LENGTH_MAX + 1];
621
540 - strncpy(buf, type, RRD_STATS_NAME_MAX - 1);
541 - buf[RRD_STATS_NAME_MAX - 1] = '\0';
622 + strncpy(buf, type, RRD_ID_LENGTH_MAX - 1);
623 + buf[RRD_ID_LENGTH_MAX - 1] = '\0';
624 strcat(buf, ".");
625 int len = strlen(buf);
544 - strncpy(&buf[len], id, RRD_STATS_NAME_MAX - len);
545 - buf[RRD_STATS_NAME_MAX] = '\0';
626 + strncpy(&buf[len], id, RRD_ID_LENGTH_MAX - len);
627 + buf[RRD_ID_LENGTH_MAX] = '\0';
628
547 - return(rrd_stats_find(buf));
629 + return(rrdset_find(buf));
630 }
631
550 -RRD_STATS *rrd_stats_find_byname(const char *name)
632 +RRDSET *rrdset_find_byname(const char *name)
633 {
634 debug(D_RRD_CALLS, "rrd_stats_find_byname() for chart %s", name);
635
636 char b[CONFIG_MAX_VALUE + 1];
637
556 - rrd_stats_strncpy_name(b, name, CONFIG_MAX_VALUE);
638 + rrdset_strncpy_name(b, name, CONFIG_MAX_VALUE);
639 unsigned long hash = simple_hash(b);
640
559 - pthread_rwlock_rdlock(&root_rwlock);
560 - RRD_STATS *st = root;
641 + pthread_rwlock_rdlock(&rrdset_root_rwlock);
642 + RRDSET *st = rrdset_root;
643 for ( ; st ; st = st->next ) {
644 if(hash == st->hash_name && strcmp(st->name, b) == 0) break;
645 }
564 - pthread_rwlock_unlock(&root_rwlock);
646 + pthread_rwlock_unlock(&rrdset_root_rwlock);
647
648 return(st);
649 }
650
569 -RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id)
651 +RRDDIM *rrddim_find(RRDSET *st, const char *id)
652 {
653 debug(D_RRD_CALLS, "rrd_stats_dimension_find() for chart %s, dimension %s", st->name, id);
654
573 - unsigned long hash = simple_hash(id);
574 -
575 - RRD_DIMENSION *rd = st->dimensions;
576 -
577 - for ( ; rd ; rd = rd->next )
578 - if(hash == rd->hash)
579 - if(strcmp(rd->id, id) == 0)
580 - break;
581 -
582 - return(rd);
655 + return rrddim_index_find(st, id, 0);
656 }
657
585 -int rrd_stats_dimension_hide(RRD_STATS *st, const char *id)
658 +int rrddim_hide(RRDSET *st, const char *id)
659 {
660 debug(D_RRD_CALLS, "rrd_stats_dimension_hide() for chart %s, dimension %s", st->name, id);
661
589 - RRD_DIMENSION *rd = rrd_stats_dimension_find(st, id);
662 + RRDDIM *rd = rrddim_find(st, id);
663 if(!rd) {
664 error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
665 return 1;
@@ -596,7 +669,7 @@ int rrd_stats_dimension_hide(RRD_STATS *st, const char *id)
669 return 0;
670 }
671
599 -void rrd_stats_dimension_set_by_pointer(RRD_STATS *st, RRD_DIMENSION *rd, collected_number value)
672 +void rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number value)
673 {
674 debug(D_RRD_CALLS, "rrd_stats_dimension_set() for chart %s, dimension %s, value " COLLECTED_NUMBER_FORMAT, st->name, rd->name, value);
675
@@ -605,19 +678,19 @@ void rrd_stats_dimension_set_by_pointer(RRD_STATS *st, RRD_DIMENSION *rd, collec
678 rd->updated = 1;
679 }
680
608 -int rrd_stats_dimension_set(RRD_STATS *st, const char *id, collected_number value)
681 +int rrddim_set(RRDSET *st, const char *id, collected_number value)
682 {
610 - RRD_DIMENSION *rd = rrd_stats_dimension_find(st, id);
683 + RRDDIM *rd = rrddim_find(st, id);
684 if(!rd) {
685 error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
686 return 1;
687 }
688
616 - rrd_stats_dimension_set_by_pointer(st, rd, value);
689 + rrddim_set_by_pointer(st, rd, value);
690 return 0;
691 }
692
620 -void rrd_stats_next_usec(RRD_STATS *st, unsigned long long microseconds)
693 +void rrdset_next_usec(RRDSET *st, unsigned long long microseconds)
694 {
695 debug(D_RRD_CALLS, "rrd_stats_next() for chart %s with microseconds %llu", st->name, microseconds);
696
@@ -625,7 +698,7 @@ void rrd_stats_next_usec(RRD_STATS *st, unsigned long long microseconds)
698 st->usec_since_last_update = microseconds;
699 }
700
628 -void rrd_stats_next(RRD_STATS *st)
701 +void rrdset_next(RRDSET *st)
702 {
703 unsigned long long microseconds = 0;
704
@@ -635,19 +708,19 @@ void rrd_stats_next(RRD_STATS *st)
708 microseconds = usecdiff(&now, &st->last_collected_time);
709 }
710
638 - rrd_stats_next_usec(st, microseconds);
711 + rrdset_next_usec(st, microseconds);
712 }
713
641 -void rrd_stats_next_plugins(RRD_STATS *st)
714 +void rrdset_next_plugins(RRDSET *st)
715 {
643 - rrd_stats_next(st);
716 + rrdset_next(st);
717 }
718
646 -unsigned long long rrd_stats_done(RRD_STATS *st)
719 +unsigned long long rrdset_done(RRDSET *st)
720 {
721 debug(D_RRD_CALLS, "rrd_stats_done() for chart %s", st->name);
722
650 - RRD_DIMENSION *rd, *last;
723 + RRDDIM *rd, *last;
724 int oldstate, store_this_entry = 1;
725
726 if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) != 0)
@@ -659,7 +732,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
732 // check if the chart has a long time to be refreshed
733 if(st->usec_since_last_update > st->entries * st->update_every * 1000000ULL) {
734 info("%s: took too long to be updated (%0.3Lf secs). Reseting it.", st->name, (long double)(st->usec_since_last_update / 1000000.0));
662 - rrd_stats_reset(st);
735 + rrdset_reset(st);
736 st->usec_since_last_update = st->update_every * 1000000ULL;
737 }
738 if(st->debug) debug(D_RRD_STATS, "%s: microseconds since last update: %llu", st->name, st->usec_since_last_update);
@@ -701,7 +774,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
774 // check if we will re-write the entire data set
775 if(usecdiff(&st->last_collected_time, &st->last_updated) > st->update_every * st->entries * 1000000ULL) {
776 info("%s: too old data (last updated at %u.%u, last collected at %u.%u). Reseting it. Will not store the next entry.", st->name, st->last_updated.tv_sec, st->last_updated.tv_usec, st->last_collected_time.tv_sec, st->last_collected_time.tv_usec);
704 - rrd_stats_reset(st);
777 + rrdset_reset(st);
778
779 st->usec_since_last_update = st->update_every * 1000000ULL;
780
@@ -759,7 +832,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
832 );
833
834 switch(rd->algorithm) {
762 - case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
835 + case RRDDIM_PCENT_OVER_DIFF_TOTAL:
836 // the percentage of the current increment
837 // over the increment of all dimensions together
838 if(st->collected_total == st->last_collected_total) rd->calculated_value = rd->last_calculated_value;
@@ -780,7 +853,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
853 );
854 break;
855
783 - case RRD_DIMENSION_PCENT_OVER_ROW_TOTAL:
856 + case RRDDIM_PCENT_OVER_ROW_TOTAL:
857 if(!st->collected_total) rd->calculated_value = 0;
858 else
859 // the percentage of the current value
@@ -802,10 +875,14 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
875 );
876 break;
877
805 - case RRD_DIMENSION_INCREMENTAL:
878 + case RRDDIM_INCREMENTAL:
879 // if the new is smaller than the old (an overflow, or reset), set the old equal to the new
880 // to reset the calculation (it will give zero as the calculation for this second)
881 if(rd->last_collected_value > rd->collected_value) {
882 + info("%s.%s: Detect RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
883 + , st->name, rd->name
884 + , rd->last_collected_value
885 + , rd->collected_value);
886 storage_flags = SN_EXISTS_RESET;
887 rd->last_collected_value = rd->collected_value;
888 }
@@ -822,7 +899,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
899 );
900 break;
901
825 - case RRD_DIMENSION_ABSOLUTE:
902 + case RRDDIM_ABSOLUTE:
903 rd->calculated_value = (calculated_number)rd->collected_value;
904
905 if(st->debug)
@@ -869,7 +946,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
946 calculated_number new_value;
947
948 switch(rd->algorithm) {
872 - case RRD_DIMENSION_INCREMENTAL:
949 + case RRDDIM_INCREMENTAL:
950 new_value = (calculated_number)
951 ( rd->calculated_value
952 * (calculated_number)(next_ut - last_ut)
@@ -892,9 +969,9 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
969 rd->calculated_value -= new_value;
970 break;
971
895 - case RRD_DIMENSION_ABSOLUTE:
896 - case RRD_DIMENSION_PCENT_OVER_ROW_TOTAL:
897 - case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
972 + case RRDDIM_ABSOLUTE:
973 + case RRDDIM_PCENT_OVER_ROW_TOTAL:
974 + case RRDDIM_PCENT_OVER_DIFF_TOTAL:
975 default:
976 new_value = (calculated_number)
977 ( ( (rd->calculated_value - rd->last_calculated_value)
@@ -926,7 +1003,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1003 continue;
1004 }
1005
929 - if(rd->updated && iterations < st->gap_when_lost_iterations) {
1006 + if(rd->updated && iterations < st->gap_when_lost_iterations_above) {
1007 rd->values[st->current_entry] = pack_storage_number(
1008 new_value
1009 * (calculated_number)rd->multiplier
@@ -1007,8 +1084,8 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1084 // we have to set the first calculated_value to zero
1085 // to eliminate the first spike
1086 if(st->counter_done == 1) switch(rd->algorithm) {
1010 - case RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL:
1011 - case RRD_DIMENSION_INCREMENTAL:
1087 + case RRDDIM_PCENT_OVER_DIFF_TOTAL:
1088 + case RRDDIM_INCREMENTAL:
1089 rd->calculated_value = 0;
1090 // the next time, a new incremental total will be calculated
1091 break;
@@ -1037,14 +1114,14 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1114 if(!last) {
1115 st->dimensions = rd->next;
1116 rd->next = NULL;
1040 - rrd_stats_dimension_free(rd);
1117 + rrddim_free(st, rd);
1118 rd = st->dimensions;
1119 continue;
1120 }
1121 else {
1122 last->next = rd->next;
1123 rd->next = NULL;
1047 - rrd_stats_dimension_free(rd);
1124 + rrddim_free(st, rd);
1125 rd = last->next;
1126 continue;
1127 }
@@ -1067,7 +1144,7 @@ unsigned long long rrd_stats_done(RRD_STATS *st)
1144
1145
1146 // find the oldest entry in the data, skipping all empty slots
1070 -time_t rrd_stats_first_entry_t(RRD_STATS *st)
1147 +time_t rrdset_first_entry_t(RRDSET *st)
1148 {
1149 if(!st->first_entry_t) return st->last_updated.tv_sec;
1150
src/rrd.h
+97 -77
@@ -1,6 +1,7 @@
1 #include <sys/time.h>
2 #include <pthread.h>
3
4 +#include "avl.h"
5 #include "storage_number.h"
6
7 #ifndef NETDATA_RRD_H
@@ -8,77 +9,81 @@
9
10 #define UPDATE_EVERY 1
11 #define UPDATE_EVERY_MAX 3600
11 -extern int update_every;
12 +extern int rrd_update_every;
13
13 -#define HISTORY 3600
14 -#define HISTORY_MAX (86400*10)
15 -extern int save_history;
14 +#define RRD_DEFAULT_HISTORY_ENTRIES 3600
15 +#define RRD_HISTORY_ENTRIES_MAX (86400*10)
16 +extern int rrd_default_history_entries;
17
17 -#define DEFAULT_GAP_INTERPOLATIONS 10
18 +#define RRD_DEFAULT_GAP_INTERPOLATIONS 10
19
20 typedef long long total_number;
20 -
21 #define TOTAL_NUMBER_FORMAT "%lld"
22
23 -#define RRD_STATS_NAME_MAX 1024
24 -
25 -#define RRD_STATS_MAGIC "NETDATA CACHE STATS FILE V010"
26 -#define RRD_DIMENSION_MAGIC "NETDATA CACHE DIMENSION FILE V010"
23 +#define RRD_ID_LENGTH_MAX 1024
24
25 +#define RRDSET_MAGIC "NETDATA CACHE STATS FILE V011"
26 +#define RRDDIMENSION_MAGIC "NETDATA CACHE DIMENSION FILE V011"
27
28 // ----------------------------------------------------------------------------
29 // chart types
30
32 -#define CHART_TYPE_LINE_NAME "line"
33 -#define CHART_TYPE_AREA_NAME "area"
34 -#define CHART_TYPE_STACKED_NAME "stacked"
31 +#define RRDSET_TYPE_LINE_NAME "line"
32 +#define RRDSET_TYPE_AREA_NAME "area"
33 +#define RRDSET_TYPE_STACKED_NAME "stacked"
34
36 -#define CHART_TYPE_LINE 0
37 -#define CHART_TYPE_AREA 1
38 -#define CHART_TYPE_STACKED 2
35 +#define RRDSET_TYPE_LINE 0
36 +#define RRDSET_TYPE_AREA 1
37 +#define RRDSET_TYPE_STACKED 2
38
40 -int chart_type_id(const char *name);
41 -const char *chart_type_name(int chart_type);
39 +int rrdset_type_id(const char *name);
40 +const char *rrdset_type_name(int chart_type);
41
42
43 // ----------------------------------------------------------------------------
44 // memory mode
45
47 -#define NETDATA_MEMORY_MODE_RAM_NAME "ram"
48 -#define NETDATA_MEMORY_MODE_MAP_NAME "map"
49 -#define NETDATA_MEMORY_MODE_SAVE_NAME "save"
46 +#define RRD_MEMORY_MODE_RAM_NAME "ram"
47 +#define RRD_MEMORY_MODE_MAP_NAME "map"
48 +#define RRD_MEMORY_MODE_SAVE_NAME "save"
49
51 -#define NETDATA_MEMORY_MODE_RAM 0
52 -#define NETDATA_MEMORY_MODE_MAP 1
53 -#define NETDATA_MEMORY_MODE_SAVE 2
50 +#define RRD_MEMORY_MODE_RAM 0
51 +#define RRD_MEMORY_MODE_MAP 1
52 +#define RRD_MEMORY_MODE_SAVE 2
53
55 -extern int memory_mode;
54 +extern int rrd_memory_mode;
55
57 -extern const char *memory_mode_name(int id);
58 -extern int memory_mode_id(const char *name);
56 +extern const char *rrd_memory_mode_name(int id);
57 +extern int rrd_memory_mode_id(const char *name);
58
59
60 // ----------------------------------------------------------------------------
61 // algorithms types
62
64 -#define RRD_DIMENSION_ABSOLUTE_NAME "absolute"
65 -#define RRD_DIMENSION_INCREMENTAL_NAME "incremental"
66 -#define RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL_NAME "percentage-of-incremental-row"
67 -#define RRD_DIMENSION_PCENT_OVER_ROW_TOTAL_NAME "percentage-of-absolute-row"
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"
67 +
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
72 +
73 +extern int rrddim_algorithm_id(const char *name);
74 +extern const char *rrddim_algorithm_name(int chart_type);
75
69 -#define RRD_DIMENSION_ABSOLUTE 0
70 -#define RRD_DIMENSION_INCREMENTAL 1
71 -#define RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL 2
72 -#define RRD_DIMENSION_PCENT_OVER_ROW_TOTAL 3
76
74 -extern int algorithm_id(const char *name);
75 -extern const char *algorithm_name(int chart_type);
77 +// ----------------------------------------------------------------------------
78 +// RRD DIMENSION
79 +
80 +struct rrddim {
81 + avl avl;
82
77 -struct rrd_dimension {
78 - char magic[sizeof(RRD_DIMENSION_MAGIC) + 1]; // our magic
79 - char id[RRD_STATS_NAME_MAX + 1]; // the id of this dimension (for internal identification)
80 - char *name; // the name of this dimension (as presented to user)
81 - char cache_file[FILENAME_MAX+1];
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];
87
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
@@ -110,19 +115,25 @@ struct rrd_dimension {
115 calculated_number collected_volume;
116 calculated_number stored_volume;
117
113 - struct rrd_dimension *next; // linking of dimensions within the same data set
118 + struct rrddim *next; // linking of dimensions within the same data set
119
120 storage_number values[]; // the array of values - THIS HAS TO BE THE LAST MEMBER
121 };
117 -typedef struct rrd_dimension RRD_DIMENSION;
122 +typedef struct rrddim RRDDIM;
123 +
124 +
125 +// ----------------------------------------------------------------------------
126 +// RRDSET
127 +
128 +struct rrdset {
129 + avl avl;
130
119 -struct rrd_stats {
120 - char magic[sizeof(RRD_STATS_MAGIC) + 1]; // our magic
131 + char magic[sizeof(RRDSET_MAGIC) + 1]; // our magic
132
122 - char id[RRD_STATS_NAME_MAX + 1]; // id of the data set
123 - char *name; // name of the data set
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
125 - char cache_file[FILENAME_MAX+1];
136 + char cache_filename[FILENAME_MAX+1];
137
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,7 +151,7 @@ struct rrd_stats {
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
153
143 - int gap_when_lost_iterations; // after how many lost iterations a gap should be stored
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
156
157 long priority;
@@ -164,49 +175,58 @@ struct rrd_stats {
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)
177
167 - RRD_DIMENSION *dimensions; // the actual data for every dimension
178 + RRDDIM *dimensions; // the actual data for every dimension
179
169 - struct rrd_stats *next; // linking of rrd stats
180 + avl_tree dimensions_index;
181 +
182 + struct rrdset *next; // linking of rrdsets
183 };
171 -typedef struct rrd_stats RRD_STATS;
184 +typedef struct rrdset RRDSET;
185 +
186 +extern RRDSET *rrdset_root;
187 +extern pthread_rwlock_t rrdset_root_rwlock;
188
173 -extern RRD_STATS *root;
174 -extern pthread_rwlock_t root_rwlock;
189 +// ----------------------------------------------------------------------------
190 +// RRD SET functions
191 +
192 +extern char *rrdset_strncpy_name(char *to, const char *from, int length);
193 +extern void rrdset_set_name(RRDSET *st, const char *name);
194
176 -extern char *rrd_stats_strncpy_name(char *to, const char *from, int length);
177 -extern void rrd_stats_set_name(RRD_STATS *st, const char *name);
195 +extern char *rrdset_cache_dir(const char *id);
196
179 -extern char *rrd_stats_cache_dir(const char *id);
197 +extern void rrdset_reset(RRDSET *st);
198
181 -extern void rrd_stats_reset(RRD_STATS *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);
200
183 -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);
201 +extern void rrdset_free_all(void);
202 +extern void rrdset_save_all(void);
203
185 -extern RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
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);
207
187 -extern void rrd_stats_dimension_set_name(RRD_STATS *st, RRD_DIMENSION *rd, const char *name);
188 -extern void rrd_stats_dimension_free(RRD_DIMENSION *rd);
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);
211
190 -extern void rrd_stats_free_all(void);
191 -extern void rrd_stats_save_all(void);
212 +extern unsigned long long rrdset_done(RRDSET *st);
213
193 -extern RRD_STATS *rrd_stats_find(const char *id);
194 -extern RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id);
195 -extern RRD_STATS *rrd_stats_find_byname(const char *name);
214 +extern time_t rrdset_first_entry_t(RRDSET *st);
215
197 -extern RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id);
216
199 -extern int rrd_stats_dimension_hide(RRD_STATS *st, const char *id);
217 +// ----------------------------------------------------------------------------
218 +// RRD DIMENSION functions
219 +
220 +extern RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier, long divisor, int algorithm);
221
201 -extern void rrd_stats_dimension_set_by_pointer(RRD_STATS *st, RRD_DIMENSION *rd, collected_number value);
202 -extern int rrd_stats_dimension_set(RRD_STATS *st, const char *id, collected_number value);
222 +extern void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name);
223 +extern void rrddim_free(RRDSET *st, RRDDIM *rd);
224
204 -extern void rrd_stats_next_usec(RRD_STATS *st, unsigned long long microseconds);
205 -extern void rrd_stats_next(RRD_STATS *st);
206 -extern void rrd_stats_next_plugins(RRD_STATS *st);
225 +extern RRDDIM *rrddim_find(RRDSET *st, const char *id);
226
208 -extern unsigned long long rrd_stats_done(RRD_STATS *st);
227 +extern int rrddim_hide(RRDSET *st, const char *id);
228
210 -extern time_t rrd_stats_first_entry_t(RRD_STATS *st);
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);
231
232 #endif /* NETDATA_RRD_H */
src/rrd2json.c
+17 -17
@@ -8,7 +8,7 @@
8 #define HOSTNAME_MAX 1024
9 char *hostname = "unknown";
10
11 -unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer *wb)
11 +unsigned long rrd_stats_one_json(RRDSET *st, char *options, struct web_buffer *wb)
12 {
13 time_t now = time(NULL);
14 web_buffer_increase(wb, 16384);
@@ -48,10 +48,10 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
48 , st->enabled
49 , st->units
50 , st->name, options?options:""
51 - , chart_type_name(st->chart_type)
51 + , rrdset_type_name(st->chart_type)
52 , st->counter
53 , st->entries
54 - , rrd_stats_first_entry_t(st)
54 + , rrdset_first_entry_t(st)
55 , st->current_entry
56 , st->last_updated.tv_sec
57 , now - (st->last_updated.tv_sec > now) ? now : st->last_updated.tv_sec
@@ -64,7 +64,7 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
64
65 unsigned long memory = st->memsize;
66
67 - RRD_DIMENSION *rd;
67 + RRDDIM *rd;
68 for(rd = st->dimensions; rd ; rd = rd->next) {
69 memory += rd->memsize;
70
@@ -88,7 +88,7 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
88 , rd->name
89 , rd->entries
90 , rd->hidden
91 - , algorithm_name(rd->algorithm)
91 + , rrddim_algorithm_name(rd->algorithm)
92 , rd->multiplier
93 , rd->divisor
94 , rd->last_collected_time.tv_sec
@@ -115,7 +115,7 @@ unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer
115 #define RRD_GRAPH_JSON_HEADER "{\n\t\"charts\": [\n"
116 #define RRD_GRAPH_JSON_FOOTER "\n\t]\n}\n"
117
118 -void rrd_stats_graph_json(RRD_STATS *st, char *options, struct web_buffer *wb)
118 +void rrd_stats_graph_json(RRDSET *st, char *options, struct web_buffer *wb)
119 {
120 web_buffer_increase(wb, 16384);
121
@@ -130,19 +130,19 @@ void rrd_stats_all_json(struct web_buffer *wb)
130
131 unsigned long memory = 0;
132 long c;
133 - RRD_STATS *st;
133 + RRDSET *st;
134
135 web_buffer_printf(wb, RRD_GRAPH_JSON_HEADER);
136
137 - pthread_rwlock_rdlock(&root_rwlock);
138 - for(st = root, c = 0; st ; st = st->next) {
137 + pthread_rwlock_rdlock(&rrdset_root_rwlock);
138 + for(st = rrdset_root, c = 0; st ; st = st->next) {
139 if(st->enabled) {
140 if(c) web_buffer_printf(wb, "%s", ",\n");
141 memory += rrd_stats_one_json(st, NULL, wb);
142 c++;
143 }
144 }
145 - pthread_rwlock_unlock(&root_rwlock);
145 + pthread_rwlock_unlock(&rrdset_root_rwlock);
146
147 web_buffer_printf(wb, "\n\t],\n"
148 "\t\"hostname\": \"%s\",\n"
@@ -151,13 +151,13 @@ void rrd_stats_all_json(struct web_buffer *wb)
151 "\t\"memory\": %lu\n"
152 "}\n"
153 , hostname
154 - , update_every
155 - , save_history
154 + , rrd_update_every
155 + , rrd_default_history_entries
156 , memory
157 );
158 }
159
160 -unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, int entries_to_show, int group, int group_method, time_t after, time_t before, int only_non_zero)
160 +unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int entries_to_show, int group, int group_method, time_t after, time_t before, int only_non_zero)
161 {
162 int c;
163 pthread_rwlock_rdlock(&st->rwlock);
@@ -198,7 +198,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, int
198 time_t time_init = st->last_updated.tv_sec;
199
200 if(before == 0 || before > time_init) before = time_init;
201 - if(after == 0) after = rrd_stats_first_entry_t(st);
201 + if(after == 0) after = rrdset_first_entry_t(st);
202
203
204 // ---
@@ -212,7 +212,7 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, int
212 // find how many dimensions we have
213
214 int dimensions = 0;
215 - RRD_DIMENSION *rd;
215 + RRDDIM *rd;
216 for( rd = st->dimensions ; rd ; rd = rd->next) dimensions++;
217 if(!dimensions) {
218 pthread_rwlock_unlock(&st->rwlock);
@@ -238,9 +238,9 @@ unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, int
238 if(st->debug) {
239 debug(D_RRD_STATS, "%s first_entry_t = %lu, last_entry_t = %lu, duration = %lu, after = %lu, before = %lu, duration = %lu, entries_to_show = %lu, group = %lu, max_entries = %ld"
240 , st->id
241 - , rrd_stats_first_entry_t(st)
241 + , rrdset_first_entry_t(st)
242 , st->last_updated.tv_sec
243 - , st->last_updated.tv_sec - rrd_stats_first_entry_t(st)
243 + , st->last_updated.tv_sec - rrdset_first_entry_t(st)
244 , after
245 , before
246 , before - after
src/rrd2json.h
+3 -3
@@ -18,12 +18,12 @@ extern char *hostname;
18 #define GROUP_MAX 1
19 #define GROUP_SUM 2
20
21 -extern unsigned long rrd_stats_one_json(RRD_STATS *st, char *options, struct web_buffer *wb);
21 +extern unsigned long rrd_stats_one_json(RRDSET *st, char *options, struct web_buffer *wb);
22
23 -extern void rrd_stats_graph_json(RRD_STATS *st, char *options, struct web_buffer *wb);
23 +extern void rrd_stats_graph_json(RRDSET *st, char *options, struct web_buffer *wb);
24
25 extern void rrd_stats_all_json(struct web_buffer *wb);
26
27 -extern unsigned long rrd_stats_json(int type, RRD_STATS *st, struct web_buffer *wb, int entries_to_show, int group, int group_method, time_t after, time_t before, int only_non_zero);
27 +extern unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int entries_to_show, int group, int group_method, time_t after, time_t before, int only_non_zero);
28
29 #endif /* NETDATA_RRD2JSON_H */
src/unit_test.c
+18 -18
@@ -246,32 +246,32 @@ int unit_test(long delay, long shift)
246 snprintf(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
247
248 debug_flags = 0xffffffff;
249 - memory_mode = NETDATA_MEMORY_MODE_RAM;
250 - update_every = 1;
249 + rrd_memory_mode = RRD_MEMORY_MODE_RAM;
250 + rrd_update_every = 1;
251
252 int do_abs = 1;
253 int do_inc = 1;
254 int do_abst = 1;
255 int do_absi = 1;
256
257 - RRD_STATS *st = rrd_stats_create("netdata", name, name, "netdata", "Unit Testing", "a value", 1, 1, CHART_TYPE_LINE);
257 + RRDSET *st = rrdset_create("netdata", name, name, "netdata", "Unit Testing", "a value", 1, 1, RRDSET_TYPE_LINE);
258 st->debug = 1;
259
260 - RRD_DIMENSION *rdabs = NULL;
261 - RRD_DIMENSION *rdinc = NULL;
262 - RRD_DIMENSION *rdabst = NULL;
263 - RRD_DIMENSION *rdabsi = NULL;
260 + RRDDIM *rdabs = NULL;
261 + RRDDIM *rdinc = NULL;
262 + RRDDIM *rdabst = NULL;
263 + RRDDIM *rdabsi = NULL;
264
265 - if(do_abs) rdabs = rrd_stats_dimension_add(st, "absolute", "absolute", 1, 1, RRD_DIMENSION_ABSOLUTE);
266 - if(do_inc) rdinc = rrd_stats_dimension_add(st, "incremental", "incremental", 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
267 - if(do_abst) rdabst = rrd_stats_dimension_add(st, "percentage-of-absolute-row", "percentage-of-absolute-row", 1, 1, RRD_DIMENSION_PCENT_OVER_ROW_TOTAL);
268 - if(do_absi) rdabsi = rrd_stats_dimension_add(st, "percentage-of-incremental-row", "percentage-of-incremental-row", 1, 1, RRD_DIMENSION_PCENT_OVER_DIFF_TOTAL);
265 + if(do_abs) rdabs = rrddim_add(st, "absolute", "absolute", 1, 1, RRDDIM_ABSOLUTE);
266 + if(do_inc) rdinc = rrddim_add(st, "incremental", "incremental", 1, 1 * rrd_update_every, RRDDIM_INCREMENTAL);
267 + if(do_abst) rdabst = rrddim_add(st, "percentage-of-absolute-row", "percentage-of-absolute-row", 1, 1, RRDDIM_PCENT_OVER_ROW_TOTAL);
268 + if(do_absi) rdabsi = rrddim_add(st, "percentage-of-incremental-row", "percentage-of-incremental-row", 1, 1, RRDDIM_PCENT_OVER_DIFF_TOTAL);
269
270 long increment = 1000;
271 collected_number i = 0;
272
273 unsigned long c, dimensions = 0;
274 - RRD_DIMENSION *rd;
274 + RRDDIM *rd;
275 for(rd = st->dimensions ; rd ; rd = rd->next) dimensions++;
276
277 for(c = 0; c < 20 ;c++) {
@@ -279,12 +279,12 @@ int unit_test(long delay, long shift)
279
280 fprintf(stderr, "\n\nLOOP = %lu, DELAY = %ld, VALUE = " COLLECTED_NUMBER_FORMAT "\n", c, delay, i);
281 if(c) {
282 - rrd_stats_next_usec(st, delay);
282 + rrdset_next_usec(st, delay);
283 }
284 - if(do_abs) rrd_stats_dimension_set(st, "absolute", i);
285 - if(do_inc) rrd_stats_dimension_set(st, "incremental", i);
286 - if(do_abst) rrd_stats_dimension_set(st, "percentage-of-absolute-row", i);
287 - if(do_absi) rrd_stats_dimension_set(st, "percentage-of-incremental-row", i);
284 + if(do_abs) rrddim_set(st, "absolute", i);
285 + if(do_inc) rrddim_set(st, "incremental", i);
286 + if(do_abst) rrddim_set(st, "percentage-of-absolute-row", i);
287 + if(do_absi) rrddim_set(st, "percentage-of-incremental-row", i);
288
289 if(!c) {
290 gettimeofday(&st->last_collected_time, NULL);
@@ -294,7 +294,7 @@ int unit_test(long delay, long shift)
294 // prevent it from deleting the dimensions
295 for(rd = st->dimensions ; rd ; rd = rd->next) rd->last_collected_time.tv_sec = st->last_collected_time.tv_sec;
296
297 - rrd_stats_done(st);
297 + rrdset_done(st);
298 }
299
300 unsigned long oincrement = increment;
src/web_server.c
+24 -6
@@ -11,6 +11,7 @@
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <netinet/tcp.h>
14 +#include <malloc.h>
15
16 #include "common.h"
17 #include "log.h"
@@ -26,6 +27,23 @@
27 int listen_fd = -1;
28 int listen_port = LISTEN_PORT;
29
30 +static void log_allocations(void)
31 +{
32 + static int mem = 0;
33 +
34 + struct mallinfo mi;
35 +
36 + mi = mallinfo();
37 + if(mi.uordblks > mem) {
38 + int clients = 0;
39 + struct web_client *w;
40 + for(w = web_clients; w ; w = w->next) clients++;
41 +
42 + info("Allocated memory increased from %d to %d (increased by %d bytes). There are %d web clients connected.", mem, mi.uordblks, mi.uordblks - mem, clients);
43 + mem = mi.uordblks;
44 + }
45 +}
46 +
47 int create_listen_socket(int port)
48 {
49 int sock=-1;
@@ -257,8 +275,8 @@ int web_client_data_request(struct web_client *w, char *url, int datasource_type
275 debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);
276
277 // do we have such a data set?
260 - RRD_STATS *st = rrd_stats_find_byname(tok);
261 - if(!st) st = rrd_stats_find(tok);
278 + RRDSET *st = rrdset_find_byname(tok);
279 + if(!st) st = rrdset_find(tok);
280 if(!st) {
281 // we don't have it
282 // try to send a file with that name
@@ -270,7 +288,7 @@ int web_client_data_request(struct web_client *w, char *url, int datasource_type
288 debug(D_WEB_CLIENT, "%llu: Found RRD data with name '%s'.", w->id, tok);
289
290 // how many entries does the client want?
273 - long lines = save_history;
291 + long lines = rrd_default_history_entries;
292 long group_count = 1;
293 time_t after = 0, before = 0;
294 int group_method = GROUP_AVERAGE;
@@ -472,7 +490,7 @@ void web_client_process(struct web_client *w)
490 debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);
491
492 // do we have such a data set?
475 - RRD_STATS *st = rrd_stats_find_byname(tok);
493 + RRDSET *st = rrdset_find_byname(tok);
494 if(!st) {
495 // we don't have it
496 // try to send a file with that name
@@ -495,7 +513,7 @@ void web_client_process(struct web_client *w)
513 debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok);
514
515 // do we have such a data set?
498 - RRD_STATS *st = rrd_stats_find_byname(tok);
516 + RRDSET *st = rrdset_find_byname(tok);
517 if(!st) {
518 code = 404;
519 web_buffer_printf(w->data, "Chart %s is not found.\r\n", tok);
@@ -528,7 +546,7 @@ void web_client_process(struct web_client *w)
546 debug(D_WEB_CLIENT_ACCESS, "%llu: Sending list of RRD_STATS...", w->id);
547
548 w->data->bytes = 0;
531 - RRD_STATS *st = root;
549 + RRDSET *st = rrdset_root;
550
551 for ( ; st ; st = st->next )
552 web_buffer_printf(w->data, "%s\n", st->name);