summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@tsaousis.gr>2018-11-10 00:55:30 +0200
committerGitHub <noreply@github.com>2018-11-10 00:55:30 +0200
commitee1b7ef695f8c8d16cb77425841d477b564ee125 (patch)
treeba2665ce95570e92636dfd2c612a3ecf90da0d4b
parent9e820a3b38e490863aff3863e63e471f471e76cc (diff)
fixed max interface speed calculation (#4594)
-rw-r--r--collectors/proc.plugin/proc_net_dev.c63
-rw-r--r--database/rrdcalctemplate.h2
-rw-r--r--health/health.d/net.conf14
-rw-r--r--health/health_config.c2
4 files changed, 63 insertions, 18 deletions
diff --git a/collectors/proc.plugin/proc_net_dev.c b/collectors/proc.plugin/proc_net_dev.c
index 97cbc060a4..7ebc3b8797 100644
--- a/collectors/proc.plugin/proc_net_dev.c
+++ b/collectors/proc.plugin/proc_net_dev.c
@@ -66,7 +66,7 @@ static struct netdev {
kernel_uint_t tcollisions;
kernel_uint_t tcarrier;
kernel_uint_t tcompressed;
- kernel_uint_t speed_max;
+ kernel_uint_t speed;
// charts
RRDSET *st_bandwidth;
@@ -96,6 +96,10 @@ static struct netdev {
RRDDIM *rd_tcarrier;
RRDDIM *rd_tcompressed;
+ usec_t speed_last_collected_usec;
+ char *filename_speed;
+ RRDSETVAR *chart_var_speed;
+
struct netdev *next;
} *netdev_root = NULL, *netdev_last_used = NULL;
@@ -139,7 +143,7 @@ static void netdev_charts_release(struct netdev *d) {
d->rd_tcompressed = NULL;
}
-static void netdev_free_strings(struct netdev *d) {
+static void netdev_free_chart_strings(struct netdev *d) {
freez((void *)d->chart_type_net_bytes);
freez((void *)d->chart_type_net_compressed);
freez((void *)d->chart_type_net_drops);
@@ -161,9 +165,10 @@ static void netdev_free_strings(struct netdev *d) {
static void netdev_free(struct netdev *d) {
netdev_charts_release(d);
- netdev_free_strings(d);
+ netdev_free_chart_strings(d);
freez((void *)d->name);
+ freez((void *)d->filename_speed);
freez((void *)d);
netdev_added--;
}
@@ -265,7 +270,7 @@ static inline void netdev_rename_cgroup(struct netdev *d, struct netdev_rename *
info("CGROUP: renaming network interface '%s' as '%s' under '%s'", r->host_device, r->container_device, r->container_name);
netdev_charts_release(d);
- netdev_free_strings(d);
+ netdev_free_chart_strings(d);
char buffer[RRD_ID_LENGTH_MAX + 1];
@@ -435,8 +440,8 @@ int do_proc_net_dev(int update_every, usec_t dt) {
static procfile *ff = NULL;
static int enable_new_interfaces = -1;
static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
- static char *path_to_sys_devices_virtual_net = NULL;
- static char *path_to_sys_net_speed = NULL;
+ static char *path_to_sys_devices_virtual_net = NULL, *path_to_sys_class_net_speed = NULL;
+ static long long int dt_to_refresh_speed = 0;
if(unlikely(enable_new_interfaces == -1)) {
char filename[FILENAME_MAX + 1];
@@ -444,6 +449,9 @@ int do_proc_net_dev(int update_every, usec_t dt) {
snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/devices/virtual/net/%s");
path_to_sys_devices_virtual_net = config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "path to get virtual interfaces", filename);
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/class/net/%s/speed");
+ path_to_sys_class_net_speed = config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "path to get net device speed", filename);
+
enable_new_interfaces = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "enable new interfaces detected at runtime", CONFIG_BOOLEAN_AUTO);
do_bandwidth = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "bandwidth for all interfaces", CONFIG_BOOLEAN_AUTO);
@@ -455,6 +463,9 @@ int do_proc_net_dev(int update_every, usec_t dt) {
do_events = config_get_boolean_ondemand(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "frames, collisions, carrier counters for all interfaces", CONFIG_BOOLEAN_AUTO);
disabled_list = simple_pattern_create(config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "disable by default interfaces matching", "lo fireqos* *-ifb"), NULL, SIMPLE_PATTERN_EXACT);
+
+ dt_to_refresh_speed = config_get_number(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "refresh interface speed every seconds", 10) * USEC_PER_SEC;
+ if(dt_to_refresh_speed < 0) dt_to_refresh_speed = 0;
}
if(unlikely(!ff)) {
@@ -505,12 +516,10 @@ int do_proc_net_dev(int update_every, usec_t dt) {
else
d->virtual = 0;
- // set nic speed if present
if(likely(!d->virtual)) {
- snprintfz(buffer, FILENAME_MAX, "%s/sys/class/net/%s/speed", netdata_configured_host_prefix, d->name);
- path_to_sys_net_speed = config_get(CONFIG_SECTION_PLUGIN_PROC_NETDEV, "path to get net device speed", buffer);
- int ret = read_single_number_file(path_to_sys_net_speed, (unsigned long long*)&d->speed_max);
- if(ret) error("Cannot read '%s'.", path_to_sys_net_speed);
+ // set the filename to get the interface speed
+ snprintfz(buffer, FILENAME_MAX, path_to_sys_class_net_speed, d->name);
+ d->filename_speed = strdupz(buffer);
}
snprintfz(buffer, FILENAME_MAX, "plugin:proc:/proc/net/dev:%s", d->name);
@@ -597,9 +606,6 @@ int do_proc_net_dev(int update_every, usec_t dt) {
, RRDSET_TYPE_AREA
);
- RRDSETVAR *nic_speed_max = rrdsetvar_custom_chart_variable_create(d->st_bandwidth, "nic_speed_max");
- if(nic_speed_max) rrdsetvar_custom_chart_variable_set(nic_speed_max, (calculated_number)d->speed_max);
-
d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL);
@@ -616,6 +622,35 @@ int do_proc_net_dev(int update_every, usec_t dt) {
rrddim_set_by_pointer(d->st_bandwidth, d->rd_rbytes, (collected_number)d->rbytes);
rrddim_set_by_pointer(d->st_bandwidth, d->rd_tbytes, (collected_number)d->tbytes);
rrdset_done(d->st_bandwidth);
+
+ // update the interface speed
+ if(d->filename_speed) {
+ d->speed_last_collected_usec += dt;
+
+ if(unlikely(d->speed_last_collected_usec >= (usec_t)dt_to_refresh_speed)) {
+
+ if(unlikely(!d->chart_var_speed)) {
+ d->chart_var_speed = rrdsetvar_custom_chart_variable_create(d->st_bandwidth, "nic_speed_max");
+ if(!d->chart_var_speed) {
+ error("Cannot create interface %s chart variable 'nic_speed_max'. Will not update its speed anymore.", d->name);
+ freez(d->filename_speed);
+ d->filename_speed = NULL;
+ }
+ }
+
+ if(d->filename_speed && d->chart_var_speed) {
+ if(read_single_number_file(d->filename_speed, (unsigned long long *) &d->speed)) {
+ error("Cannot refresh interface %s speed by reading '%s'. Will not update its speed anymore.", d->name, d->filename_speed);
+ freez(d->filename_speed);
+ d->filename_speed = NULL;
+ }
+ else {
+ rrdsetvar_custom_chart_variable_set(d->chart_var_speed, (calculated_number) d->speed);
+ d->speed_last_collected_usec = 0;
+ }
+ }
+ }
+ }
}
// --------------------------------------------------------------------
diff --git a/database/rrdcalctemplate.h b/database/rrdcalctemplate.h
index 2235ecaa16..b8996bc14e 100644
--- a/database/rrdcalctemplate.h
+++ b/database/rrdcalctemplate.h
@@ -58,7 +58,7 @@ struct rrdcalctemplate {
struct rrdcalctemplate *next;
};
-#define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
+#define RRDCALCTEMPLATE_HAS_DB_LOOKUP(rt) ((rt)->after)
extern void rrdcalctemplate_link_matching(RRDSET *st);
diff --git a/health/health.d/net.conf b/health/health.d/net.conf
index 489016dd56..ae3c26ec61 100644
--- a/health/health.d/net.conf
+++ b/health/health.d/net.conf
@@ -4,13 +4,23 @@
# -----------------------------------------------------------------------------
# net traffic overflow
+ template: interface_speed
+ on: net.net
+ os: *
+ hosts: *
+ families: *
+ calc: ( $nic_speed_max > 0 ) ? ( $nic_speed_max) : ( nan )
+ units: Mbit
+ every: 10s
+ info: The current speed of the physical network interface
+
template: 1m_received_traffic_overflow
on: net.net
os: linux
hosts: *
families: *
lookup: average -1m unaligned absolute of received
- calc: ($nic_speed_max > 0) ? ($this * 100 / ($nic_speed_max * 1000)) : ( nan )
+ calc: ($interface_speed > 0) ? ($this * 100 / ($interface_speed * 1000)) : ( nan )
units: %
every: 10s
warn: $this > (($status >= $WARNING) ? (80) : (85))
@@ -25,7 +35,7 @@
hosts: *
families: *
lookup: average -1m unaligned absolute of sent
- calc: ($nic_speed_max > 0) ? ($this * 100 / ($nic_speed_max * 1000)) : ( nan )
+ calc: ($interface_speed > 0) ? ($this * 100 / ($interface_speed * 1000)) : ( nan )
units: %
every: 10s
warn: $this > (($status >= $WARNING) ? (80) : (85))
diff --git a/health/health_config.c b/health/health_config.c
index d4af9776fb..d4cf78d973 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -84,7 +84,7 @@ static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCAL
return 0;
}
- if(unlikely(!RRDCALCTEMPLATE_HAS_CALCULATION(rt) && !rt->warning && !rt->critical)) {
+ if(unlikely(!RRDCALCTEMPLATE_HAS_DB_LOOKUP(rt) && !rt->calculation && !rt->warning && !rt->critical)) {
error("Health configuration for template '%s' is useless (no calculation, no warning and no critical evaluation)", rt->name);
return 0;
}