all required system headers in common.h; some progress on health variables
Costa Tsaousis committed
Aug 6, 2016 at 03:52 UTC
f399edf7dffc296873c14fa0fca3f593674b291a
65 files changed
+240
-809
CMakeLists.txt
+1
-1
@@ -82,7 +82,7 @@ set(NETDATA_SOURCE_FILES
82
src/web_client.h
83
src/web_server.c
84
src/web_server.h
85
- config.h)
85
+ config.h src/health.h src/health.c)
86
87
set(APPS_PLUGIN_SOURCE_FILES
88
src/appconfig.c
src/Makefile.am
+1
@@ -33,6 +33,7 @@ netdata_SOURCES = \
33
daemon.c daemon.h \
34
dictionary.c dictionary.h \
35
global_statistics.c global_statistics.h \
36
+ health.c health.h \
37
log.c log.h \
38
main.c main.h \
39
plugin_checks.c plugin_checks.h \
src/appconfig.c
-18
@@ -1,22 +1,4 @@
1
-
2
-/*
3
- * TODO
4
- *
5
- * 1. Re-write this using DICTIONARY
6
- *
7
- */
8
-
9
-#ifdef HAVE_CONFIG_H
10
-#include <config.h>
11
-#endif
12
-#include <pthread.h>
13
-#include <stdlib.h>
14
-#include <string.h>
15
-
16
-#include "avl.h"
1
#include "common.h"
18
-#include "appconfig.h"
19
-#include "log.h"
2
3
#define CONFIG_FILE_LINE_MAX ((CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 1024) * 2)
4
src/appconfig.h
-2
@@ -1,5 +1,3 @@
1
-#include "web_buffer.h"
2
-
1
#ifndef NETDATA_CONFIG_H
2
#define NETDATA_CONFIG_H 1
3
src/apps_plugin.c
-40
@@ -1,44 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <time.h>
8
-#include <unistd.h>
9
-#include <sys/types.h>
10
-#include <sys/time.h>
11
-#include <sys/wait.h>
12
-#include <sys/stat.h>
13
-
14
-#include <sys/resource.h>
15
-#include <sys/stat.h>
16
-
17
-#include <errno.h>
18
-#include <stdarg.h>
19
-#include <locale.h>
20
-#include <ctype.h>
21
-#include <fcntl.h>
22
-
23
-#include <malloc.h>
24
-#include <dirent.h>
25
-#include <arpa/inet.h>
26
-
27
-#include <sys/types.h>
28
-#include <pwd.h>
29
-#include <grp.h>
30
-
31
-#include "avl.h"
32
-
1
#include "common.h"
34
-#include "log.h"
35
-#include "procfile.h"
36
-#include "../config.h"
37
-#include "web_buffer.h"
38
-
39
-#ifdef NETDATA_INTERNAL_CHECKS
40
-#include <sys/prctl.h>
41
-#endif
2
3
#define MAX_COMPARE_NAME 100
4
#define MAX_NAME 100
src/avl.c
+1
-7
@@ -1,10 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-// #include <assert.h>
5
-
6
-#include "avl.h"
7
-#include "log.h"
1
+#include "common.h"
2
3
/* ------------------------------------------------------------------------- */
4
/*
src/common.c
-17
@@ -1,21 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <sys/syscall.h>
5
-#include <string.h>
6
-#include <ctype.h>
7
-#include <errno.h>
8
-#include <unistd.h>
9
-#include <sys/types.h>
10
-#include <sys/stat.h>
11
-#include <fcntl.h>
12
-#include <sys/mman.h>
13
-#include <time.h>
14
-
15
-#include "log.h"
1
#include "common.h"
17
-#include "appconfig.h"
18
-#include "../config.h"
2
3
char *global_host_prefix = "";
4
int enable_ksm = 1;
src/common.h
+100
-6
@@ -1,20 +1,114 @@
1
+#ifndef NETDATA_COMMON_H
2
+#define NETDATA_COMMON_H 1
3
+
4
+#ifdef HAVE_CONFIG_H
5
+#include <config.h>
6
+#endif
7
+
8
+#include <pthread.h>
9
+#include <errno.h>
10
+
11
+#include <stdio.h>
12
+#include <stdlib.h>
13
#include <stdarg.h>
2
-#include <sys/time.h>
14
+#include <stddef.h>
15
+
16
+#include <ctype.h>
17
+#include <string.h>
18
+#include <strings.h>
19
+
20
+#include <arpa/inet.h>
21
+#include <netinet/in.h>
22
+#include <netinet/tcp.h>
23
+
24
+#include <dirent.h>
25
+#include <fcntl.h>
26
+#include <getopt.h>
27
+#include <grp.h>
28
+#include <pwd.h>
29
+#include <locale.h>
30
+#include <malloc.h>
31
+#include <netdb.h>
32
+#include <poll.h>
33
+#include <signal.h>
34
+#include <syslog.h>
35
+#include <sys/mman.h>
36
#include <sys/resource.h>
4
-#include <stdio.h>
37
+#include <sys/socket.h>
38
+#include <sys/stat.h>
39
+#include <sys/statvfs.h>
40
+#include <sys/syscall.h>
41
+#include <sys/time.h>
42
+#include <sys/types.h>
43
+#include <sys/wait.h>
44
+#include <time.h>
45
+#include <unistd.h>
46
+#include <uuid/uuid.h>
47
6
-#ifndef NETDATA_COMMON_H
7
-#define NETDATA_COMMON_H 1
48
+#ifdef STORAGE_WITH_MATH
49
+#include <math.h>
50
+#endif
51
52
#if defined(HAVE_INTTYPES_H)
53
#include <inttypes.h>
54
#elif defined(HAVE_STDINT_H)
55
#include <stdint.h>
56
#endif
14
-#include <sys/types.h>
15
-#include <unistd.h>
57
58
+#ifdef NETDATA_INTERNAL_CHECKS
59
+#include <sys/prctl.h>
60
+#endif
61
+
62
+#ifdef NETDATA_WITH_ZLIB
63
+#include <zlib.h>
64
+#endif
65
+
66
+#include "avl.h"
67
+#include "log.h"
68
+#include "global_statistics.h"
69
+#include "storage_number.h"
70
+#include "web_buffer.h"
71
+#include "web_buffer_svg.h"
72
+#include "url.h"
73
+#include "popen.h"
74
+
75
+#include "procfile.h"
76
+#include "appconfig.h"
77
+#include "dictionary.h"
78
+#include "proc_self_mountinfo.h"
79
+#include "plugin_checks.h"
80
+#include "plugin_idlejitter.h"
81
+#include "plugin_nfacct.h"
82
+#include "plugin_proc.h"
83
+#include "plugin_tc.h"
84
+#include "plugins_d.h"
85
+
86
+#include "health.h"
87
+
88
+#include "rrd.h"
89
+#include "rrd2json.h"
90
+
91
+#include "web_client.h"
92
+#include "web_server.h"
93
+
94
+#include "registry.h"
95
+#include "daemon.h"
96
+#include "main.h"
97
+#include "unit_test.h"
98
+
99
+#if __GNUC__
100
+#if __x86_64__ || __ppc64__
101
+#define ENVIRONMENT64
102
+#else
103
+#define ENVIRONMENT32
104
+#endif
105
+#endif
106
+
107
+#ifdef abs
108
+#undef abs
109
+#endif
110
#define abs(x) ((x < 0)? -x : x)
111
+
112
#define usecdiff(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
113
114
extern void netdata_fix_chart_id(char *s);
src/daemon.c
-25
@@ -1,29 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <unistd.h>
7
-#include <fcntl.h>
8
-#include <errno.h>
9
-#include <signal.h>
10
-#include <string.h>
11
-#include <sys/types.h>
12
-#include <pwd.h>
13
-#include <grp.h>
14
-#include <pthread.h>
15
-#include <sys/wait.h>
16
-#include <sys/stat.h>
17
-
1
#include "common.h"
19
-#include "appconfig.h"
20
-#include "log.h"
21
-#include "web_client.h"
22
-#include "plugins_d.h"
23
-#include "rrd.h"
24
-#include "popen.h"
25
-#include "main.h"
26
-#include "daemon.h"
2
3
char pidfile[FILENAME_MAX + 1] = "";
4
src/dictionary.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-
5
-#include <pthread.h>
6
-#include <stdlib.h>
7
-#include <string.h>
8
-
9
-#include "avl.h"
1
#include "common.h"
11
-#include "log.h"
12
-
13
-#include "dictionary.h"
2
3
// ----------------------------------------------------------------------------
4
// dictionary statistics
src/dictionary.h
-5
@@ -1,8 +1,3 @@
1
-#include <pthread.h>
2
-
3
-#include "web_buffer.h"
4
-#include "avl.h"
5
-
1
#ifndef NETDATA_DICTIONARY_H
2
#define NETDATA_DICTIONARY_H 1
3
src/global_statistics.c
+1
-6
@@ -1,9 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <pthread.h>
5
-
6
-#include "global_statistics.h"
1
+#include "common.h"
2
3
struct global_statistics global_statistics = { 0, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL};
4
src/health.c
new
+53
@@ -0,0 +1,53 @@
1
+#include "common.h"
2
+
3
+int rrdvar_compare(void* a, void* b) {
4
+ if(((RRDVAR *)a)->hash < ((RRDVAR *)b)->hash) return -1;
5
+ else if(((RRDVAR *)a)->hash > ((RRDVAR *)b)->hash) return 1;
6
+ else return strcmp(((RRDVAR *)a)->name, ((RRDVAR *)b)->name);
7
+}
8
+
9
+#define rrdvar_index_add(tree, rv) (RRDVAR *)avl_insert_lock(tree, (avl *)(rv))
10
+#define rrdvar_index_del(tree, rv) (RRDVAR *)avl_remove_lock(tree, (avl *)(rv))
11
+
12
+static RRDVAR *rrdvar_index_find(avl_tree_lock *tree, const char *name, uint32_t hash) {
13
+ RRDVAR tmp;
14
+ tmp.name = (char *)name;
15
+ tmp.hash = (hash)?hash:simple_hash(tmp.name);
16
+
17
+ return (RRDVAR *)avl_search_lock(tree, (avl *)&tmp);
18
+}
19
+
20
+
21
+RRDVAR *rrdvar_get(RRDHOST *host, RRDCONTEXT *co, RRDSET *st, const char *name) {
22
+ uint32_t hash = simple_hash(name);
23
+
24
+ RRDVAR *ret = NULL;
25
+ RRDVAR *rv = rrdvar_index_find(&st->variables_root_index, name, hash);
26
+ if(!rv) {
27
+ rv = calloc(1, sizeof(RRDVAR));
28
+ if(!rv) fatal("Cannot allocate memory for RRDVAR");
29
+
30
+ rv->name = strdup(name);
31
+ if(!rv->name) fatal("Cannot allocate memory for RRDVAR name");
32
+
33
+ rv->hash = hash;
34
+
35
+ ret = rrdvar_index_add(&st->variables_root_index, rv);
36
+ if(ret != rv) {
37
+ error("Duplicate RRDVAR '%s' found on chart '%s'", name, st->id);
38
+ free(rv->name);
39
+ free(rv);
40
+ rv = ret;
41
+ }
42
+
43
+ ret = rrdvar_index_add(&co->variables_root_index, rv);
44
+ if(ret != rv)
45
+ debug(D_VARIABLES, "Variable '%s' in context '%s' does not come from chart '%s'", name, co->id, st->id);
46
+
47
+ ret = rrdvar_index_add(&host->variables_root_index, rv);
48
+ if(ret != rv)
49
+ debug(D_VARIABLES, "Variable '%s' in host '%s' does not come from chart '%s'", name, host->hostname, st->id);
50
+ }
51
+
52
+ return rv;
53
+}
src/health.h
new
+58
@@ -0,0 +1,58 @@
1
+#ifndef NETDATA_HEALTH_H
2
+#define NETDATA_HEALTH_H
3
+
4
+extern int rrdvar_compare(void *a, void *b);
5
+
6
+/*
7
+ * RRDVAR
8
+ * a variable
9
+ *
10
+ * There are 4 scopes: local (chart), context, host and global variables
11
+ *
12
+ * Standard global variables:
13
+ * $now
14
+ *
15
+ * Standard host variables:
16
+ * - none -
17
+ *
18
+ * Standard context variables:
19
+ * - none -
20
+ *
21
+ * Standard local variables:
22
+ * $last_updated
23
+ * $last_collected_value
24
+ * $last_value
25
+ *
26
+ */
27
+
28
+typedef struct rrdvar {
29
+ avl avl;
30
+
31
+ char *name;
32
+ uint32_t hash;
33
+
34
+ calculated_number *value;
35
+
36
+ time_t last_updated;
37
+} RRDVAR;
38
+
39
+typedef struct rrdcalc {
40
+ avl avl;
41
+
42
+ int group; // grouping method: average, max, etc.
43
+ int before; // ending point in time-series
44
+ int after; // starting point in time-series
45
+ int update_every; // update frequency for the calculation
46
+
47
+ const char *name;
48
+ calculated_number value;
49
+
50
+ RRDVAR *local;
51
+ RRDVAR *context;
52
+ RRDVAR *host;
53
+
54
+ struct rrdcalc *next;
55
+ struct rrdcalc *prev;
56
+} RRDCALC;
57
+
58
+#endif //NETDATA_HEALTH_H
src/log.c
-12
@@ -1,17 +1,5 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <time.h>
5
-#include <syslog.h>
6
-#include <errno.h>
7
-#include <string.h>
8
-#include <unistd.h>
9
-#include <stdlib.h>
10
-
11
-#include "log.h"
1
#include "common.h"
2
14
-
3
// ----------------------------------------------------------------------------
4
// LOG
5
src/log.h
+1
-6
@@ -1,9 +1,3 @@
1
-#include <stdio.h>
2
-#include <stdarg.h>
3
-#include <time.h>
4
-
5
-#include "main.h"
6
-
1
#ifndef NETDATA_LOG_H
2
#define NETDATA_LOG_H 1
3
@@ -29,6 +23,7 @@
23
#define D_MEMORY 0x00080000
24
#define D_CGROUP 0x00100000
25
#define D_REGISTRY 0x00200000
26
+#define D_VARIABLES 0x00400000
27
28
//#define DEBUG (D_WEB_CLIENT_ACCESS|D_LISTENER|D_RRD_STATS)
29
//#define DEBUG 0xffffffff
src/main.c
-36
@@ -1,40 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <errno.h>
5
-#include <getopt.h>
6
-#include <pthread.h>
7
-#include <signal.h>
8
-#include <stdio.h>
9
-#include <stdlib.h>
10
-#include <string.h>
11
-#include <sys/mman.h>
12
-#include <sys/prctl.h>
13
-#include <sys/wait.h>
14
-#include <syslog.h>
15
-#include <unistd.h>
16
-
17
-#include "appconfig.h"
1
#include "common.h"
19
-#include "daemon.h"
20
-#include "log.h"
21
-#include "popen.h"
22
-#include "rrd.h"
23
-#include "rrd2json.h"
24
-#include "web_client.h"
25
-#include "web_server.h"
26
-
27
-#include "unit_test.h"
28
-
29
-#include "plugin_checks.h"
30
-#include "plugin_idlejitter.h"
31
-#include "plugin_nfacct.h"
32
-#include "registry.h"
33
-#include "plugin_proc.h"
34
-#include "plugin_tc.h"
35
-#include "plugins_d.h"
36
-
37
-#include "main.h"
2
3
extern void *cgroups_main(void *ptr);
4
src/main.h
-4
@@ -1,10 +1,6 @@
1
-#include <getopt.h>
2
-
1
#ifndef NETDATA_MAIN_H
2
#define NETDATA_MAIN_H 1
3
6
-#include <signal.h>
7
-
4
extern volatile sig_atomic_t netdata_exit;
5
6
/**
src/plugin_checks.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <pthread.h>
5
-#include <sys/time.h>
6
-#include <sys/resource.h>
7
-#include <strings.h>
8
-#include <unistd.h>
9
-
1
#include "common.h"
11
-#include "appconfig.h"
12
-#include "log.h"
13
-#include "rrd.h"
14
-#include "plugin_checks.h"
2
3
void *checks_main(void *ptr)
4
{
src/plugin_idlejitter.c
-14
@@ -1,18 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <pthread.h>
5
-#include <sys/time.h>
6
-#include <sys/resource.h>
7
-#include <strings.h>
8
-#include <unistd.h>
9
-
10
-#include "global_statistics.h"
1
#include "common.h"
12
-#include "appconfig.h"
13
-#include "log.h"
14
-#include "rrd.h"
15
-#include "plugin_idlejitter.h"
2
3
#define CPU_IDLEJITTER_SLEEP_TIME_MS 20
4
src/plugin_nfacct.c
-20
@@ -1,28 +1,8 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
1
#ifdef INTERNAL_PLUGIN_NFACCT
5
-#include <stdio.h>
6
-#include <stdlib.h>
7
-#include <string.h>
8
-#include <sys/types.h>
9
-#include <dirent.h>
10
-#include <sys/stat.h>
11
-#include <fcntl.h>
12
-#include <unistd.h>
13
-#include <time.h>
14
-#include <errno.h>
15
-
2
#include <libmnl/libmnl.h>
3
#include <libnetfilter_acct/libnetfilter_acct.h>
4
19
-#include "main.h"
20
-#include "global_statistics.h"
5
#include "common.h"
22
-#include "appconfig.h"
23
-#include "log.h"
24
-#include "rrd.h"
25
-#include "plugin_proc.h"
6
7
struct mynfacct {
8
const char *name;
src/plugin_proc.c
-16
@@ -1,20 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <pthread.h>
5
-#include <sys/time.h>
6
-#include <sys/resource.h>
7
-#include <strings.h>
8
-#include <unistd.h>
9
-
10
-#include "global_statistics.h"
1
#include "common.h"
12
-#include "appconfig.h"
13
-#include "log.h"
14
-#include "rrd.h"
15
-#include "plugin_proc.h"
16
-#include "main.h"
17
-#include "registry.h"
2
3
void *proc_main(void *ptr)
4
{
src/plugin_tc.c
-16
@@ -1,20 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <sys/types.h>
8
-#include <sys/resource.h>
9
-
10
-#include "avl.h"
11
-#include "log.h"
1
#include "common.h"
13
-#include "appconfig.h"
14
-#include "rrd.h"
15
-#include "popen.h"
16
-#include "plugin_tc.h"
17
-#include "main.h"
2
3
#define RRD_TYPE_TC "tc"
4
#define RRD_TYPE_TC_LEN strlen(RRD_TYPE_TC)
src/plugins_d.c
-18
@@ -1,22 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <sys/types.h>
5
-#include <dirent.h>
6
-#include <pthread.h>
7
-#include <string.h>
8
-#include <stdio.h>
9
-#include <stdlib.h>
10
-#include <signal.h>
11
-
12
-#include "main.h"
1
#include "common.h"
14
-#include "appconfig.h"
15
-#include "log.h"
16
-#include "rrd.h"
17
-#include "popen.h"
18
-#include "plugins_d.h"
19
-#include "../config.h"
2
3
struct plugind *pluginsd_root = NULL;
4
src/plugins_d.h
-4
@@ -1,7 +1,3 @@
1
-#include <sys/types.h>
2
-#include <unistd.h>
3
-
4
-
1
#ifndef NETDATA_PLUGINS_D_H
2
#define NETDATA_PLUGINS_D_H 1
3
src/popen.c
-11
@@ -1,14 +1,3 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <signal.h>
5
-#include <unistd.h>
6
-#include <stdlib.h>
7
-#include <sys/types.h>
8
-#include <sys/wait.h>
9
-
10
-#include "log.h"
11
-#include "popen.h"
1
#include "common.h"
2
3
/*
src/popen.h
-4
@@ -1,7 +1,3 @@
1
-#include <stdio.h>
2
-#include <unistd.h>
3
-#include <sys/types.h>
4
-
1
#ifndef NETDATA_POPEN_H
2
#define NETDATA_POPEN_H 1
3
src/proc_diskstats.c
-21
@@ -1,25 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <dirent.h>
5
-#include <fcntl.h>
6
-#include <stdio.h>
7
-#include <stdlib.h>
8
-#include <string.h>
9
-#include <sys/stat.h>
10
-#include <sys/statvfs.h>
11
-#include <sys/types.h>
12
-#include <unistd.h>
13
-
14
-
1
#include "common.h"
16
-#include "log.h"
17
-#include "appconfig.h"
18
-#include "procfile.h"
19
-#include "rrd.h"
20
-#include "plugin_proc.h"
21
-
22
-#include "proc_self_mountinfo.h"
2
3
#define RRD_TYPE_DISK "disk"
4
src/proc_interrupts.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <ctype.h>
8
-
1
#include "common.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
14
-#include "log.h"
2
3
#define MAX_INTERRUPT_NAME 50
4
src/proc_loadavg.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
8
-#include "log.h"
1
#include "common.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
int do_proc_loadavg(int update_every, unsigned long long dt) {
4
static procfile *ff = NULL;
src/proc_meminfo.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
#define MAX_PROC_MEMINFO_LINE 4096
4
#define MAX_PROC_MEMINFO_NAME 1024
src/proc_net_dev.c
-11
@@ -1,15 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "appconfig.h"
10
-#include "procfile.h"
11
-#include "rrd.h"
12
-#include "plugin_proc.h"
2
3
int do_proc_net_dev(int update_every, unsigned long long dt) {
4
static procfile *ff = NULL;
src/proc_net_ip_vs_stats.c
-10
@@ -1,14 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-
1
#include "common.h"
8
-#include "appconfig.h"
9
-#include "procfile.h"
10
-#include "rrd.h"
11
-#include "plugin_proc.h"
2
3
#define RRD_TYPE_NET_IPVS "ipvs"
4
#define RRD_TYPE_NET_IPVS_LEN strlen(RRD_TYPE_NET_IPVS)
src/proc_net_netstat.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
int do_proc_net_netstat(int update_every, unsigned long long dt) {
4
static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1;
src/proc_net_rpc_nfsd.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
struct nfsd_procs {
4
char name[30];
src/proc_net_snmp.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
#define RRD_TYPE_NET_SNMP "ipv4"
4
#define RRD_TYPE_NET_SNMP_LEN strlen(RRD_TYPE_NET_SNMP)
src/proc_net_snmp6.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <unistd.h>
8
-
1
#include "common.h"
10
-#include "log.h"
11
-#include "appconfig.h"
12
-#include "procfile.h"
13
-#include "rrd.h"
14
-#include "plugin_proc.h"
2
3
#define RRD_TYPE_NET_SNMP6 "ipv6"
4
#define RRD_TYPE_NET_SNMP6_LEN strlen(RRD_TYPE_NET_SNMP6)
src/proc_net_stat_conntrack.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
#define RRD_TYPE_NET_STAT_NETFILTER "netfilter"
4
#define RRD_TYPE_NET_STAT_CONNTRACK "conntrack"
src/proc_net_stat_synproxy.c
-11
@@ -1,15 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-
1
#include "common.h"
8
-#include "appconfig.h"
9
-#include "procfile.h"
10
-#include "rrd.h"
11
-#include "plugin_proc.h"
12
-#include "log.h"
2
3
#define RRD_TYPE_NET_STAT_NETFILTER "netfilter"
4
#define RRD_TYPE_NET_STAT_SYNPROXY "synproxy"
src/proc_self_mountinfo.c
-15
@@ -1,19 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <sys/types.h>
8
-#include <sys/stat.h>
9
-#include <fcntl.h>
10
-#include <ctype.h>
11
-
1
#include "common.h"
13
-#include "log.h"
14
-#include "appconfig.h"
15
-
16
-#include "proc_self_mountinfo.h"
2
3
// find the mount info with the given major:minor
4
// in the supplied linked list of mountinfo structures
src/proc_self_mountinfo.h
-2
@@ -1,5 +1,3 @@
1
-#include "procfile.h"
2
-
1
#ifndef NETDATA_PROC_SELF_MOUNTINFO_H
2
#define NETDATA_PROC_SELF_MOUNTINFO_H 1
3
src/proc_softirqs.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <ctype.h>
8
-
1
#include "common.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
14
-#include "log.h"
2
3
#define MAX_INTERRUPT_NAME 50
4
src/proc_stat.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
3
int do_proc_stat(int update_every, unsigned long long dt) {
4
(void)dt;
src/proc_sys_kernel_random_entropy_avail.c
-10
@@ -1,14 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-
1
#include "common.h"
8
-#include "appconfig.h"
9
-#include "procfile.h"
10
-#include "rrd.h"
11
-#include "plugin_proc.h"
2
3
int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long dt) {
4
static procfile *ff = NULL;
src/proc_vmstat.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <unistd.h>
8
-
1
#include "common.h"
10
-#include "log.h"
11
-#include "appconfig.h"
12
-#include "procfile.h"
13
-#include "rrd.h"
14
-#include "plugin_proc.h"
2
3
int do_proc_vmstat(int update_every, unsigned long long dt) {
4
static procfile *ff = NULL;
src/procfile.c
-22
@@ -1,26 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <unistd.h>
7
-#include <errno.h>
8
-#include <fcntl.h>
9
-#include <string.h>
10
-#include <malloc.h>
11
-#include <ctype.h>
12
-#include <time.h>
13
-#include <sys/time.h>
14
-#include <sys/wait.h>
15
-
16
-#include <sys/types.h>
17
-#include <sys/stat.h>
18
-#include <sys/mman.h>
19
-
1
#include "common.h"
21
-#include "log.h"
22
-#include "procfile.h"
23
-#include "../config.h"
2
3
#define PF_PREFIX "PROCFILE"
4
src/registry.c
-24
@@ -1,28 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-
5
-#include <uuid/uuid.h>
6
-#include <inttypes.h>
7
-#include <stdlib.h>
8
-#include <string.h>
9
-#include <ctype.h>
10
-#include <unistd.h>
11
-#include <sys/stat.h>
12
-#include <sys/types.h>
13
-#include <errno.h>
14
-#include <fcntl.h>
15
-
16
-#include "log.h"
1
#include "common.h"
18
-#include "dictionary.h"
19
-#include "appconfig.h"
20
-
21
-#include "web_client.h"
22
-#include "rrd.h"
23
-#include "rrd2json.h"
24
-#include "registry.h"
25
-
2
3
// ----------------------------------------------------------------------------
4
// TODO
src/registry.h
-2
@@ -1,5 +1,3 @@
1
-#include "web_client.h"
2
-
1
#ifndef NETDATA_REGISTRY_H
2
#define NETDATA_REGISTRY_H 1
3
src/rrd.c
+14
-22
@@ -1,25 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stddef.h>
5
-#include <string.h>
6
-#include <unistd.h>
7
-#include <time.h>
8
-#include <sys/time.h>
9
-#include <sys/mman.h>
10
-#include <pthread.h>
11
-#include <errno.h>
12
-#include <ctype.h>
13
-#include <sys/stat.h>
14
-#include <sys/types.h>
15
-#include <stdlib.h>
16
-
1
#include "common.h"
18
-#include "log.h"
19
-#include "appconfig.h"
20
-
21
-#include "main.h"
22
-#include "rrd.h"
2
3
#define RRD_DEFAULT_GAP_INTERPOLATIONS 1
4
@@ -54,6 +33,10 @@ RRDHOST localhost = {
33
.rrdcontext_root_index = {
34
{ NULL, rrdcontext_compare },
35
AVL_LOCK_INITIALIZER
36
+ },
37
+ .variables_root_index = {
38
+ { NULL, rrdvar_compare },
39
+ AVL_LOCK_INITIALIZER
40
}
41
};
42
@@ -82,10 +65,15 @@ RRDCONTEXT *rrdcontext_create(const char *id) {
65
if(!rc) {
66
rc = calloc(1, sizeof(RRDCONTEXT));
67
if(!rc) fatal("Cannot allocate RRDCONTEXT memory");
68
+
69
rc->id = strdup(id);
70
if(!rc->id) fatal("Cannot allocate RRDCONTEXT.id memory");
71
+
72
rc->hash = simple_hash(rc->id);
88
- // avl_init_lock(&rc->variables_root_index, compar);
73
+
74
+ // initialize the variables index
75
+ avl_init_lock(&rc->variables_root_index, rrdvar_compare);
76
+
77
RRDCONTEXT *ret = rrdcontext_index_add(&localhost, rc);
78
if(ret != rc)
79
fatal("INTERNAL ERROR: Expected to INSERT RRDCONTEXT '%s' into index, but inserted '%s'.", rc->id, (ret)?ret->id:"NONE");
@@ -102,6 +90,9 @@ void rrdcontext_free(RRDCONTEXT *rc) {
90
if(ret != rc)
91
fatal("INTERNAL ERROR: Expected to DELETE RRDCONTEXT '%s' from index, but deleted '%s'.", rc->id, (ret)?ret->id:"NONE");
92
93
+ if(rc->variables_root_index.avl_tree.root != NULL)
94
+ fatal("INTERNAL ERROR: Variables index of RRDCONTEXT '%s' that is freed, is not empty.", rc->id);
95
+
96
free((void *)rc->id);
97
free(rc);
98
}
@@ -511,6 +502,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
502
config_get_number(st->id, "gap when lost iterations above", RRD_DEFAULT_GAP_INTERPOLATIONS) + 2);
503
504
avl_init_lock(&st->dimensions_index, rrddim_compare);
505
+ avl_init_lock(&st->variables_root_index, rrdvar_compare);
506
507
pthread_rwlock_init(&st->rwlock, NULL);
508
pthread_rwlock_wrlock(&localhost.rrdset_root_rwlock);
src/rrd.h
+7
-9
@@ -1,10 +1,3 @@
1
-#include <sys/time.h>
2
-#include <pthread.h>
3
-#include <stdint.h>
4
-
5
-#include "avl.h"
6
-#include "storage_number.h"
7
-
1
#ifndef NETDATA_RRD_H
2
#define NETDATA_RRD_H 1
3
@@ -93,7 +86,7 @@ struct rrdcontext {
86
87
size_t use_count;
88
96
- // avl_tree_lock variables_root_index;
89
+ avl_tree_lock variables_root_index;
90
};
91
typedef struct rrdcontext RRDCONTEXT;
92
@@ -267,6 +260,11 @@ struct rrdset {
260
261
avl_tree_lock dimensions_index; // the root of the dimensions index
262
RRDDIM *dimensions; // the actual data for every dimension
263
+
264
+ // ------------------------------------------------------------------------
265
+ // local variables
266
+
267
+ avl_tree_lock variables_root_index;
268
};
269
typedef struct rrdset RRDSET;
270
@@ -285,7 +283,7 @@ struct rrdhost {
283
avl_tree_lock rrdset_root_index_name;
284
285
avl_tree_lock rrdcontext_root_index;
288
- // avl_tree_lock variables_root_index;
286
+ avl_tree_lock variables_root_index;
287
};
288
typedef struct rrdhost RRDHOST;
289
src/rrd2json.c
-11
@@ -1,15 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <pthread.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <stdint.h>
8
-#include <math.h>
9
-
10
-#include "log.h"
1
#include "common.h"
12
-#include "rrd2json.h"
2
3
#define HOSTNAME_MAX 1024
4
char *hostname = "unknown";
src/rrd2json.h
-5
@@ -1,8 +1,3 @@
1
-#include <time.h>
2
-
3
-#include "web_buffer.h"
4
-#include "rrd.h"
5
-
1
#ifndef NETDATA_RRD2JSON_H
2
#define NETDATA_RRD2JSON_H 1
3
src/storage_number.c
-17
@@ -1,21 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#ifdef STORAGE_WITH_MATH
5
-#include <math.h>
6
-#endif
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "storage_number.h"
11
-
12
-#if __GNUC__
13
-#if __x86_64__ || __ppc64__
14
-#define ENVIRONMENT64
15
-#else
16
-#define ENVIRONMENT32
17
-#endif
18
-#endif
2
3
extern char *print_number_lu_r(char *str, unsigned long uvalue);
4
extern char *print_number_llu_r(char *str, unsigned long long uvalue);
src/storage_number.h
-2
@@ -1,5 +1,3 @@
1
-#include <stdint.h>
2
-
1
#ifndef NETDATA_STORAGE_NUMBER_H
2
#define NETDATA_STORAGE_NUMBER_H
3
src/sys_fs_cgroup.c
-19
@@ -1,23 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-
5
-#include <stdio.h>
6
-#include <stdlib.h>
7
-#include <inttypes.h>
8
-#include <sys/types.h>
9
-#include <dirent.h>
10
-#include <string.h>
11
-#include <sys/stat.h>
12
-
1
#include "common.h"
14
-#include "appconfig.h"
15
-#include "procfile.h"
16
-#include "log.h"
17
-#include "rrd.h"
18
-#include "main.h"
19
-#include "popen.h"
20
-#include "proc_self_mountinfo.h"
2
3
// ----------------------------------------------------------------------------
4
// cgroup globals
src/sys_kernel_mm_ksm.c
+3
-15
@@ -1,21 +1,9 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "appconfig.h"
11
-#include "procfile.h"
12
-#include "rrd.h"
13
-#include "plugin_proc.h"
2
15
-typedef struct name_value {
3
+typedef struct ksm_name_value {
4
char filename[FILENAME_MAX + 1];
5
unsigned long long value;
18
-} NAME_VALUE;
6
+} KSM_NAME_VALUE;
7
8
#define PAGES_SHARED 0
9
#define PAGES_SHARING 1
@@ -23,7 +11,7 @@ typedef struct name_value {
11
#define PAGES_VOLATILE 3
12
#define PAGES_TO_SCAN 4
13
26
-NAME_VALUE values[] = {
14
+KSM_NAME_VALUE values[] = {
15
[PAGES_SHARED] = { "/sys/kernel/mm/ksm/pages_shared", 0ULL },
16
[PAGES_SHARING] = { "/sys/kernel/mm/ksm/pages_sharing", 0ULL },
17
[PAGES_UNSHARED] = { "/sys/kernel/mm/ksm/pages_unshared", 0ULL },
src/unit_test.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <sys/resource.h>
8
-#include <math.h>
9
-
1
#include "common.h"
11
-#include "storage_number.h"
12
-#include "rrd.h"
13
-#include "log.h"
14
-#include "web_buffer.h"
2
3
int check_storage_number(calculated_number n, int debug) {
4
char buffer[100];
src/url.c
-9
@@ -1,13 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdlib.h>
5
-#include <string.h>
6
-#include <ctype.h>
7
-
1
#include "common.h"
9
-#include "log.h"
10
-#include "url.h"
2
3
// ----------------------------------------------------------------------------
4
// URL encode / decode
src/web_buffer.c
-12
@@ -1,16 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <stdlib.h>
5
-#include <string.h>
6
-
7
-#ifdef STORAGE_WITH_MATH
8
-#include <math.h>
9
-#endif
10
-
1
#include "common.h"
12
-#include "web_buffer.h"
13
-#include "log.h"
2
3
#define BUFFER_OVERFLOW_EOF "EOF"
4
src/web_buffer.h
-4
@@ -1,7 +1,3 @@
1
-#include <stdarg.h>
2
-#include <time.h>
3
-#include "storage_number.h"
4
-
1
#ifndef NETDATA_WEB_BUFFER_H
2
#define NETDATA_WEB_BUFFER_H 1
3
src/web_buffer_svg.c
-13
@@ -1,17 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <math.h>
5
-#include <string.h>
6
-#include <ctype.h>
7
-#include <stdlib.h>
8
-
1
#include "common.h"
10
-#include "log.h"
11
-#include "appconfig.h"
12
-#include "url.h"
13
-#include "web_buffer.h"
14
-#include "web_buffer_svg.h"
2
3
#define BADGE_HORIZONTAL_PADDING 4
4
#define VERDANA_KERNING 0.5
src/web_buffer_svg.h
-3
@@ -1,6 +1,3 @@
1
-#include "web_buffer.h"
2
-#include "dictionary.h"
3
-
1
#ifndef NETDATA_WEB_BUFFER_SVG_H
2
#define NETDATA_WEB_BUFFER_SVG_H 1
3
src/web_client.c
-34
@@ -1,38 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <unistd.h>
5
-#include <stdlib.h>
6
-#include <sys/types.h>
7
-#include <sys/socket.h>
8
-#include <netinet/in.h>
9
-#include <arpa/inet.h>
10
-#include <errno.h>
11
-#include <pthread.h>
12
-#include <sys/stat.h>
13
-#include <fcntl.h>
14
-#include <malloc.h>
15
-#include <pwd.h>
16
-#include <grp.h>
17
-#include <ctype.h>
18
-#include <poll.h>
19
-
20
-// TCP_CORK
21
-#include <netinet/tcp.h>
22
-
1
#include "common.h"
24
-#include "log.h"
25
-#include "main.h"
26
-#include "appconfig.h"
27
-#include "url.h"
28
-#include "web_buffer.h"
29
-#include "web_server.h"
30
-#include "global_statistics.h"
31
-#include "rrd.h"
32
-#include "rrd2json.h"
33
-#include "registry.h"
34
-#include "web_buffer_svg.h"
35
-#include "web_client.h"
2
3
#define INITIAL_WEB_DATA_LENGTH 16384
4
#define WEB_REQUEST_LENGTH 16384
src/web_client.h
-16
@@ -1,19 +1,3 @@
1
-
2
-#ifdef NETDATA_WITH_ZLIB
3
-#include <zlib.h>
4
-#endif
5
-
6
-#include <sys/time.h>
7
-#include <string.h>
8
-#include <sys/types.h>
9
-#include <sys/socket.h>
10
-#include <netinet/in.h>
11
-#include <arpa/inet.h>
12
-#include <netdb.h>
13
-
14
-#include "web_buffer.h"
15
-#include "dictionary.h"
16
-
1
#ifndef NETDATA_WEB_CLIENT_H
2
#define NETDATA_WEB_CLIENT_H 1
3
src/web_server.c
-28
@@ -1,32 +1,4 @@
1
-#ifdef HAVE_CONFIG_H
2
-#include <config.h>
3
-#endif
4
-#include <unistd.h>
5
-#include <stdlib.h>
6
-#include <sys/types.h>
7
-#include <sys/socket.h>
8
-#include <netinet/in.h>
9
-#include <arpa/inet.h>
10
-#include <errno.h>
11
-#include <pthread.h>
12
-#include <sys/stat.h>
13
-#include <fcntl.h>
14
-#include <netinet/tcp.h>
15
-#include <malloc.h>
16
-#include <poll.h>
17
-#include <ctype.h>
18
-
1
#include "common.h"
20
-#include "log.h"
21
-#include "appconfig.h"
22
-#include "url.h"
23
-#include "web_buffer.h"
24
-#include "web_client.h"
25
-#include "web_server.h"
26
-#include "global_statistics.h"
27
-#include "rrd.h"
28
-#include "rrd2json.h"
29
-#include "../config.h"
2
3
int listen_backlog = LISTEN_BACKLOG;
4
int listen_fds_count = 0;