From f399edf7dffc296873c14fa0fca3f593674b291a Mon Sep 17 00:00:00 2001 From: Costa Tsaousis Date: Sat, 6 Aug 2016 03:52:03 +0300 Subject: [PATCH] all required system headers in common.h; some progress on health variables --- CMakeLists.txt | 2 +- src/Makefile.am | 1 + src/appconfig.c | 18 ---- src/appconfig.h | 2 - src/apps_plugin.c | 40 -------- src/avl.c | 8 +- src/common.c | 17 ---- src/common.h | 106 +++++++++++++++++++-- src/daemon.c | 25 ----- src/dictionary.c | 12 --- src/dictionary.h | 5 - src/global_statistics.c | 7 +- src/health.c | 53 +++++++++++ src/health.h | 58 +++++++++++ src/log.c | 12 --- src/log.h | 7 +- src/main.c | 36 ------- src/main.h | 4 - src/plugin_checks.c | 13 --- src/plugin_idlejitter.c | 14 --- src/plugin_nfacct.c | 20 ---- src/plugin_proc.c | 16 ---- src/plugin_tc.c | 16 ---- src/plugins_d.c | 18 ---- src/plugins_d.h | 4 - src/popen.c | 11 --- src/popen.h | 4 - src/proc_diskstats.c | 21 ---- src/proc_interrupts.c | 13 --- src/proc_loadavg.c | 12 --- src/proc_meminfo.c | 12 --- src/proc_net_dev.c | 11 --- src/proc_net_ip_vs_stats.c | 10 -- src/proc_net_netstat.c | 12 --- src/proc_net_rpc_nfsd.c | 12 --- src/proc_net_snmp.c | 12 --- src/proc_net_snmp6.c | 13 --- src/proc_net_stat_conntrack.c | 12 --- src/proc_net_stat_synproxy.c | 11 --- src/proc_self_mountinfo.c | 15 --- src/proc_self_mountinfo.h | 2 - src/proc_softirqs.c | 13 --- src/proc_stat.c | 12 --- src/proc_sys_kernel_random_entropy_avail.c | 10 -- src/proc_vmstat.c | 13 --- src/procfile.c | 22 ----- src/registry.c | 24 ----- src/registry.h | 2 - src/rrd.c | 36 +++---- src/rrd.h | 16 ++-- src/rrd2json.c | 11 --- src/rrd2json.h | 5 - src/storage_number.c | 17 ---- src/storage_number.h | 2 - src/sys_fs_cgroup.c | 19 ---- src/sys_kernel_mm_ksm.c | 18 +--- src/unit_test.c | 13 --- src/url.c | 9 -- src/web_buffer.c | 12 --- src/web_buffer.h | 4 - src/web_buffer_svg.c | 13 --- src/web_buffer_svg.h | 3 - src/web_client.c | 34 ------- src/web_client.h | 16 ---- src/web_server.c | 28 ------ 65 files changed, 240 insertions(+), 809 deletions(-) create mode 100644 src/health.c create mode 100644 src/health.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ea5fbf..e4bc52d4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ set(NETDATA_SOURCE_FILES src/web_client.h src/web_server.c src/web_server.h - config.h) + config.h src/health.h src/health.c) set(APPS_PLUGIN_SOURCE_FILES src/appconfig.c diff --git a/src/Makefile.am b/src/Makefile.am index 664be8b0..2b698f8a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,6 +33,7 @@ netdata_SOURCES = \ daemon.c daemon.h \ dictionary.c dictionary.h \ global_statistics.c global_statistics.h \ + health.c health.h \ log.c log.h \ main.c main.h \ plugin_checks.c plugin_checks.h \ diff --git a/src/appconfig.c b/src/appconfig.c index 748c6eff..dd90aa87 100644 --- a/src/appconfig.c +++ b/src/appconfig.c @@ -1,22 +1,4 @@ - -/* - * TODO - * - * 1. Re-write this using DICTIONARY - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - -#include "avl.h" #include "common.h" -#include "appconfig.h" -#include "log.h" #define CONFIG_FILE_LINE_MAX ((CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 1024) * 2) diff --git a/src/appconfig.h b/src/appconfig.h index b5245e55..08aae834 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -1,5 +1,3 @@ -#include "web_buffer.h" - #ifndef NETDATA_CONFIG_H #define NETDATA_CONFIG_H 1 diff --git a/src/apps_plugin.c b/src/apps_plugin.c index 6b43216c..188d5a95 100644 --- a/src/apps_plugin.c +++ b/src/apps_plugin.c @@ -1,44 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include "avl.h" - #include "common.h" -#include "log.h" -#include "procfile.h" -#include "../config.h" -#include "web_buffer.h" - -#ifdef NETDATA_INTERNAL_CHECKS -#include -#endif #define MAX_COMPARE_NAME 100 #define MAX_NAME 100 diff --git a/src/avl.c b/src/avl.c index cf9705e2..71d206f2 100644 --- a/src/avl.c +++ b/src/avl.c @@ -1,10 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -// #include - -#include "avl.h" -#include "log.h" +#include "common.h" /* ------------------------------------------------------------------------- */ /* diff --git a/src/common.c b/src/common.c index 2566aa58..07aa2098 100644 --- a/src/common.c +++ b/src/common.c @@ -1,21 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "log.h" #include "common.h" -#include "appconfig.h" -#include "../config.h" char *global_host_prefix = ""; int enable_ksm = 1; diff --git a/src/common.h b/src/common.h index f6736df6..bf6773b4 100644 --- a/src/common.h +++ b/src/common.h @@ -1,20 +1,114 @@ +#ifndef NETDATA_COMMON_H +#define NETDATA_COMMON_H 1 + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include #include -#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#ifndef NETDATA_COMMON_H -#define NETDATA_COMMON_H 1 +#ifdef STORAGE_WITH_MATH +#include +#endif #if defined(HAVE_INTTYPES_H) #include #elif defined(HAVE_STDINT_H) #include #endif -#include -#include +#ifdef NETDATA_INTERNAL_CHECKS +#include +#endif + +#ifdef NETDATA_WITH_ZLIB +#include +#endif + +#include "avl.h" +#include "log.h" +#include "global_statistics.h" +#include "storage_number.h" +#include "web_buffer.h" +#include "web_buffer_svg.h" +#include "url.h" +#include "popen.h" + +#include "procfile.h" +#include "appconfig.h" +#include "dictionary.h" +#include "proc_self_mountinfo.h" +#include "plugin_checks.h" +#include "plugin_idlejitter.h" +#include "plugin_nfacct.h" +#include "plugin_proc.h" +#include "plugin_tc.h" +#include "plugins_d.h" + +#include "health.h" + +#include "rrd.h" +#include "rrd2json.h" + +#include "web_client.h" +#include "web_server.h" + +#include "registry.h" +#include "daemon.h" +#include "main.h" +#include "unit_test.h" + +#if __GNUC__ +#if __x86_64__ || __ppc64__ +#define ENVIRONMENT64 +#else +#define ENVIRONMENT32 +#endif +#endif + +#ifdef abs +#undef abs +#endif #define abs(x) ((x < 0)? -x : x) + #define usecdiff(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec))) extern void netdata_fix_chart_id(char *s); diff --git a/src/daemon.c b/src/daemon.c index b14b4d9a..eb4b8d45 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1,29 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "web_client.h" -#include "plugins_d.h" -#include "rrd.h" -#include "popen.h" -#include "main.h" -#include "daemon.h" char pidfile[FILENAME_MAX + 1] = ""; diff --git a/src/dictionary.c b/src/dictionary.c index 8bc04827..a360803b 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "avl.h" #include "common.h" -#include "log.h" - -#include "dictionary.h" // ---------------------------------------------------------------------------- // dictionary statistics diff --git a/src/dictionary.h b/src/dictionary.h index c32d8bd9..7613e285 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -1,8 +1,3 @@ -#include - -#include "web_buffer.h" -#include "avl.h" - #ifndef NETDATA_DICTIONARY_H #define NETDATA_DICTIONARY_H 1 diff --git a/src/global_statistics.c b/src/global_statistics.c index 40d3c3e3..e2852962 100644 --- a/src/global_statistics.c +++ b/src/global_statistics.c @@ -1,9 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include - -#include "global_statistics.h" +#include "common.h" struct global_statistics global_statistics = { 0, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL}; diff --git a/src/health.c b/src/health.c new file mode 100644 index 00000000..47659ccd --- /dev/null +++ b/src/health.c @@ -0,0 +1,53 @@ +#include "common.h" + +int rrdvar_compare(void* a, void* b) { + if(((RRDVAR *)a)->hash < ((RRDVAR *)b)->hash) return -1; + else if(((RRDVAR *)a)->hash > ((RRDVAR *)b)->hash) return 1; + else return strcmp(((RRDVAR *)a)->name, ((RRDVAR *)b)->name); +} + +#define rrdvar_index_add(tree, rv) (RRDVAR *)avl_insert_lock(tree, (avl *)(rv)) +#define rrdvar_index_del(tree, rv) (RRDVAR *)avl_remove_lock(tree, (avl *)(rv)) + +static RRDVAR *rrdvar_index_find(avl_tree_lock *tree, const char *name, uint32_t hash) { + RRDVAR tmp; + tmp.name = (char *)name; + tmp.hash = (hash)?hash:simple_hash(tmp.name); + + return (RRDVAR *)avl_search_lock(tree, (avl *)&tmp); +} + + +RRDVAR *rrdvar_get(RRDHOST *host, RRDCONTEXT *co, RRDSET *st, const char *name) { + uint32_t hash = simple_hash(name); + + RRDVAR *ret = NULL; + RRDVAR *rv = rrdvar_index_find(&st->variables_root_index, name, hash); + if(!rv) { + rv = calloc(1, sizeof(RRDVAR)); + if(!rv) fatal("Cannot allocate memory for RRDVAR"); + + rv->name = strdup(name); + if(!rv->name) fatal("Cannot allocate memory for RRDVAR name"); + + rv->hash = hash; + + ret = rrdvar_index_add(&st->variables_root_index, rv); + if(ret != rv) { + error("Duplicate RRDVAR '%s' found on chart '%s'", name, st->id); + free(rv->name); + free(rv); + rv = ret; + } + + ret = rrdvar_index_add(&co->variables_root_index, rv); + if(ret != rv) + debug(D_VARIABLES, "Variable '%s' in context '%s' does not come from chart '%s'", name, co->id, st->id); + + ret = rrdvar_index_add(&host->variables_root_index, rv); + if(ret != rv) + debug(D_VARIABLES, "Variable '%s' in host '%s' does not come from chart '%s'", name, host->hostname, st->id); + } + + return rv; +} diff --git a/src/health.h b/src/health.h new file mode 100644 index 00000000..d4b55a5d --- /dev/null +++ b/src/health.h @@ -0,0 +1,58 @@ +#ifndef NETDATA_HEALTH_H +#define NETDATA_HEALTH_H + +extern int rrdvar_compare(void *a, void *b); + +/* + * RRDVAR + * a variable + * + * There are 4 scopes: local (chart), context, host and global variables + * + * Standard global variables: + * $now + * + * Standard host variables: + * - none - + * + * Standard context variables: + * - none - + * + * Standard local variables: + * $last_updated + * $last_collected_value + * $last_value + * + */ + +typedef struct rrdvar { + avl avl; + + char *name; + uint32_t hash; + + calculated_number *value; + + time_t last_updated; +} RRDVAR; + +typedef struct rrdcalc { + avl avl; + + int group; // grouping method: average, max, etc. + int before; // ending point in time-series + int after; // starting point in time-series + int update_every; // update frequency for the calculation + + const char *name; + calculated_number value; + + RRDVAR *local; + RRDVAR *context; + RRDVAR *host; + + struct rrdcalc *next; + struct rrdcalc *prev; +} RRDCALC; + +#endif //NETDATA_HEALTH_H diff --git a/src/log.c b/src/log.c index 62f07add..3c42afae 100644 --- a/src/log.c +++ b/src/log.c @@ -1,17 +1,5 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include - -#include "log.h" #include "common.h" - // ---------------------------------------------------------------------------- // LOG diff --git a/src/log.h b/src/log.h index 2c0f5cd7..95b6b301 100644 --- a/src/log.h +++ b/src/log.h @@ -1,9 +1,3 @@ -#include -#include -#include - -#include "main.h" - #ifndef NETDATA_LOG_H #define NETDATA_LOG_H 1 @@ -29,6 +23,7 @@ #define D_MEMORY 0x00080000 #define D_CGROUP 0x00100000 #define D_REGISTRY 0x00200000 +#define D_VARIABLES 0x00400000 //#define DEBUG (D_WEB_CLIENT_ACCESS|D_LISTENER|D_RRD_STATS) //#define DEBUG 0xffffffff diff --git a/src/main.c b/src/main.c index 41590c56..04758092 100644 --- a/src/main.c +++ b/src/main.c @@ -1,40 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "appconfig.h" #include "common.h" -#include "daemon.h" -#include "log.h" -#include "popen.h" -#include "rrd.h" -#include "rrd2json.h" -#include "web_client.h" -#include "web_server.h" - -#include "unit_test.h" - -#include "plugin_checks.h" -#include "plugin_idlejitter.h" -#include "plugin_nfacct.h" -#include "registry.h" -#include "plugin_proc.h" -#include "plugin_tc.h" -#include "plugins_d.h" - -#include "main.h" extern void *cgroups_main(void *ptr); diff --git a/src/main.h b/src/main.h index a41aa0c2..b1acf8a6 100644 --- a/src/main.h +++ b/src/main.h @@ -1,10 +1,6 @@ -#include - #ifndef NETDATA_MAIN_H #define NETDATA_MAIN_H 1 -#include - extern volatile sig_atomic_t netdata_exit; /** diff --git a/src/plugin_checks.c b/src/plugin_checks.c index 379fb9a8..217cdc51 100644 --- a/src/plugin_checks.c +++ b/src/plugin_checks.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "rrd.h" -#include "plugin_checks.h" void *checks_main(void *ptr) { diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c index 56c22a16..abdb03d1 100644 --- a/src/plugin_idlejitter.c +++ b/src/plugin_idlejitter.c @@ -1,18 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - -#include "global_statistics.h" #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "rrd.h" -#include "plugin_idlejitter.h" #define CPU_IDLEJITTER_SLEEP_TIME_MS 20 diff --git a/src/plugin_nfacct.c b/src/plugin_nfacct.c index 6cde66e0..b61f9e53 100644 --- a/src/plugin_nfacct.c +++ b/src/plugin_nfacct.c @@ -1,28 +1,8 @@ -#ifdef HAVE_CONFIG_H -#include -#endif #ifdef INTERNAL_PLUGIN_NFACCT -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include -#include "main.h" -#include "global_statistics.h" #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "rrd.h" -#include "plugin_proc.h" struct mynfacct { const char *name; diff --git a/src/plugin_proc.c b/src/plugin_proc.c index e7b8d50c..1f69b284 100644 --- a/src/plugin_proc.c +++ b/src/plugin_proc.c @@ -1,20 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - -#include "global_statistics.h" #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "rrd.h" -#include "plugin_proc.h" -#include "main.h" -#include "registry.h" void *proc_main(void *ptr) { diff --git a/src/plugin_tc.c b/src/plugin_tc.c index 251cfeeb..201cfcad 100644 --- a/src/plugin_tc.c +++ b/src/plugin_tc.c @@ -1,20 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - -#include "avl.h" -#include "log.h" #include "common.h" -#include "appconfig.h" -#include "rrd.h" -#include "popen.h" -#include "plugin_tc.h" -#include "main.h" #define RRD_TYPE_TC "tc" #define RRD_TYPE_TC_LEN strlen(RRD_TYPE_TC) diff --git a/src/plugins_d.c b/src/plugins_d.c index 23757bbe..aa233cfb 100644 --- a/src/plugins_d.c +++ b/src/plugins_d.c @@ -1,22 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -#include "main.h" #include "common.h" -#include "appconfig.h" -#include "log.h" -#include "rrd.h" -#include "popen.h" -#include "plugins_d.h" -#include "../config.h" struct plugind *pluginsd_root = NULL; diff --git a/src/plugins_d.h b/src/plugins_d.h index 1a10dc0d..7e49b184 100644 --- a/src/plugins_d.h +++ b/src/plugins_d.h @@ -1,7 +1,3 @@ -#include -#include - - #ifndef NETDATA_PLUGINS_D_H #define NETDATA_PLUGINS_D_H 1 diff --git a/src/popen.c b/src/popen.c index 4e2874f4..a603c72d 100644 --- a/src/popen.c +++ b/src/popen.c @@ -1,14 +1,3 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - -#include "log.h" -#include "popen.h" #include "common.h" /* diff --git a/src/popen.h b/src/popen.h index 10680f0c..90845e1f 100644 --- a/src/popen.h +++ b/src/popen.h @@ -1,7 +1,3 @@ -#include -#include -#include - #ifndef NETDATA_POPEN_H #define NETDATA_POPEN_H 1 diff --git a/src/proc_diskstats.c b/src/proc_diskstats.c index 3e3df246..87140ada 100644 --- a/src/proc_diskstats.c +++ b/src/proc_diskstats.c @@ -1,25 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" - -#include "proc_self_mountinfo.h" #define RRD_TYPE_DISK "disk" diff --git a/src/proc_interrupts.c b/src/proc_interrupts.c index ad00c202..b4a62f04 100644 --- a/src/proc_interrupts.c +++ b/src/proc_interrupts.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" -#include "log.h" #define MAX_INTERRUPT_NAME 50 diff --git a/src/proc_loadavg.c b/src/proc_loadavg.c index c8e893b9..54c08c2b 100644 --- a/src/proc_loadavg.c +++ b/src/proc_loadavg.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - -#include "log.h" #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_loadavg(int update_every, unsigned long long dt) { static procfile *ff = NULL; diff --git a/src/proc_meminfo.c b/src/proc_meminfo.c index 611b4ed2..fc22ddf0 100644 --- a/src/proc_meminfo.c +++ b/src/proc_meminfo.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" #define MAX_PROC_MEMINFO_LINE 4096 #define MAX_PROC_MEMINFO_NAME 1024 diff --git a/src/proc_net_dev.c b/src/proc_net_dev.c index 12d8078c..2c02b069 100644 --- a/src/proc_net_dev.c +++ b/src/proc_net_dev.c @@ -1,15 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_net_dev(int update_every, unsigned long long dt) { static procfile *ff = NULL; diff --git a/src/proc_net_ip_vs_stats.c b/src/proc_net_ip_vs_stats.c index ffb5da7b..ff038b92 100644 --- a/src/proc_net_ip_vs_stats.c +++ b/src/proc_net_ip_vs_stats.c @@ -1,14 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" #define RRD_TYPE_NET_IPVS "ipvs" #define RRD_TYPE_NET_IPVS_LEN strlen(RRD_TYPE_NET_IPVS) diff --git a/src/proc_net_netstat.c b/src/proc_net_netstat.c index 70d8cd68..1f3bff30 100644 --- a/src/proc_net_netstat.c +++ b/src/proc_net_netstat.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_net_netstat(int update_every, unsigned long long dt) { static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1; diff --git a/src/proc_net_rpc_nfsd.c b/src/proc_net_rpc_nfsd.c index b5d766e0..69a18773 100644 --- a/src/proc_net_rpc_nfsd.c +++ b/src/proc_net_rpc_nfsd.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" struct nfsd_procs { char name[30]; diff --git a/src/proc_net_snmp.c b/src/proc_net_snmp.c index 69b2938a..815eeac7 100644 --- a/src/proc_net_snmp.c +++ b/src/proc_net_snmp.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" #define RRD_TYPE_NET_SNMP "ipv4" #define RRD_TYPE_NET_SNMP_LEN strlen(RRD_TYPE_NET_SNMP) diff --git a/src/proc_net_snmp6.c b/src/proc_net_snmp6.c index 4586ee7d..0d770ddd 100644 --- a/src/proc_net_snmp6.c +++ b/src/proc_net_snmp6.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" #define RRD_TYPE_NET_SNMP6 "ipv6" #define RRD_TYPE_NET_SNMP6_LEN strlen(RRD_TYPE_NET_SNMP6) diff --git a/src/proc_net_stat_conntrack.c b/src/proc_net_stat_conntrack.c index 1fcf6ffc..3af66f19 100644 --- a/src/proc_net_stat_conntrack.c +++ b/src/proc_net_stat_conntrack.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" #define RRD_TYPE_NET_STAT_NETFILTER "netfilter" #define RRD_TYPE_NET_STAT_CONNTRACK "conntrack" diff --git a/src/proc_net_stat_synproxy.c b/src/proc_net_stat_synproxy.c index d90a376f..c3874eee 100644 --- a/src/proc_net_stat_synproxy.c +++ b/src/proc_net_stat_synproxy.c @@ -1,15 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" -#include "log.h" #define RRD_TYPE_NET_STAT_NETFILTER "netfilter" #define RRD_TYPE_NET_STAT_SYNPROXY "synproxy" diff --git a/src/proc_self_mountinfo.c b/src/proc_self_mountinfo.c index ac5baa4e..b4b2f684 100644 --- a/src/proc_self_mountinfo.c +++ b/src/proc_self_mountinfo.c @@ -1,19 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" - -#include "proc_self_mountinfo.h" // find the mount info with the given major:minor // in the supplied linked list of mountinfo structures diff --git a/src/proc_self_mountinfo.h b/src/proc_self_mountinfo.h index 51712a58..af98ca4a 100644 --- a/src/proc_self_mountinfo.h +++ b/src/proc_self_mountinfo.h @@ -1,5 +1,3 @@ -#include "procfile.h" - #ifndef NETDATA_PROC_SELF_MOUNTINFO_H #define NETDATA_PROC_SELF_MOUNTINFO_H 1 diff --git a/src/proc_softirqs.c b/src/proc_softirqs.c index 96b5d3d3..020bc5e3 100644 --- a/src/proc_softirqs.c +++ b/src/proc_softirqs.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" -#include "log.h" #define MAX_INTERRUPT_NAME 50 diff --git a/src/proc_stat.c b/src/proc_stat.c index a1e9c2f5..9450f381 100644 --- a/src/proc_stat.c +++ b/src/proc_stat.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_stat(int update_every, unsigned long long dt) { (void)dt; diff --git a/src/proc_sys_kernel_random_entropy_avail.c b/src/proc_sys_kernel_random_entropy_avail.c index d7d1e826..a08f494c 100644 --- a/src/proc_sys_kernel_random_entropy_avail.c +++ b/src/proc_sys_kernel_random_entropy_avail.c @@ -1,14 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long dt) { static procfile *ff = NULL; diff --git a/src/proc_vmstat.c b/src/proc_vmstat.c index c69b389b..dcddb14d 100644 --- a/src/proc_vmstat.c +++ b/src/proc_vmstat.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" int do_proc_vmstat(int update_every, unsigned long long dt) { static procfile *ff = NULL; diff --git a/src/procfile.c b/src/procfile.c index 25f9d2e7..49f715d4 100644 --- a/src/procfile.c +++ b/src/procfile.c @@ -1,26 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - #include "common.h" -#include "log.h" -#include "procfile.h" -#include "../config.h" #define PF_PREFIX "PROCFILE" diff --git a/src/registry.c b/src/registry.c index 26004d4d..0c184a73 100644 --- a/src/registry.c +++ b/src/registry.c @@ -1,28 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "log.h" #include "common.h" -#include "dictionary.h" -#include "appconfig.h" - -#include "web_client.h" -#include "rrd.h" -#include "rrd2json.h" -#include "registry.h" - // ---------------------------------------------------------------------------- // TODO diff --git a/src/registry.h b/src/registry.h index 9e7a13ec..c2b57a23 100644 --- a/src/registry.h +++ b/src/registry.h @@ -1,5 +1,3 @@ -#include "web_client.h" - #ifndef NETDATA_REGISTRY_H #define NETDATA_REGISTRY_H 1 diff --git a/src/rrd.c b/src/rrd.c index c7e4917b..5ba5d39a 100644 --- a/src/rrd.c +++ b/src/rrd.c @@ -1,25 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" - -#include "main.h" -#include "rrd.h" #define RRD_DEFAULT_GAP_INTERPOLATIONS 1 @@ -54,6 +33,10 @@ RRDHOST localhost = { .rrdcontext_root_index = { { NULL, rrdcontext_compare }, AVL_LOCK_INITIALIZER + }, + .variables_root_index = { + { NULL, rrdvar_compare }, + AVL_LOCK_INITIALIZER } }; @@ -82,10 +65,15 @@ RRDCONTEXT *rrdcontext_create(const char *id) { if(!rc) { rc = calloc(1, sizeof(RRDCONTEXT)); if(!rc) fatal("Cannot allocate RRDCONTEXT memory"); + rc->id = strdup(id); if(!rc->id) fatal("Cannot allocate RRDCONTEXT.id memory"); + rc->hash = simple_hash(rc->id); - // avl_init_lock(&rc->variables_root_index, compar); + + // initialize the variables index + avl_init_lock(&rc->variables_root_index, rrdvar_compare); + RRDCONTEXT *ret = rrdcontext_index_add(&localhost, rc); if(ret != rc) 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) { if(ret != rc) fatal("INTERNAL ERROR: Expected to DELETE RRDCONTEXT '%s' from index, but deleted '%s'.", rc->id, (ret)?ret->id:"NONE"); + if(rc->variables_root_index.avl_tree.root != NULL) + fatal("INTERNAL ERROR: Variables index of RRDCONTEXT '%s' that is freed, is not empty.", rc->id); + free((void *)rc->id); free(rc); } @@ -511,6 +502,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const config_get_number(st->id, "gap when lost iterations above", RRD_DEFAULT_GAP_INTERPOLATIONS) + 2); avl_init_lock(&st->dimensions_index, rrddim_compare); + avl_init_lock(&st->variables_root_index, rrdvar_compare); pthread_rwlock_init(&st->rwlock, NULL); pthread_rwlock_wrlock(&localhost.rrdset_root_rwlock); diff --git a/src/rrd.h b/src/rrd.h index b291bdca..e61c58da 100644 --- a/src/rrd.h +++ b/src/rrd.h @@ -1,10 +1,3 @@ -#include -#include -#include - -#include "avl.h" -#include "storage_number.h" - #ifndef NETDATA_RRD_H #define NETDATA_RRD_H 1 @@ -93,7 +86,7 @@ struct rrdcontext { size_t use_count; - // avl_tree_lock variables_root_index; + avl_tree_lock variables_root_index; }; typedef struct rrdcontext RRDCONTEXT; @@ -267,6 +260,11 @@ struct rrdset { avl_tree_lock dimensions_index; // the root of the dimensions index RRDDIM *dimensions; // the actual data for every dimension + + // ------------------------------------------------------------------------ + // local variables + + avl_tree_lock variables_root_index; }; typedef struct rrdset RRDSET; @@ -285,7 +283,7 @@ struct rrdhost { avl_tree_lock rrdset_root_index_name; avl_tree_lock rrdcontext_root_index; - // avl_tree_lock variables_root_index; + avl_tree_lock variables_root_index; }; typedef struct rrdhost RRDHOST; diff --git a/src/rrd2json.c b/src/rrd2json.c index 5da41736..f6c74201 100644 --- a/src/rrd2json.c +++ b/src/rrd2json.c @@ -1,15 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - -#include "log.h" #include "common.h" -#include "rrd2json.h" #define HOSTNAME_MAX 1024 char *hostname = "unknown"; diff --git a/src/rrd2json.h b/src/rrd2json.h index 42a7e200..bb7b0406 100644 --- a/src/rrd2json.h +++ b/src/rrd2json.h @@ -1,8 +1,3 @@ -#include - -#include "web_buffer.h" -#include "rrd.h" - #ifndef NETDATA_RRD2JSON_H #define NETDATA_RRD2JSON_H 1 diff --git a/src/storage_number.c b/src/storage_number.c index df80bf72..70eb6384 100644 --- a/src/storage_number.c +++ b/src/storage_number.c @@ -1,21 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#ifdef STORAGE_WITH_MATH -#include -#endif - #include "common.h" -#include "log.h" -#include "storage_number.h" - -#if __GNUC__ -#if __x86_64__ || __ppc64__ -#define ENVIRONMENT64 -#else -#define ENVIRONMENT32 -#endif -#endif extern char *print_number_lu_r(char *str, unsigned long uvalue); extern char *print_number_llu_r(char *str, unsigned long long uvalue); diff --git a/src/storage_number.h b/src/storage_number.h index 1b7da79f..7ff83943 100644 --- a/src/storage_number.h +++ b/src/storage_number.h @@ -1,5 +1,3 @@ -#include - #ifndef NETDATA_STORAGE_NUMBER_H #define NETDATA_STORAGE_NUMBER_H diff --git a/src/sys_fs_cgroup.c b/src/sys_fs_cgroup.c index 5bc408c9..8c83190b 100644 --- a/src/sys_fs_cgroup.c +++ b/src/sys_fs_cgroup.c @@ -1,23 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - #include "common.h" -#include "appconfig.h" -#include "procfile.h" -#include "log.h" -#include "rrd.h" -#include "main.h" -#include "popen.h" -#include "proc_self_mountinfo.h" // ---------------------------------------------------------------------------- // cgroup globals diff --git a/src/sys_kernel_mm_ksm.c b/src/sys_kernel_mm_ksm.c index 8064cb18..f6cf52f9 100644 --- a/src/sys_kernel_mm_ksm.c +++ b/src/sys_kernel_mm_ksm.c @@ -1,21 +1,9 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "procfile.h" -#include "rrd.h" -#include "plugin_proc.h" -typedef struct name_value { +typedef struct ksm_name_value { char filename[FILENAME_MAX + 1]; unsigned long long value; -} NAME_VALUE; +} KSM_NAME_VALUE; #define PAGES_SHARED 0 #define PAGES_SHARING 1 @@ -23,7 +11,7 @@ typedef struct name_value { #define PAGES_VOLATILE 3 #define PAGES_TO_SCAN 4 -NAME_VALUE values[] = { +KSM_NAME_VALUE values[] = { [PAGES_SHARED] = { "/sys/kernel/mm/ksm/pages_shared", 0ULL }, [PAGES_SHARING] = { "/sys/kernel/mm/ksm/pages_sharing", 0ULL }, [PAGES_UNSHARED] = { "/sys/kernel/mm/ksm/pages_unshared", 0ULL }, diff --git a/src/unit_test.c b/src/unit_test.c index dbf9190b..1a8ef012 100644 --- a/src/unit_test.c +++ b/src/unit_test.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include - #include "common.h" -#include "storage_number.h" -#include "rrd.h" -#include "log.h" -#include "web_buffer.h" int check_storage_number(calculated_number n, int debug) { char buffer[100]; diff --git a/src/url.c b/src/url.c index bd22b818..26d53cb8 100644 --- a/src/url.c +++ b/src/url.c @@ -1,13 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include - #include "common.h" -#include "log.h" -#include "url.h" // ---------------------------------------------------------------------------- // URL encode / decode diff --git a/src/web_buffer.c b/src/web_buffer.c index 582890e1..a7c16ec5 100644 --- a/src/web_buffer.c +++ b/src/web_buffer.c @@ -1,16 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include - -#ifdef STORAGE_WITH_MATH -#include -#endif - #include "common.h" -#include "web_buffer.h" -#include "log.h" #define BUFFER_OVERFLOW_EOF "EOF" diff --git a/src/web_buffer.h b/src/web_buffer.h index 399eb84a..6b10c525 100644 --- a/src/web_buffer.h +++ b/src/web_buffer.h @@ -1,7 +1,3 @@ -#include -#include -#include "storage_number.h" - #ifndef NETDATA_WEB_BUFFER_H #define NETDATA_WEB_BUFFER_H 1 diff --git a/src/web_buffer_svg.c b/src/web_buffer_svg.c index 250bbc89..087c79a3 100644 --- a/src/web_buffer_svg.c +++ b/src/web_buffer_svg.c @@ -1,17 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "url.h" -#include "web_buffer.h" -#include "web_buffer_svg.h" #define BADGE_HORIZONTAL_PADDING 4 #define VERDANA_KERNING 0.5 diff --git a/src/web_buffer_svg.h b/src/web_buffer_svg.h index b853e97d..1281847e 100644 --- a/src/web_buffer_svg.h +++ b/src/web_buffer_svg.h @@ -1,6 +1,3 @@ -#include "web_buffer.h" -#include "dictionary.h" - #ifndef NETDATA_WEB_BUFFER_SVG_H #define NETDATA_WEB_BUFFER_SVG_H 1 diff --git a/src/web_client.c b/src/web_client.c index ea4a942e..71419cea 100644 --- a/src/web_client.c +++ b/src/web_client.c @@ -1,38 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// TCP_CORK -#include - #include "common.h" -#include "log.h" -#include "main.h" -#include "appconfig.h" -#include "url.h" -#include "web_buffer.h" -#include "web_server.h" -#include "global_statistics.h" -#include "rrd.h" -#include "rrd2json.h" -#include "registry.h" -#include "web_buffer_svg.h" -#include "web_client.h" #define INITIAL_WEB_DATA_LENGTH 16384 #define WEB_REQUEST_LENGTH 16384 diff --git a/src/web_client.h b/src/web_client.h index a3198857..a8339a32 100644 --- a/src/web_client.h +++ b/src/web_client.h @@ -1,19 +1,3 @@ - -#ifdef NETDATA_WITH_ZLIB -#include -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "web_buffer.h" -#include "dictionary.h" - #ifndef NETDATA_WEB_CLIENT_H #define NETDATA_WEB_CLIENT_H 1 diff --git a/src/web_server.c b/src/web_server.c index 14ac610f..1af02b3b 100644 --- a/src/web_server.c +++ b/src/web_server.c @@ -1,32 +1,4 @@ -#ifdef HAVE_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" -#include "log.h" -#include "appconfig.h" -#include "url.h" -#include "web_buffer.h" -#include "web_client.h" -#include "web_server.h" -#include "global_statistics.h" -#include "rrd.h" -#include "rrd2json.h" -#include "../config.h" int listen_backlog = LISTEN_BACKLOG; int listen_fds_count = 0; -- 2.39.2