Merge pull request #10682 from hnyman/collectd-backport

[19.07] Collectd: backport changes from master to 19.07
This commit is contained in:
Hannu Nyman 2019-12-04 19:52:16 +02:00 committed by GitHub
commit 3507167719
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 296 additions and 25 deletions

View file

@ -8,13 +8,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=collectd
PKG_VERSION:=5.9.0
PKG_RELEASE:=4
PKG_VERSION:=5.10.0
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://collectd.org/files/ \
https://github.com/collectd/collectd/releases/download/collectd-$(PKG_VERSION)
PKG_HASH:=7b220f8898a061f6e7f29a8c16697d1a198277f813da69474a67911097c0626b
PKG_HASH:=a03359f563023e744c2dc743008a00a848f4cd506e072621d86b6d8313c0375b
PKG_FIXUP:=autoreconf
PKG_REMOVE_FILES:=aclocal.m4 libltdl/aclocal.m4
@ -82,6 +82,7 @@ COLLECTD_PLUGINS_DISABLED:= \
perl \
pf \
pinba \
procevent \
python \
redis \
rrdcached \
@ -92,6 +93,7 @@ COLLECTD_PLUGINS_DISABLED:= \
statsd \
swap \
synproxy \
sysevent \
tape \
tokyotyrant \
turbostat \
@ -177,6 +179,7 @@ COLLECTD_PLUGINS_SELECTED:= \
teamspeak2 \
ted \
thermal \
threshold \
unixsock \
uptime \
users \
@ -419,6 +422,7 @@ $(eval $(call BuildPlugin,teamspeak2,TeamSpeak2 input,teamspeak2,))
$(eval $(call BuildPlugin,ted,The Energy Detective input,ted,))
$(eval $(call BuildPlugin,tcpconns,TCP connection tracking input,tcpconns,))
$(eval $(call BuildPlugin,thermal,system temperatures input,thermal,))
$(eval $(call BuildPlugin,threshold,Notifications and thresholds,threshold,))
$(eval $(call BuildPlugin,unixsock,unix socket output,unixsock,))
$(eval $(call BuildPlugin,uptime,uptime status input,uptime,))
$(eval $(call BuildPlugin,users,user logged in status input,users,))

View file

