summaryrefslogtreecommitdiffstats
path: root/libnetdata/libnetdata.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libnetdata/libnetdata.h (renamed from src/common.h)252
1 files changed, 100 insertions, 152 deletions
diff --git a/src/common.h b/libnetdata/libnetdata.h
index 15fc50a6a..0bac3dc8f 100644
--- a/src/common.h
+++ b/libnetdata/libnetdata.h
@@ -1,10 +1,16 @@
-#ifndef NETDATA_COMMON_H
-#define NETDATA_COMMON_H 1
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#ifndef NETDATA_LIB_H
+#define NETDATA_LIB_H 1
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#define OS_LINUX 1
+#define OS_FREEBSD 2
+#define OS_MACOS 3
+
// ----------------------------------------------------------------------------
// system include files for all netdata C programs
@@ -14,9 +20,9 @@
#if defined(HAVE_JEMALLOC_JEMALLOC_H)
#include <jemalloc/jemalloc.h>
-#else
+#else // !defined(HAVE_JEMALLOC_JEMALLOC_H)
#include <malloc.h>
-#endif
+#endif // !defined(HAVE_JEMALLOC_JEMALLOC_H)
#elif defined(ENABLE_TCMALLOC)
@@ -28,7 +34,18 @@
#include <malloc.h>
#endif /* __FreeBSD__ || __APPLE__ */
-#endif
+#endif /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
+
+// ----------------------------------------------------------------------------
+
+#if defined(__FreeBSD__)
+#include <pthread_np.h>
+#define NETDATA_OS_TYPE "freebsd"
+#elif defined(__APPLE__)
+#define NETDATA_OS_TYPE "macos"
+#else
+#define NETDATA_OS_TYPE "linux"
+#endif /* __FreeBSD__, __APPLE__*/
#include <pthread.h>
#include <errno.h>
@@ -42,41 +59,20 @@
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-#ifdef HAVE_RESOLV_H
-#include <resolv.h>
-#endif
-
+#include <libgen.h>
#include <dirent.h>
#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <pwd.h>
#include <locale.h>
-
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
#include <net/if.h>
-
#include <poll.h>
#include <signal.h>
#include <syslog.h>
#include <sys/mman.h>
-
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
-
#include <sys/resource.h>
#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/statvfs.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -86,6 +82,42 @@
#include <unistd.h>
#include <uuid/uuid.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_RESOLV_H
+#include <resolv.h>
+#endif
+
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_SYS_STATFS_H
+#include <sys/statfs.h>
+#endif
+
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+
// #1408
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
@@ -94,10 +126,6 @@
#include <sys/sysmacros.h>
#endif
-/*
-#include <mntent.h>
-*/
-
#ifdef STORAGE_WITH_MATH
#include <math.h>
#include <float.h>
@@ -117,27 +145,6 @@
#include <sys/capability.h>
#endif
-// ----------------------------------------------------------------------------
-// netdata chart priorities
-
-// This is a work in progress - to scope is to collect here all chart priorities.
-// These should be based on the CONTEXT of the charts + the chart id when needed
-// - for each SECTION +1000 (or +X000 for big sections)
-// - for each FAMILY +100
-// - for each CHART +10
-
-// Memory Section - 1xxx
-#define NETDATA_CHART_PRIO_MEM_SYSTEM 1000
-#define NETDATA_CHART_PRIO_MEM_SYSTEM_AVAILABLE 1010
-#define NETDATA_CHART_PRIO_MEM_SYSTEM_COMMITTED 1020
-#define NETDATA_CHART_PRIO_MEM_SYSTEM_PGFAULTS 1030
-#define NETDATA_CHART_PRIO_MEM_KERNEL 1100
-#define NETDATA_CHART_PRIO_MEM_SLAB 1200
-#define NETDATA_CHART_PRIO_MEM_HUGEPAGES 1250
-#define NETDATA_CHART_PRIO_MEM_KSM 1300
-#define NETDATA_CHART_PRIO_MEM_NUMA 1400
-#define NETDATA_CHART_PRIO_MEM_HW 1500
-
// ----------------------------------------------------------------------------
// netdata common definitions
@@ -197,92 +204,6 @@
#define GUID_LEN 36
-// ----------------------------------------------------------------------------
-// netdata include files
-
-#include "clocks.h"
-#include "log.h"
-#include "threads.h"
-#include "locks.h"
-#include "simple_pattern.h"
-#include "avl.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"
-
-#if defined(__FreeBSD__)
-#include <pthread_np.h>
-#include "plugin_freebsd.h"
-#define NETDATA_OS_TYPE "freebsd"
-#elif defined(__APPLE__)
-#include "plugin_macos.h"
-#define NETDATA_OS_TYPE "macos"
-#else
-#include "plugin_proc.h"
-#include "plugin_proc_diskspace.h"
-#define NETDATA_OS_TYPE "linux"
-#endif /* __FreeBSD__, __APPLE__*/
-
-typedef enum rrdcalc_status {
- RRDCALC_STATUS_REMOVED = -2,
- RRDCALC_STATUS_UNDEFINED = -1,
- RRDCALC_STATUS_UNINITIALIZED = 0,
- RRDCALC_STATUS_CLEAR = 1,
- RRDCALC_STATUS_RAISED = 2,
- RRDCALC_STATUS_WARNING = 3,
- RRDCALC_STATUS_CRITICAL = 4
-} RRDCALC_STATUS;
-
-#include "eval.h"
-#include "health.h"
-
-#include "statistical.h"
-#include "socket.h"
-#include "rrd.h"
-#include "plugin_tc.h"
-#include "plugins_d.h"
-#include "statsd.h"
-#include "rrd2json.h"
-#include "rrd2json_api_old.h"
-#include "web_client.h"
-#include "web_server.h"
-#include "registry.h"
-#include "signals.h"
-#include "daemon.h"
-#include "main.h"
-#include "unit_test.h"
-#include "ipc.h"
-#include "backends.h"
-#include "backend_prometheus.h"
-#include "inlined.h"
-#include "adaptive_resortable_list.h"
-#include "rrdpush.h"
-#include "web_api_v1.h"
-#include "web_api_old.h"
-
-extern char *netdata_configured_hostname;
-extern char *netdata_configured_config_dir;
-extern char *netdata_configured_log_dir;
-extern char *netdata_configured_plugins_dir_base;
-extern char *netdata_configured_plugins_dir;
-extern char *netdata_configured_web_dir;
-extern char *netdata_configured_cache_dir;
-extern char *netdata_configured_varlib_dir;
-extern char *netdata_configured_home_dir;
-extern char *netdata_configured_host_prefix;
-extern char *netdata_configured_timezone;
-
extern void netdata_fix_chart_id(char *s);
extern void netdata_fix_chart_name(char *s);
@@ -296,6 +217,7 @@ extern int snprintfz(char *dst, size_t n, const char *fmt, ...) PRINTFLIKE(3, 4
// memory allocation functions that handle failures
#ifdef NETDATA_LOG_ALLOCATIONS
+extern __thread size_t log_thread_memory_allocations;
#define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
#define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
#define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
@@ -307,13 +229,13 @@ extern void *callocz_int(const char *file, const char *function, const unsigned
extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
-#else
+#else // NETDATA_LOG_ALLOCATIONS
extern char *strdupz(const char *s) MALLOCLIKE NEVERNULL;
extern void *callocz(size_t nmemb, size_t size) MALLOCLIKE NEVERNULL;
extern void *mallocz(size_t size) MALLOCLIKE NEVERNULL;
extern void *reallocz(void *ptr, size_t size) MALLOCLIKE NEVERNULL;
extern void freez(void *ptr);
-#endif
+#endif // NETDATA_LOG_ALLOCATIONS
extern void json_escape_string(char *dst, const char *src, size_t size);
extern void json_fix_string(char *s);
@@ -327,19 +249,9 @@ extern struct rlimit rlimit_nofile;
extern int enable_ksm;
-extern int sleep_usec(usec_t usec);
-
extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
-extern int processors;
-extern long get_system_cpus(void);
-
-extern pid_t pid_max;
-extern pid_t get_system_pid_max(void);
-
-/* Number of ticks per second */
-extern unsigned int hz;
-extern void get_system_HZ(void);
+extern int verify_netdata_host_prefix();
extern int recursively_delete_dir(const char *path, const char *reason);
@@ -348,6 +260,18 @@ extern const char *os_type;
extern const char *program_version;
+extern char *strdupz_path_subpath(const char *path, const char *subpath);
+extern int path_is_dir(const char *path, const char *subpath);
+extern int path_is_file(const char *path, const char *subpath);
+extern void recursive_config_double_dir_load(
+ const char *user_path
+ , const char *stock_path
+ , const char *subpath
+ , int (*callback)(const char *filename, void *data)
+ , void *data
+ , size_t depth
+);
+
/* fix for alpine linux */
#ifndef RUSAGE_THREAD
#ifdef RUSAGE_CHILDREN
@@ -357,4 +281,28 @@ extern const char *program_version;
#define BITS_IN_A_KILOBIT 1000
-#endif /* NETDATA_COMMON_H */
+
+extern void netdata_cleanup_and_exit(int ret) NORETURN;
+extern char *netdata_configured_host_prefix;
+
+#include "os.h"
+#include "storage_number/storage_number.h"
+#include "threads/threads.h"
+#include "buffer/buffer.h"
+#include "locks/locks.h"
+#include "avl/avl.h"
+#include "inlined.h"
+#include "clocks/clocks.h"
+#include "popen/popen.h"
+#include "simple_pattern/simple_pattern.h"
+#include "socket/socket.h"
+#include "config/appconfig.h"
+#include "log/log.h"
+#include "procfile/procfile.h"
+#include "dictionary/dictionary.h"
+#include "eval/eval.h"
+#include "statistical/statistical.h"
+#include "adaptive_resortable_list/adaptive_resortable_list.h"
+#include "url/url.h"
+
+#endif // NETDATA_LIB_H