summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--CMakeLists.txt52
-rw-r--r--Makefile.am13
-rw-r--r--collectors/README.md18
-rw-r--r--collectors/all.h4
-rw-r--r--collectors/apps.plugin/apps_groups.conf2
-rw-r--r--collectors/nfacct.plugin/README.md47
-rw-r--r--collectors/nfacct.plugin/plugin_nfacct.c677
-rw-r--r--collectors/nfacct.plugin/plugin_nfacct.h30
-rw-r--r--collectors/plugins.d/README.md1
-rw-r--r--configure.ac7
-rw-r--r--daemon/main.c1
-rw-r--r--docs/Add-more-charts-to-netdata.md5
-rwxr-xr-xdocs/generator/buildyaml.sh2
-rwxr-xr-xnetdata-installer.sh11
15 files changed, 490 insertions, 383 deletions
diff --git a/.gitignore b/.gitignore
index 7412721846..f0de5df0b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -50,6 +50,9 @@ freeipmi.plugin
cups.plugin
!cups.plugin/
+nfacct.plugin
+!nfacct.plugin/
+
cgroup-network
!cgroup-network/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cb1e1ef482..b7d83b85a3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -248,7 +248,6 @@ set(FREEIPMI_PLUGIN_FILES
set(NFACCT_PLUGIN_FILES
collectors/nfacct.plugin/plugin_nfacct.c
- collectors/nfacct.plugin/plugin_nfacct.h
)
set(PROC_PLUGIN_FILES
@@ -458,13 +457,6 @@ set(NETDATA_FILES
${WEB_PLUGIN_FILES}
)
-IF(LINUX AND MNL_LIBRARIES AND NFACCT_LIBRARIES)
- message(STATUS "nfacct.plugin: enabled (will work only if netdata runs as root)")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DINTERNAL_PLUGIN_NFACCT=1")
-ELSE()
- message(STATUS "nfacct.plugin: disabled (requires libmnl and libnetfilter_acct)")
-ENDIF()
-
include_directories(AFTER .)
add_definitions(
@@ -488,22 +480,12 @@ IF(LINUX)
add_executable(netdata config.h ${NETDATA_FILES}
${CGROUPS_PLUGIN_FILES}
${DISKSPACE_PLUGIN_FILES}
- ${NFACCT_PLUGIN_FILES}
${PROC_PLUGIN_FILES}
${TC_PLUGIN_FILES}
)
- target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES}
- ${MNL_LIBRARIES}
- ${NFACCT_LIBRARIES}
- )
- target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS}
- ${MNL_INCLUDE_DIRS}
- ${NFACCT_INCLUDE_DIRS}
- )
- target_compile_options(netdata PUBLIC ${NETDATA_COMMON_CFLAGS}
- ${MNL_CFLAGS_OTHER}
- ${NFACCT_CFLAGS_OTHER}
- )
+ target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES})
+ target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
+ target_compile_options(netdata PUBLIC ${NETDATA_COMMON_CFLAGS})
SET(ENABLE_PLUGIN_CGROUP_NETWORK True)
SET(ENABLE_PLUGIN_APPS True)
@@ -532,6 +514,12 @@ ELSE()
SET(ENABLE_PLUGIN_FREEIPMI False)
ENDIF()
+IF(LINUX AND MNL_LIBRARIES AND NFACCT_LIBRARIES)
+ SET(ENABLE_PLUGIN_NFACCT True)
+ELSE()
+ SET(ENABLE_PLUGIN_NFACCT False)
+ENDIF()
+
# -----------------------------------------------------------------------------
# apps.plugin
@@ -554,22 +542,36 @@ IF(ENABLE_PLUGIN_FREEIPMI)
message(STATUS "freeipmi.plugin: enabled")
add_executable(freeipmi.plugin config.h ${FREEIPMI_PLUGIN_FILES})
target_link_libraries (freeipmi.plugin libnetdata ${NETDATA_COMMON_LIBRARIES} ${IPMI_LIBRARIES})
- target_include_directories(apps.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS} ${IPMI_INCLUDE_DIRS})
- target_compile_options(apps.plugin PUBLIC ${NETDATA_COMMON_CFLAGS} ${IPMI_CFLAGS_OTHER})
+ target_include_directories(freeipmi.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS} ${IPMI_INCLUDE_DIRS})
+ target_compile_options(freeipmi.plugin PUBLIC ${NETDATA_COMMON_CFLAGS} ${IPMI_CFLAGS_OTHER})
ELSE()
message(STATUS "freeipmi.plugin: disabled (depends on libipmimonitoring)")
ENDIF()
# -----------------------------------------------------------------------------
+# nfacct.plugin
+
+IF(ENABLE_PLUGIN_NFACCT)
+ message(STATUS "nfacct.plugin: enabled")
+ add_executable(nfacct.plugin config.h ${NFACCT_PLUGIN_FILES})
+ target_link_libraries (nfacct.plugin libnetdata ${NETDATA_COMMON_LIBRARIES} ${MNL_LIBRARIES} ${NFACCT_LIBRARIES})
+ target_include_directories(nfacct.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS} ${MNL_INCLUDE_DIRS} ${NFACCT_INCLUDE_DIRS})
+ target_compile_options(nfacct.plugin PUBLIC ${NETDATA_COMMON_CFLAGS} ${MNL_CFLAGS_OTHER} ${NFACCT_CFLAGS_OTHER})
+ELSE()
+ message(STATUS "nfacct.plugin: disabled (requires libmnl and libnetfilter_acct)")
+ENDIF()
+
+
+# -----------------------------------------------------------------------------
# cgroup-network
IF(ENABLE_PLUGIN_CGROUP_NETWORK)
message(STATUS "cgroup-network: enabled")
add_executable(cgroup-network config.h ${CGROUP_NETWORK_FILES})
target_link_libraries (cgroup-network libnetdata ${NETDATA_COMMON_LIBRARIES})
- target_include_directories(apps.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
- target_compile_options(apps.plugin PUBLIC ${NETDATA_COMMON_CFLAGS})
+ target_include_directories(cgroup-network PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
+ target_compile_options(cgroup-network PUBLIC ${NETDATA_COMMON_CFLAGS})
ELSE()
message(STATUS "cgroup-network: disabled (requires Linux)")
ENDIF()
diff --git a/Makefile.am b/Makefile.am
index 376ccf178b..15777dd2ca 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -221,7 +221,7 @@ CUPS_PLUGIN_FILES = \
NFACCT_PLUGIN_FILES = \
collectors/nfacct.plugin/plugin_nfacct.c \
- collectors/nfacct.plugin/plugin_nfacct.h \
+ $(LIBNETDATA_FILES) \
$(NULL)
PROC_PLUGIN_FILES = \
@@ -449,7 +449,6 @@ if LINUX
NETDATA_FILES += \
$(CGROUPS_PLUGIN_FILES) \
$(DISKSPACE_PLUGIN_FILES) \
- $(NFACCT_PLUGIN_FILES) \
$(PROC_PLUGIN_FILES) \
$(TC_PLUGIN_FILES) \
$(NULL)
@@ -467,7 +466,6 @@ sbin_PROGRAMS += netdata
netdata_SOURCES = $(NETDATA_FILES)
netdata_LDADD = \
$(NETDATA_COMMON_LIBS) \
- $(OPTIONAL_NFACCT_LIBS) \
$(NULL)
if ENABLE_PLUGIN_APPS
@@ -504,3 +502,12 @@ if ENABLE_PLUGIN_CUPS
$(OPTIONAL_CUPS_LIBS) \
$(NULL)
endif
+
+if ENABLE_PLUGIN_NFACCT
+ plugins_PROGRAMS += nfacct.plugin
+ nfacct_plugin_SOURCES = $(NFACCT_PLUGIN_FILES)
+ nfacct_plugin_LDADD = \
+ $(NETDATA_COMMON_LIBS) \
+ $(OPTIONAL_NFACCT_LIBS) \
+ $(NULL)
+endif
diff --git a/collectors/README.md b/collectors/README.md
index d0393dae22..81efe19b71 100644
--- a/collectors/README.md
+++ b/collectors/README.md
@@ -13,7 +13,7 @@ To minimize the number of processes spawn for data collection, netdata also supp
Instead they support data collection **modules** written in the language of the orchestrator.
Usually the orchestrator provides a higher level abstraction, making it ideal for writing new
data collection modules with the minimum of code.
-
+
Currently netdata provides plugin orchestrators
BASH v4+ [charts.d.plugin](charts.d.plugin/),
node.js [node.d.plugin](node.d.plugin/) and
@@ -34,7 +34,7 @@ plugin|lang|O/S|runs as|modular|description
[freeipmi.plugin](freeipmi.plugin/)|`C`|linux, freebsd|external|-|collects metrics from enterprise hardware sensors, on Linux and FreeBSD servers.
[idlejitter.plugin](idlejitter.plugin/)|`C`|any|internal|-|measures CPU latency and jitter on all operating systems
[macos.plugin](macos.plugin/)|`C`|macos|internal|yes|collects resource usage and performance data on MacOS systems
-[nfacct.plugin](nfacct.plugin/)|`C`|linux|internal|-|collects netfilter firewall, connection tracker and accounting metrics using `libmnl` and `libnetfilter_acct`
+[nfacct.plugin](nfacct.plugin/)|`C`|linux|external|-|collects netfilter firewall, connection tracker and accounting metrics using `libmnl` and `libnetfilter_acct`
[node.d.plugin](node.d.plugin/)|`node.js`|any|external|yes|a **plugin orchestrator** for data collection modules written in `node.js`.
[plugins.d](plugins.d/)|`C`|any|internal|-|implements the **external plugins** API and serves external plugins
[proc.plugin](proc.plugin/)|`C`|linux|internal|yes|collects resource usage and performance data on Linux systems
@@ -46,7 +46,7 @@ plugin|lang|O/S|runs as|modular|description
Each plugin can be enabled or disabled via `netdata.conf`, section `[plugins]`.
-At this section there a list of all the plugins with a boolean setting to enable them or disable them.
+At this section there a list of all the plugins with a boolean setting to enable them or disable them.
The exception is `statsd.plugin` that has its own `[statsd]` section.
@@ -66,14 +66,14 @@ The internal data collection API consists of the following calls:
```c
collect_data() {
// collect data here (one iteration)
-
+
collected_number collected_value = collect_a_value();
-
+
// give the metrics to netdata
-
+
static RRDSET *st = NULL; // the chart
static RRDDIM *rd = NULL; // a dimension attached to this chart
-
+
if(unlikely(!st)) {
// we haven't created this chart before
// create it now
@@ -100,10 +100,10 @@ collect_data() {
// let netdata know we start a new iteration on it
rrdset_next(st);
}
-
+
// give the collected value(s) to the chart
rrddim_set_by_pointer(st, rd, collected_value);
-
+
// signal netdata we are done with this iteration
rrdset_done(st);
}
diff --git a/collectors/all.h b/collectors/all.h
index 9f1d7613b5..236bb4f944 100644
--- a/collectors/all.h
+++ b/collectors/all.h
@@ -12,7 +12,6 @@
#include "idlejitter.plugin/plugin_idlejitter.h"
#include "cgroups.plugin/sys_fs_cgroup.h"
#include "diskspace.plugin/plugin_diskspace.h"
-#include "nfacct.plugin/plugin_nfacct.h"
#include "proc.plugin/plugin_proc.h"
#include "tc.plugin/plugin_tc.h"
#include "macos.plugin/plugin_macos.h"
@@ -288,9 +287,6 @@
#define NETDATA_CHART_PRIO_NETFILTER_ERRORS 8705
#define NETDATA_CHART_PRIO_NETFILTER_SEARCH 8710
-#define NETDATA_CHART_PRIO_NETFILTER_PACKETS 8906
-#define NETDATA_CHART_PRIO_NETFILTER_BYTES 8907
-
// SYNPROXY
#define NETDATA_CHART_PRIO_SYNPROXY_SYN_RECEIVED 8751
diff --git a/collectors/apps.plugin/apps_groups.conf b/collectors/apps.plugin/apps_groups.conf
index 91206410f7..943351edf9 100644
--- a/collectors/apps.plugin/apps_groups.conf
+++ b/collectors/apps.plugin/apps_groups.conf
@@ -74,6 +74,8 @@ netdata: netdata
# plugins not defined here will be accumulated in netdata, above
apps.plugin: apps.plugin
freeipmi.plugin: freeipmi.plugin
+nfacct.plugin: nfacct.plugin
+cups.plugin: cups.plugin
charts.d.plugin: *charts.d.plugin*
node.d.plugin: *node.d.plugin*
python.d.plugin: *python.d.plugin*
diff --git a/collectors/nfacct.plugin/README.md b/collectors/nfacct.plugin/README.md
index 5f1ee2e7c8..b60fc6a44f 100644
--- a/collectors/nfacct.plugin/README.md
+++ b/collectors/nfacct.plugin/README.md
@@ -1,12 +1,47 @@
# nfacct.plugin
-This plugin that collects NFACCT statistics.
+`nfacct.plugin` collects Netfilter statistics.
-It is currently disabled by default, because it requires root access.
-We have to move the code to an external plugin to setuid just the plugin not the whole netdata server.
+## Prerequisites
-You can build netdata with it to test it though.
-Just run `./configure` (or `netdata-installer.sh`) with the option `--enable-plugin-nfacct` (and any other options you may need).
-Remember, you have to tell netdata you want it to run as `root` for this plugin to work.
+1. install `libmnl-dev` and `libnetfilter_acct-dev` using the package manager of your system.
+
+2. re-install netdata from source. The installer will detect that the required libraries are now available and will also build netdata.plugin.
+
+Keep in mind that NFACCT requires root access, so the plugin is setuid to root.
+
+## Charts
+
+The plugin provides Netfilter connection tracker statistics and nfacct packet and bandwidth accounting:
+
+Connection tracker:
+1. Connections.
+2. Changes.
+3. Expectations.
+4. Errors.
+5. Searches.
+
+Netfilter accounting:
+1. Packets.
+2. Bandwidth.
+
+## Configuration
+
+If you need to disable NFACCT for netdata, edit /etc/netdata/netdata.conf and set:
+
+```
+[plugins]
+ nfacct = no
+```
+
+## Debugging
+
+You can run the plugin by hand:
+
+```
+sudo /usr/libexec/netdata/plugins.d/nfacct.plugin 1 debug
+```
+
+You will get verbose output on what the plugin does.
[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Fnfacct.plugin%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
diff --git a/collectors/nfacct.plugin/plugin_nfacct.c b/collectors/nfacct.plugin/plugin_nfacct.c
index 7d42dd1897..b6788e6180 100644
--- a/collectors/nfacct.plugin/plugin_nfacct.c
+++ b/collectors/nfacct.plugin/plugin_nfacct.c
@@ -1,11 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "plugin_nfacct.h"
-
-#if defined(INTERNAL_PLUGIN_NFACCT)
+#include "../../libnetdata/libnetdata.h"
#define PLUGIN_NFACCT_NAME "nfacct.plugin"
+#define NETDATA_CHART_PRIO_NETFILTER_NEW 8701
+#define NETDATA_CHART_PRIO_NETFILTER_CHANGES 8702
+#define NETDATA_CHART_PRIO_NETFILTER_EXPECT 8703
+#define NETDATA_CHART_PRIO_NETFILTER_ERRORS 8705
+#define NETDATA_CHART_PRIO_NETFILTER_SEARCH 8710
+
+#define NETDATA_CHART_PRIO_NETFILTER_PACKETS 8906
+#define NETDATA_CHART_PRIO_NETFILTER_BYTES 8907
+
#ifdef HAVE_LIBMNL
#include <libmnl/libmnl.h>
@@ -15,6 +22,41 @@ static inline size_t mnl_buffer_size() {
return (size_t)s;
}
+// callback required by fatal()
+void netdata_cleanup_and_exit(int ret) {
+ exit(ret);
+}
+
+void send_statistics( const char *action, const char *action_result, const char *action_data) {
+ (void) action;
+ (void) action_result;
+ (void) action_data;
+ return;
+}
+
+// callbacks required by popen()
+void signals_block(void) {};
+void signals_unblock(void) {};
+void signals_reset(void) {};
+
+// callback required by eval()
+int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
+ (void)variable;
+ (void)hash;
+ (void)rc;
+ (void)result;
+ return 0;
+};
+
+// required by get_system_cpus()
+char *netdata_configured_host_prefix = "";
+
+// Variables
+
+static int debug = 0;
+
+static int netdata_update_every = 1;
+
// ----------------------------------------------------------------------------
// DO_NFSTAT - collect netfilter connection tracker statistics via netlink
// example: https://github.com/formorer/pkg-conntrack-tools/blob/master/src/conntrack.c
@@ -103,17 +145,6 @@ static int nfstat_init(int update_every) {
return 0;
}
-static void nfstat_cleanup() {
- if(nfstat_root.mnl) {
- mnl_socket_close(nfstat_root.mnl);
- nfstat_root.mnl = NULL;
- }
-
- freez(nfstat_root.buf);
- nfstat_root.buf = NULL;
- nfstat_root.buf_size = 0;
-}
-
static struct nlmsghdr * nfct_mnl_nlmsghdr_put(char *buf, uint16_t subsys, uint16_t type, uint8_t family, uint32_t seq) {
struct nlmsghdr *nlh;
struct nfgenmsg *nfh;
@@ -292,191 +323,211 @@ static int nfstat_collect() {
}
static void nfstat_send_metrics() {
-
- {
- static RRDSET *st_new = NULL;
- static RRDDIM *rd_new = NULL, *rd_ignore = NULL, *rd_invalid = NULL;
-
- if(!st_new) {
- st_new = rrdset_create_localhost(
- RRD_TYPE_NET_STAT_NETFILTER
- , RRD_TYPE_NET_STAT_CONNTRACK "_new"
- , NULL
- , RRD_TYPE_NET_STAT_CONNTRACK
- , NULL
- , "Connection Tracker New Connections"
- , "connections/s"
- , PLUGIN_NFACCT_NAME
- , NULL
- , NETDATA_CHART_PRIO_NETFILTER_NEW
- , nfstat_root.update_every
- , RRDSET_TYPE_LINE
- );
-
- rd_new = rrddim_add(st_new, nfstat_root.attr2name[CTA_STATS_NEW], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_ignore = rrddim_add(st_new, nfstat_root.attr2name[CTA_STATS_IGNORE], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_invalid = rrddim_add(st_new, nfstat_root.attr2name[CTA_STATS_INVALID], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- }
- else
- rrdset_next(st_new);
-
- rrddim_set_by_pointer(st_new, rd_new, (collected_number) nfstat_root.metrics[CTA_STATS_NEW]);
- rrddim_set_by_pointer(st_new, rd_ignore, (collected_number) nfstat_root.metrics[CTA_STATS_IGNORE]);
- rrddim_set_by_pointer(st_new, rd_invalid, (collected_number) nfstat_root.metrics[CTA_STATS_INVALID]);
-
- rrdset_done(st_new);
- }
+ static int new_chart_generated = 0, changes_chart_generated = 0, search_chart_generated = 0, errors_chart_generated = 0, expect_chart_generated = 0;
+
+ if(!new_chart_generated) {
+ new_chart_generated = 1;
+
+ printf("CHART %s.%s '' 'Connection Tracker New Connections' 'connections/s' %s '' line %d %d %s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_new"
+ , RRD_TYPE_NET_STAT_CONNTRACK
+ , NETDATA_CHART_PRIO_NETFILTER_NEW
+ , nfstat_root.update_every
+ , PLUGIN_NFACCT_NAME
+ );
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_NEW]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_IGNORE]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_INVALID]);
+ }
+
+ printf(
+ "BEGIN %s.%s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_new"
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_NEW]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_NEW]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_IGNORE]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_IGNORE]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_INVALID]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_INVALID]
+ );
+ printf("END\n");
// ----------------------------------------------------------------
- {
- static RRDSET *st_changes = NULL;
- static RRDDIM *rd_inserted = NULL, *rd_deleted = NULL, *rd_delete_list = NULL;
-
- if(!st_changes) {
- st_changes = rrdset_create_localhost(
- RRD_TYPE_NET_STAT_NETFILTER
- , RRD_TYPE_NET_STAT_CONNTRACK "_changes"
- , NULL
- , RRD_TYPE_NET_STAT_CONNTRACK
- , NULL
- , "Connection Tracker Changes"
- , "changes/s"
- , PLUGIN_NFACCT_NAME
- , NULL
- , NETDATA_CHART_PRIO_NETFILTER_CHANGES
- , nfstat_root.update_every
- , RRDSET_TYPE_LINE
- );
- rrdset_flag_set(st_changes, RRDSET_FLAG_DETAIL);
-
- rd_inserted = rrddim_add(st_changes, nfstat_root.attr2name[CTA_STATS_INSERT], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_deleted = rrddim_add(st_changes, nfstat_root.attr2name[CTA_STATS_DELETE], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_delete_list = rrddim_add(st_changes, nfstat_root.attr2name[CTA_STATS_DELETE_LIST], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- }
- else
- rrdset_next(st_changes);
-
- rrddim_set_by_pointer(st_changes, rd_inserted, (collected_number) nfstat_root.metrics[CTA_STATS_INSERT]);
- rrddim_set_by_pointer(st_changes, rd_deleted, (collected_number) nfstat_root.metrics[CTA_STATS_DELETE]);
- rrddim_set_by_pointer(st_changes, rd_delete_list, (collected_number) nfstat_root.metrics[CTA_STATS_DELETE_LIST]);
+ if(!changes_chart_generated) {
+ changes_chart_generated = 1;
- rrdset_done(st_changes);
- }
+ printf("CHART %s.%s '' 'Connection Tracker Changes' 'changes/s' %s '' line %d %d detail %s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_changes"
+ , RRD_TYPE_NET_STAT_CONNTRACK
+ , NETDATA_CHART_PRIO_NETFILTER_CHANGES
+ , nfstat_root.update_every
+ , PLUGIN_NFACCT_NAME
+ );
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_INSERT]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_DELETE]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_DELETE_LIST]);
+ }
+
+ printf(
+ "BEGIN %s.%s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_changes"
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_INSERT]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_INSERT]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_DELETE]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_DELETE]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_DELETE_LIST]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_DELETE_LIST]
+ );
+ printf("END\n");
// ----------------------------------------------------------------
- {
- static RRDSET *st_search = NULL;
- static RRDDIM *rd_searched = NULL, *rd_restarted = NULL, *rd_found = NULL;
-
- if(!st_search) {
- st_search = rrdset_create_localhost(
- RRD_TYPE_NET_STAT_NETFILTER
- , RRD_TYPE_NET_STAT_CONNTRACK "_search"
- , NULL
- , RRD_TYPE_NET_STAT_CONNTRACK
- , NULL
- , "Connection Tracker Searches"
- , "searches/s"
- , PLUGIN_NFACCT_NAME
- , NULL
- , NETDATA_CHART_PRIO_NETFILTER_SEARCH
- , nfstat_root.update_every
- , RRDSET_TYPE_LINE
- );
- rrdset_flag_set(st_search, RRDSET_FLAG_DETAIL);
-
- rd_searched = rrddim_add(st_search, nfstat_root.attr2name[CTA_STATS_SEARCHED], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_restarted = rrddim_add(st_search, nfstat_root.attr2name[CTA_STATS_SEARCH_RESTART], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_found = rrddim_add(st_search, nfstat_root.attr2name[CTA_STATS_FOUND], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- }
- else
- rrdset_next(st_search);
+ if(!search_chart_generated) {
+ search_chart_generated = 1;
- rrddim_set_by_pointer(st_search, rd_searched, (collected_number) nfstat_root.metrics[CTA_STATS_SEARCHED]);
- rrddim_set_by_pointer(st_search, rd_restarted, (collected_number) nfstat_root.metrics[CTA_STATS_SEARCH_RESTART]);
- rrddim_set_by_pointer(st_search, rd_found, (collected_number) nfstat_root.metrics[CTA_STATS_FOUND]);
-
- rrdset_done(st_search);
- }
+ printf("CHART %s.%s '' 'Connection Tracker Searches' 'searches/s' %s '' line %d %d detail %s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_search"
+ , RRD_TYPE_NET_STAT_CONNTRACK
+ , NETDATA_CHART_PRIO_NETFILTER_SEARCH
+ , nfstat_root.update_every
+ , PLUGIN_NFACCT_NAME
+ );
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_SEARCHED]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_SEARCH_RESTART]);
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_FOUND]);
+ }
+
+ printf(
+ "BEGIN %s.%s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_search"
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_SEARCHED]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_SEARCHED]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_SEARCH_RESTART]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_SEARCH_RESTART]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_FOUND]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_FOUND]
+ );
+ printf("END\n");
// ----------------------------------------------------------------
- {
- static RRDSET *st_errors = NULL;
- static RRDDIM *rd_error = NULL, *rd_insert_failed = NULL, *rd_drop = NULL, *rd_early_drop = NULL;
-
- if(!st_errors) {
- st_errors = rrdset_create_localhost(
- RRD_TYPE_NET_STAT_NETFILTER
- , RRD_TYPE_NET_STAT_CONNTRACK "_errors"
- , NULL
- , RRD_TYPE_NET_STAT_CONNTRACK
- , NULL
- , "Connection Tracker Errors"
- , "events/s"
- , PLUGIN_NFACCT_NAME
- , NULL
- , NETDATA_CHART_PRIO_NETFILTER_ERRORS
- , nfstat_root.update_every
- , RRDSET_TYPE_LINE
- );
- rrdset_flag_set(st_errors, RRDSET_FLAG_DETAIL);
-
- rd_error = rrddim_add(st_errors, nfstat_root.attr2name[CTA_STATS_ERROR], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_insert_failed = rrddim_add(st_errors, nfstat_root.attr2name[CTA_STATS_INSERT_FAILED], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_drop = rrddim_add(st_errors, nfstat_root.attr2name[CTA_STATS_DROP], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_early_drop = rrddim_add(st_errors, nfstat_root.attr2name[CTA_STATS_EARLY_DROP], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- }
- else
- rrdset_next(st_errors);
+ if(!errors_chart_generated) {
+ errors_chart_generated = 1;
- rrddim_set_by_pointer(st_errors, rd_error, (collected_number) nfstat_root.metrics[CTA_STATS_ERROR]);
- rrddim_set_by_pointer(st_errors, rd_insert_failed, (collected_number) nfstat_root.metrics[CTA_STATS_INSERT_FAILED]);
- rrddim_set_by_pointer(st_errors, rd_drop, (collected_number) nfstat_root.metrics[CTA_STATS_DROP]);
- rrddim_set_by_pointer(st_errors, rd_early_drop, (collected_number) nfstat_root.metrics[CTA_STATS_EARLY_DROP]);
-
- rrdset_done(st_errors);
- }
+ printf("CHART %s.%s '' 'Connection Tracker Errors' 'events/s' %s '' line %d %d detail %s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_errors"
+ , RRD_TYPE_NET_STAT_CONNTRACK
+ , NETDATA_CHART_PRIO_NETFILTER_ERRORS
+ , nfstat_root.update_every
+ , PLUGIN_NFACCT_NAME
+ );
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_ERROR]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_INSERT_FAILED]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_DROP]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_EARLY_DROP]);
+ }
+
+ printf(
+ "BEGIN %s.%s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_errors"
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_ERROR]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_ERROR]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_INSERT_FAILED]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_INSERT_FAILED]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_DROP]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_DROP]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_EARLY_DROP]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_EARLY_DROP]
+ );
+ printf("END\n");
// ----------------------------------------------------------------
- {
- static RRDSET *st_expect = NULL;
- static RRDDIM *rd_new = NULL, *rd_created = NULL, *rd_deleted = NULL;
-
- if(!st_expect) {
- st_expect = rrdset_create_localhost(
- RRD_TYPE_NET_STAT_NETFILTER
- , RRD_TYPE_NET_STAT_CONNTRACK "_expect"
- , NULL
- , RRD_TYPE_NET_STAT_CONNTRACK
- , NULL
- , "Connection Tracker Expectations"
- , "expectations/s"
- , PLUGIN_NFACCT_NAME
- , NULL
- , NETDATA_CHART_PRIO_NETFILTER_EXPECT
- , nfstat_root.update_every
- , RRDSET_TYPE_LINE
- );
- rrdset_flag_set(st_expect, RRDSET_FLAG_DETAIL);
-
- rd_created = rrddim_add(st_expect, nfstat_root.attr2name_exp[CTA_STATS_EXP_CREATE], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_deleted = rrddim_add(st_expect, nfstat_root.attr2name_exp[CTA_STATS_EXP_DELETE], NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
- rd_new = rrddim_add(st_expect, nfstat_root.attr2name_exp[CTA_STATS_EXP_NEW], NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
- }
- else
- rrdset_next(st_expect);
-
- rrddim_set_by_pointer(st_expect, rd_created, (collected_number) nfstat_root.metrics_exp[CTA_STATS_EXP_CREATE]);
- rrddim_set_by_pointer(st_expect, rd_deleted, (collected_number) nfstat_root.metrics_exp[CTA_STATS_EXP_DELETE]);
- rrddim_set_by_pointer(st_expect, rd_new, (collected_number) nfstat_root.metrics_exp[CTA_STATS_EXP_NEW]);
-
- rrdset_done(st_expect);
- }
+ if(!expect_chart_generated) {
+ expect_chart_generated = 1;
+ printf("CHART %s.%s '' 'Connection Tracker Expectations' 'expectations/s' %s '' line %d %d detail %s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_expect"
+ , RRD_TYPE_NET_STAT_CONNTRACK
+ , NETDATA_CHART_PRIO_NETFILTER_EXPECT
+ , nfstat_root.update_every
+ , PLUGIN_NFACCT_NAME
+ );
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_EXP_CREATE]);
+ printf("DIMENSION %s '' incremental -1 1\n", nfstat_root.attr2name[CTA_STATS_EXP_DELETE]);
+ printf("DIMENSION %s '' incremental 1 1\n", nfstat_root.attr2name[CTA_STATS_EXP_NEW]);
+ }
+
+ printf(
+ "BEGIN %s.%s\n"
+ , RRD_TYPE_NET_STAT_NETFILTER
+ , RRD_TYPE_NET_STAT_CONNTRACK "_expect"
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_EXP_CREATE]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_EXP_CREATE]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_EXP_DELETE]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_EXP_DELETE]
+ );
+ printf(
+ "SET %s = %lld\n"
+ , nfstat_root.attr2name[CTA_STATS_EXP_NEW]
+ , (collected_number) nfstat_root.metrics[CTA_STATS_EXP_NEW]
+ );
+ printf("END\n");
}
#endif // HAVE_LINUX_NETFILTER_NFNETLINK_CONNTRACK_H
@@ -497,8 +548,8 @@ struct nfacct_data {
uint64_t pkts;
uint64_t bytes;
- RRDDIM *rd_bytes;
- RRDDIM *rd_packets;
+ int packets_dimension_added;
+ int bytes_dimension_added;
int updated;
@@ -579,24 +630,6 @@ static int nfacct_init(int update_every) {
return 0;
}
-static void nfacct_cleanup() {
- if(nfacct_root.mnl) {
- mnl_socket_close(nfacct_root.mnl);
- nfacct_root.mnl = NULL;
- }
-
- if(nfacct_root.nfacct_buffer) {
- nfacct_free(nfacct_root.nfacct_buffer);
- nfacct_root.nfacct_buffer = NULL;
- }
-
- freez(nfacct_root.buf);
- nfacct_root.buf = NULL;
- nfacct_root.buf_size = 0;
-
- // TODO: cleanup the metrics linked list
-}
-
static int nfacct_callback(const struct nlmsghdr *nlh, void *data) {
(void)data;
@@ -661,162 +694,216 @@ static int nfacct_collect() {
}
static void nfacct_send_metrics() {
- static RRDSET *st_bytes = NULL, *st_packets = NULL;
+ static int bytes_chart_generated = 0, packets_chart_generated = 0;
if(!nfacct_root.nfacct_metrics) return;