@ -1,8 +1,6 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2016 OpenWrt.org
. "/usr/share/libubox/jshn.sh"
START=80
STOP=10
@ -46,6 +44,129 @@ process_exec_sections() {
fi
}
process_curl() {
printf "<Plugin curl>\n" >> "$COLLECTD_CONF"
config_foreach process_curl_page curl_page
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
process_curl_page() {
local cfg="$1"
local name url
config_get name "$cfg" name
[ -z "$name" ] && {
$LOG notice "No name option in config $cfg defined"
return 0
}
config_get url "$cfg" url
[ -z "$url" ] && {
$LOG notice "No URL option in config $cfg defined"
return 0
}
printf "\\t<Page \"%s\">\n" "${name}" >> "$COLLECTD_CONF"
printf "\\t\\tURL \"%s\"\n" "${url}" >> "$COLLECTD_CONF"
printf "\\t\\tMeasureResponseTime true\n" >> "$COLLECTD_CONF"
printf "\\t</Page>\n" >> "$COLLECTD_CONF"
}
process_network() {
local cfg="$1"
local TimeToLive Forward CacheFlush
printf "<Plugin network>\n" >> "$COLLECTD_CONF"
config_foreach process_network_sections network_listen "listen"
config_foreach process_network_sections network_server "server"
config_get TimeToLive "$cfg" TimeToLive
[ -z "$TimeToLive" ] || {
printf "\\tTimeToLive %s\n" "${TimeToLive}" >> "$COLLECTD_CONF"
}
config_get CacheFlush "$cfg" CacheFlush
[ -z "$CacheFlush" ] || {
printf "\\tCacheFlush %s\n" "${CacheFlush}" >> "$COLLECTD_CONF"
}
config_get_bool Forward "$cfg" Forward
if [ "$value" = "0" ]; then
printf "\\tForward false\n" >> "$COLLECTD_CONF"
else
printf "\\tForward true\n" >> "$COLLECTD_CONF"
fi
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
process_network_sections() {
local cfg="$1"
local section="$2"
local host port output
config_get host "$cfg" host
[ -z "$host" ] && {
$LOG notice "No host option in config $cfg defined"
return 0
}
if [ "$section" = "server" ]; then
output="Server \"$host\""
else
output="Listen \"$host\""
fi
config_get port "$cfg" port
if [ -z "$port" ]; then
printf "\\t%s\n" "${output}" >> "$COLLECTD_CONF"
else
printf "\\t%s \"%s\"\n" "${output}" "${port}" >> "$COLLECTD_CONF"
fi
}
process_iptables() {
local cfg="$1"
printf "<Plugin iptables>\n" >> "$COLLECTD_CONF"
config_foreach process_iptables_sections iptables_match
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
process_iptables_sections() {
local cfg="$1"
local table chain
config_get table "$cfg" table
[ -z "$table" ] && {
$LOG notice "No table option in config $cfg defined"
return 0
}
config_get chain "$cfg" chain
[ -z "$chain" ] && {
$LOG notice "No chain option in config $cfg defined"
return 0
}
config_get index "$cfg" index
[ -z "$index" ] && {
$LOG notice "No index option in config $cfg defined"
return 0
}
config_get name "$cfg" name
if [ -z "$name" ]; then
printf "\\tChain %s %s %s\n" "${table}" "${chain}" "${index}" >> "$COLLECTD_CONF"
else
printf "\\tChain %s %s %s \"%s\"\n" "${table}" "${chain}" "${index}" "${name}">> "$COLLECTD_CONF"
fi
}
CONFIG_LIST=""
add_list_option() {
local value="$1"
@ -62,6 +183,7 @@ process_generic() {
local config=""
. /usr/share/libubox/jshn.sh
json_init
json_load_file "$json"
@ -140,6 +262,18 @@ process_plugins() {
CONFIG_STRING=""
process_exec
;;
curl)
CONFIG_STRING=""
process_curl
;;
network)
CONFIG_STRING=""
process_network "$cfg"
;;
iptables)
CONFIG_STRING=""
process_iptables
;;
*)
CONFIG_STRING=""
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
@ -190,7 +324,7 @@ process_config() {
config_get ReadThreads globals ReadThreads 2
printf "ReadThreads \"%s\"\n" "$ReadThreads" >> "$COLLECTD_CONF"
config_get Hostname globals Hostname "$(hostname)"
config_get Hostname globals Hostname "$(uname -n)"
printf "Hostname \"%s\"\n" "$Hostname" >> "$COLLECTD_CONF"
printf "\n" >> "$COLLECTD_CONF"
@ -199,17 +333,24 @@ process_config() {
config_foreach process_plugins plugin
}
service_triggers()
{
procd_add_reload_trigger "collectd"
}
start_service() {
process_config
procd_open_instance
procd_set_param command /usr/sbin/collectd
procd_append_param command -C "$COLLECTD_CONF"
procd_append_param command -f # don't daemonize, procd will handle that for us
procd_append_param command -f # don't daemonize
procd_set_param nice "$NICEPRIO"
process_config
# set auto respawn behavior
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
reload_service() {
restart "$@"
}

View file

@ -8,6 +8,11 @@ config globals 'globals'
# option Interval '30'
# option ReadThreads '2'
#config plugin 'apcups'
# option enable '0'
# option Host 'localhost'
# option Port '3551'
#config plugin 'conntrack'
# option enable '0'
@ -25,6 +30,13 @@ config globals 'globals'
# option StoreRates '0'
# option DataDir '/tmp'
#config plugin 'curl'
# option enable '0'
#config curl_page
# option name 'test'
# option url 'http://finance.google.com/finance?q=NYSE%3AAMD%22'
#config plugin 'df'
# option enable '0'
# list Device '/dev/mtdblock/4'
@ -69,6 +81,15 @@ config globals 'globals'
# list Interface 'br-lan'
# option IgnoreSelected '0'
#config plugin 'iptables'
# option enable '1'
#config iptables_match
# option table 'nat'
# option chain 'zone_wan_postrouting'
# option index '1'
# option name 'WLAN-Clients traffic'
#config plugin 'irq'
# option enable '0'
# list Irq '2'
@ -96,6 +117,20 @@ config globals 'globals'
# list VerboseInterface 'br-lan'
# list QDisc 'br-lan'
#config plugin 'network'
# option enable '1'
# option TimeToLive '128'
# option Forward '1'
# option CacheFlush '86400'
#config network_listen
# option host '0.0.0.0'
# option port '25826'
#config network_server
# option host '1.1.1.1'
# option port '25826'
#config plugin 'nut'
# option enable '0'
# option UPS 'myupsname'

View file

@ -0,0 +1,6 @@
{
"string": [
"Host",
"Port"
]
}

View file

@ -1,2 +1,7 @@
{
"bool": [
"ValuesPercentage",
"ReportByCpu",
"ReportByState"
]
}

View file

@ -0,0 +1,2 @@
{
}

View file

@ -0,0 +1,2 @@
{
}

View file

@ -0,0 +1,9 @@
{
"string": [
"LogLevel",
"File"
],
"bool": [
"Timestamp"
]
}

View file

@ -1,2 +1,6 @@
{
"bool": [
"ValuesPercentage",
"ValuesAbsolute"
]
}

View file

@ -0,0 +1,2 @@
{
}

View file

@ -1,6 +1,6 @@
--- a/src/daemon/plugin.c
+++ b/src/daemon/plugin.c
@@ -1085,7 +1085,7 @@ static int plugin_insert_read(read_func_
@@ -1092,7 +1092,7 @@ static int plugin_insert_read(read_func_
int status;
llentry_t *le;

View file

@ -0,0 +1,61 @@
Adjust the reaction to a polling interval timestamp that references
to a past time.
Past timestamps can happen when ntpd adjusts router's time after network
connectivity is obtained after boot. Collectd shows warnings for each plugin
as it tries to enter new values with the same timestamp as the previous one.
This patch adjusts the next polling time to be now+2 seconds for the main
loop and for the plugin-specific read loops. That avoids the warnings, but
does not overreact in case there are shorter polling intervals or the time
gets adjusted for other reasons.
Additionally some debug statements are added, but they are visible only
when --enable-debug configure option is used in Makefile.
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
@@ -274,20 +274,23 @@ static int do_loop(void) {
update_kstat();
#endif
+ DEBUG("do_loop before plugin_read_all: now = %.3f", CDTIME_T_TO_DOUBLE(cdtime()));
/* Issue all plugins */
plugin_read_all();
cdtime_t now = cdtime();
+ DEBUG("do_loop after plugin_read_all: now = %.3f, wait_until= %.3f", CDTIME_T_TO_DOUBLE(now), CDTIME_T_TO_DOUBLE(wait_until));
if (now >= wait_until) {
- WARNING("Not sleeping because the next interval is "
+ WARNING("Sleeping only 2s because the next interval is "
"%.3f seconds in the past!",
CDTIME_T_TO_DOUBLE(now - wait_until));
- wait_until = now + interval;
- continue;
+ wait_until = now + DOUBLE_TO_CDTIME_T(2);
+ DEBUG("do_loop: wait_until adjusted to now+2 = %.3f", CDTIME_T_TO_DOUBLE(wait_until));
}
struct timespec ts_wait = CDTIME_T_TO_TIMESPEC(wait_until - now);
wait_until = wait_until + interval;
+ DEBUG("do_loop ends: wait_until set to %.3f", CDTIME_T_TO_DOUBLE(wait_until));
while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) {
if (errno != EINTR) {
--- a/src/daemon/plugin.c
+++ b/src/daemon/plugin.c
@@ -585,10 +585,11 @@ static void *plugin_read_thread(void __a
/* Check, if `rf_next_read' is in the past. */
if (rf->rf_next_read < now) {
- /* `rf_next_read' is in the past. Insert `now'
+ /* `rf_next_read' is in the past. Insert `now'+2s
* so this value doesn't trail off into the
* past too much. */
- rf->rf_next_read = now;
+ rf->rf_next_read = now + DOUBLE_TO_CDTIME_T(2);
+ DEBUG("plugin_read_thread: Next read is in the past. Adjusted to now+2s");
}
DEBUG("plugin_read_thread: Next read of the `%s' plugin at %.3f.",

View file

@ -18,7 +18,7 @@ Reversed patch to be applied:
--- a/configure.ac
+++ b/configure.ac
@@ -3399,9 +3399,9 @@ if test "x$with_libmodbus" = "xyes"; the
@@ -3389,9 +3389,9 @@ if test "x$with_libmodbus" = "xyes"; the
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"

View file

@ -1,6 +1,6 @@
--- a/configure.ac
+++ b/configure.ac
@@ -531,11 +531,7 @@ if test "x$ac_system" = "xLinux"; then
@@ -532,11 +532,7 @@ if test "x$ac_system" = "xLinux"; then
[have_cpuid_h="no (cpuid.h not found)"]
)

View file

@ -1,6 +1,6 @@
--- a/configure.ac
+++ b/configure.ac
@@ -721,6 +721,11 @@ AC_CACHE_CHECK([whether clock_boottime a
@@ -712,6 +712,11 @@ AC_CACHE_CHECK([whether clock_boottime a
]
)
@ -12,7 +12,7 @@
#
# Checks for typedefs, structures, and compiler characteristics.
@@ -6392,6 +6397,7 @@ plugin_ipc="no"
@@ -6397,6 +6402,7 @@ plugin_ipc="no"
plugin_ipmi="no"
plugin_ipvs="no"
plugin_irq="no"
@ -20,7 +20,7 @@
plugin_load="no"
plugin_log_logstash="no"
plugin_mcelog="no"
@@ -6826,6 +6832,7 @@ AC_PLUGIN([ipmi], [$plugi
@@ -6841,6 +6847,7 @@ AC_PLUGIN([ipmi], [$plugi
AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
@ -28,7 +28,7 @@
AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine])
AC_PLUGIN([load], [$plugin_load], [System load])
AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging])
@@ -7193,6 +7200,7 @@ AC_MSG_RESULT([ libyajl . . . . . . .
@@ -7212,6 +7219,7 @@ AC_MSG_RESULT([ libyajl . . . . . . .
AC_MSG_RESULT([ oracle . . . . . . . $with_oracle])
AC_MSG_RESULT([ protobuf-c . . . . . $have_protoc_c])
AC_MSG_RESULT([ protoc 3 . . . . . . $have_protoc3])
@ -36,7 +36,7 @@
AC_MSG_RESULT()
AC_MSG_RESULT([ Features:])
AC_MSG_RESULT([ daemon mode . . . . . $enable_daemon])
@@ -7253,6 +7261,7 @@ AC_MSG_RESULT([ ipmi . . . . . . . .
@@ -7274,6 +7282,7 @@ AC_MSG_RESULT([ ipmi . . . . . . . .
AC_MSG_RESULT([ iptables . . . . . . $enable_iptables])
AC_MSG_RESULT([ ipvs . . . . . . . . $enable_ipvs])
AC_MSG_RESULT([ irq . . . . . . . . . $enable_irq])
@ -46,7 +46,7 @@
AC_MSG_RESULT([ logfile . . . . . . . $enable_logfile])
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
@@ -138,6 +138,7 @@
@@ -140,6 +140,7 @@
#@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables
#@BUILD_PLUGIN_IPVS_TRUE@LoadPlugin ipvs
#@BUILD_PLUGIN_IRQ_TRUE@LoadPlugin irq
@ -54,7 +54,7 @@
#@BUILD_PLUGIN_JAVA_TRUE@LoadPlugin java
@BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
#@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar
@@ -767,6 +768,12 @@
@@ -775,6 +776,12 @@
# IgnoreSelected true
#</Plugin>
@ -69,7 +69,7 @@
# JVMArg "-Djava.class.path=@prefix@/share/collectd/java/collectd-api.jar"
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -3803,6 +3803,27 @@ and all other interrupts are collected.
@@ -3873,6 +3873,27 @@ and all other interrupts are collected.
=back
@ -252,17 +252,17 @@
+}
--- a/src/types.db
+++ b/src/types.db
@@ -240,6 +240,7 @@ voltage_threshold value:GAUGE:U:U,
@@ -240,6 +240,7 @@ snr value:GAUGE:0:U
spam_check value:GAUGE:0:U
spam_score value:GAUGE:U:U
spl value:GAUGE:U:U
+stations value:GAUGE:0:256
swap value:GAUGE:0:1099511627776
swap_io value:DERIVE:0:U
tcp_connections value:GAUGE:0:4294967295
sysevent value:GAUGE:0:1
--- a/Makefile.am
+++ b/Makefile.am
@@ -1149,6 +1149,14 @@ irq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
@@ -1165,6 +1165,14 @@ irq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
irq_la_LIBADD = libignorelist.la
endif