Merge pull request #3019 from sradco/master
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Tue, 7 May 2019 08:04:33 +0000 (10:04 +0200)
committerGitHub <noreply@github.com>
Tue, 7 May 2019 08:04:33 +0000 (10:04 +0200)
Add write_syslog output plugin

1  2 
Makefile.am
configure.ac
src/collectd.conf.in
src/collectd.conf.pod

diff --combined Makefile.am
@@@ -159,8 -159,7 +159,8 @@@ check_PROGRAMS = 
        test_utils_time \
        test_utils_vl_lookup \
        test_libcollectd_network_parse \
 -      test_utils_config_cores
 +      test_utils_config_cores \
 +      test_utils_proc_pids
  
  
  TESTS = $(check_PROGRAMS)
@@@ -377,11 -376,6 +377,11 @@@ test_utils_config_cores_SOURCES = 
        src/testing.h
  test_utils_config_cores_LDADD = libplugin_mock.la
  
 +test_utils_proc_pids_SOURCES = \
 +      src/utils/proc_pids/proc_pids_test.c \
 +      src/testing.h
 +test_utils_proc_pids_LDADD = libplugin_mock.la
 +
  libavltree_la_SOURCES = \
        src/utils/avltree/avltree.c \
        src/utils/avltree/avltree.h
@@@ -1071,25 -1065,11 +1071,25 @@@ if BUILD_PLUGIN_INTEL_RD
  pkglib_LTLIBRARIES += intel_rdt.la
  intel_rdt_la_SOURCES = \
        src/intel_rdt.c \
 +      src/utils/proc_pids/proc_pids.c \
 +      src/utils/proc_pids/proc_pids.h \
        src/utils/config_cores/config_cores.h \
        src/utils/config_cores/config_cores.c
  intel_rdt_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBPQOS_CPPFLAGS)
  intel_rdt_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBPQOS_LDFLAGS)
  intel_rdt_la_LIBADD = $(BUILD_WITH_LIBPQOS_LIBS)
 +
 +test_plugin_intel_rdt_SOURCES = \
 +      src/intel_rdt_test.c \
 +      src/utils/config_cores/config_cores.c \
 +      src/utils/proc_pids/proc_pids.c \
 +      src/daemon/configfile.c \
 +      src/daemon/types_list.c
 +test_plugin_intel_rdt_CPPFLAGS = $(AM_CPPFLAGS)
 +test_plugin_intel_rdt_LDFLAGS = $(PLUGIN_LDFLAGS)
 +test_plugin_intel_rdt_LDADD = liboconfig.la libplugin_mock.la
 +check_PROGRAMS += test_plugin_intel_rdt
 +TESTS += test_plugin_intel_rdt
  endif
  
  if BUILD_PLUGIN_INTERFACE
@@@ -1959,13 -1939,12 +1959,13 @@@ virt_la_CFLAGS = $(AM_CFLAGS) 
  virt_la_LDFLAGS = $(PLUGIN_LDFLAGS)
  virt_la_LIBADD = libignorelist.la $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
  
 -test_plugin_virt_SOURCES = src/virt_test.c
 +test_plugin_virt_SOURCES = src/virt_test.c src/daemon/configfile.c \
 +      src/daemon/types_list.c
  test_plugin_virt_CPPFLAGS = $(AM_CPPFLAGS) \
        $(BUILD_WITH_LIBVIRT_CPPFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
  test_plugin_virt_LDFLAGS = $(PLUGIN_LDFLAGS) \
        $(BUILD_WITH_LIBVIRT_LDFLAGS) $(BUILD_WITH_LIBXML2_LDFLAGS)
 -test_plugin_virt_LDADD = libplugin_mock.la \
 +test_plugin_virt_LDADD = liboconfig.la libplugin_mock.la \
        $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
  check_PROGRAMS += test_plugin_virt
  TESTS += test_plugin_virt
@@@ -2078,6 -2057,12 +2078,12 @@@ write_stackdriver_la_LIBADD = libformat
                       $(BUILD_WITH_LIBCURL_LIBS)
  endif
  
+ if BUILD_PLUGIN_WRITE_SYSLOG
+ pkglib_LTLIBRARIES += write_syslog.la
+ write_syslog_la_SOURCES = src/write_syslog.c
+ write_syslog_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+ endif
  if BUILD_PLUGIN_WRITE_TSDB
  pkglib_LTLIBRARIES += write_tsdb.la
  write_tsdb_la_SOURCES = src/write_tsdb.c
diff --combined configure.ac
  # FreeBSD
  
  if test "x$ac_system" = "xFreeBSD"; then
 +  plugin_cpufreq="yes"
    plugin_disk="yes"
    plugin_zfs_arc="yes"
  fi
@@@ -6932,6 -6931,7 +6932,7 @@@ AC_PLUGIN([write_redis],         [$with
  AC_PLUGIN([write_riemann],       [$with_libriemann_client],   [Riemann output plugin])
  AC_PLUGIN([write_sensu],         [yes],                       [Sensu output plugin])
  AC_PLUGIN([write_stackdriver],   [$plugin_write_stackdriver], [Google Stackdriver Monitoring output plugin])
+ AC_PLUGIN([write_syslog],        [yes],                       [Syslog output plugin])
  AC_PLUGIN([write_tsdb],          [yes],                       [TSDB output plugin])
  AC_PLUGIN([xencpu],              [$plugin_xencpu],            [Xen Host CPU usage])
  AC_PLUGIN([xmms],                [$with_libxmms],             [XMMS statistics])
@@@ -7357,6 -7357,7 +7358,7 @@@ AC_MSG_RESULT([    write_redis . . . . 
  AC_MSG_RESULT([    write_riemann . . . . $enable_write_riemann])
  AC_MSG_RESULT([    write_sensu . . . . . $enable_write_sensu])
  AC_MSG_RESULT([    write_stackdriver . . $enable_write_stackdriver])
+ AC_MSG_RESULT([    write_syslog . .  . . $enable_write_syslog])
  AC_MSG_RESULT([    write_tsdb  . . . . . $enable_write_tsdb])
  AC_MSG_RESULT([    xencpu  . . . . . . . $enable_xencpu])
  AC_MSG_RESULT([    xmms  . . . . . . . . $enable_xmms])
diff --combined src/collectd.conf.in
  #@BUILD_PLUGIN_WRITE_RIEMANN_TRUE@LoadPlugin write_riemann
  #@BUILD_PLUGIN_WRITE_SENSU_TRUE@LoadPlugin write_sensu
  #@BUILD_PLUGIN_WRITE_STACKDRIVER_TRUE@LoadPlugin write_stackdriver
+ #@BUILD_PLUGIN_WRITE_SYSLOG_TRUE@LoadPlugin write_syslog
  #@BUILD_PLUGIN_WRITE_TSDB_TRUE@LoadPlugin write_tsdb
  #@BUILD_PLUGIN_XENCPU_TRUE@LoadPlugin xencpu
  #@BUILD_PLUGIN_XMMS_TRUE@LoadPlugin xmms
  
  #<Plugin "intel_rdt">
  #  Cores "0-2"
 +#  Processes "sshd"
  #</Plugin>
  
  #<Plugin interface>
  #     InterfaceFormat name
  #     PluginInstanceFormat name
  #     Instances 1
 -#     ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpupin"
 +#     ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpupin disk_physical disk_allocation disk_capacity"
  #     PersistentNotification false
  #</Plugin>
  
  #    SeparateInstances false
  #    PreserveSeparator false
  #    DropDuplicateFields false
 +#    ReverseHost false
  #  </Node>
  #</Plugin>
  
  #  Url "https://monitoring.googleapis.com/v3"
  #</Plugin>
  
+ #<Plugin write_syslog>
+ #     <Node>
+ #             Host "localhost"
+ #             Port "44514"
+ #             Prefix "collectd"
+ #             MessageFormat "human"
+ #             HostTags ""
+ #             StoreRates false
+ #             AlwaysAppendDS false
+ #     </Node>
+ #</Plugin>
  #<Plugin write_tsdb>
  #     <Node>
  #             Host "localhost"
diff --combined src/collectd.conf.pod
@@@ -1656,24 -1656,15 +1656,24 @@@ Defaults to B<true>
  
  =head2 Plugin C<cpufreq>
  
 -This plugin doesn't have any options. It reads
 +This plugin is available on Linux and FreeBSD only.  It doesn't have any
 +options.  On Linux it reads
  F</sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq> (for the first CPU
  installed) to get the current CPU frequency. If this file does not exist make
  sure B<cpufreqd> (L<http://cpufreqd.sourceforge.net/>) or a similar tool is
  installed and an "cpu governor" (that's a kernel module) is loaded.
  
 -If the system has the I<cpufreq-stats> kernel module loaded, this plugin reports
 -the rate of p-state (cpu frequency) transitions and the percentage of time spent
 -in each p-state.
 +On Linux, if the system has the I<cpufreq-stats> kernel module loaded, this
 +plugin reports the rate of p-state (cpu frequency) transitions and the
 +percentage of time spent in each p-state.
 +
 +On FreeBSD it does a sysctl dev.cpu.0.freq and submits this as instance 0.
 +At this time FreeBSD only has one frequency setting for all cores.
 +See the BUGS section in the FreeBSD man page for cpufreq(4) for more details.
 +
 +On FreeBSD the plugin checks the success of sysctl dev.cpu.0.freq and
 +unregisters the plugin when this fails.  A message will be logged to indicate
 +this.
  
  =head2 Plugin C<cpusleep>
  
@@@ -3507,7 -3498,6 +3507,7 @@@ B<Synopsis:
  
    <Plugin "intel_rdt">
      Cores "0-2" "3,4,6" "8-10,15"
 +    Processes "sshd,qemu-system-x86" "bash"
    </Plugin>
  
  B<Options:>
@@@ -3523,10 -3513,11 +3523,10 @@@ recommended to set interval higher tha
  
  =item B<Cores> I<cores groups>
  
 -All events are reported on a per core basis. Monitoring of the events can be
 -configured for group of cores (aggregated statistics). This field defines groups
 -of cores on which to monitor supported events. The field is represented as list
 -of strings with core group values. Each string represents a list of cores in a
 -group. Allowed formats are:
 +Monitoring of the events can be configured for group of cores
 +(aggregated statistics). This field defines groups of cores on which to monitor
 +supported events. The field is represented as list of strings with core group
 +values. Each string represents a list of cores in a group. Allowed formats are:
      0,1,2,3
      0-10,20-18
      1,3,5-8,10,0x10-12
  If an empty string is provided as value for this field default cores
  configuration is applied - a separate group is created for each core.
  
 +=item B<Processes> I<process names groups>
 +
 +Monitoring of the events can be configured for group of processes
 +(aggregated statistics). This field defines groups of processes on which to
 +monitor supported events. The field is represented as list of strings with
 +process names group values. Each string represents a list of processes in a
 +group. Allowed format is:
 +    sshd,bash,qemu
 +
  =back
  
  B<Note:> By default global interval is used to retrieve statistics on monitored
@@@ -4462,12 -4444,6 +4462,12 @@@ For Modbus/RTU, specifies the path to t
  For Modbus/RTU, specifies the baud rate of the serial device.
  Note, connections currently support only 8/N/1.
  
 +=item B<UARTType> I<UARTType>
 +
 +For Modbus/RTU, specifies the type of the serial device.
 +RS232, RS422 and RS485 are supported. Defaults to RS232.
 +Available only on Linux systems with libmodbus>=2.9.4.
 +
  =item B<Interval> I<Interval>
  
  Sets the interval (in seconds) in which the values will be collected from this
@@@ -9276,51 -9252,13 +9276,51 @@@ surrounded by I</.../> and collectd wa
  
  The default is to collect statistics for all domains and all their devices.
  
 -Example:
 +B<Note:> B<BlockDevice> and B<InterfaceDevice> options are related to
 +corresponding B<*Format> options. Specifically, B<BlockDevice> filtering depends
 +on B<BlockDeviceFormat> setting - if user wants to filter block devices by
 +'target' name then B<BlockDeviceFormat> option has to be set to 'target' and
 +B<BlockDevice> option must be set to a valid block device target
 +name("/:hdb/"). Mixing formats and filter values from different worlds (i.e.,
 +using 'target' name as B<BlockDevice> value with B<BlockDeviceFormat> set to
 +'source') may lead to unexpected results (all devices filtered out or all
 +visible, depending on the value of B<IgnoreSelected> option).
 +Similarly, option B<InterfaceDevice> is related to B<InterfaceFormat> setting
 +(i.e., when user wants to use MAC address as a filter then B<InterfaceFormat>
 +has to be set to 'address' - using wrong type here may filter out all of the
 +interfaces).
 +
 +B<Example 1:>
 +
 +Ignore all I<hdb> devices on any domain, but other block devices (eg. I<hda>)
 +will be collected:
  
   BlockDevice "/:hdb/"
   IgnoreSelected "true"
 + BlockDeviceFormat "target"
  
 -Ignore all I<hdb> devices on any domain, but other block devices (eg. I<hda>)
 -will be collected.
 +B<Example 2:>
 +
 +Collect metrics only for block device on 'baremetal0' domain when its
 +'source' matches given path:
 +
 + BlockDevice "baremetal0:/var/lib/libvirt/images/baremetal0.qcow2"
 + BlockDeviceFormat source
 +
 +As you can see it is possible to filter devices/interfaces using
 +various formats - for block devices 'target' or 'source' name can be
 +used.  Interfaces can be filtered using 'name', 'address' or 'number'.
 +
 +B<Example 3:>
 +
 +Collect metrics only for domains 'baremetal0' and 'baremetal1' and
 +ignore any other domain:
 +
 + Domain "baremetal0"
 + Domain "baremetal1"
 +
 +It is possible to filter multiple block devices/domains/interfaces by
 +adding multiple filtering entries in separate lines.
  
  =item B<BlockDeviceFormat> B<target>|B<source>
  
@@@ -9351,11 -9289,6 +9351,11 @@@ to C<sda>
  Setting C<BlockDeviceFormat source> will cause the I<type instance> to be set
  to C<var_lib_libvirt_images_image1.qcow2>.
  
 +B<Note:> this option determines also what field will be used for
 +filtering over block devices (filter value in B<BlockDevice>
 +will be applied to target or source). More info about filtering
 +block devices can be found in the description of B<BlockDevice>.
 +
  =item B<BlockDeviceFormatBasename> B<false>|B<true>
  
  The B<BlockDeviceFormatBasename> controls whether the full path or the
@@@ -9406,11 -9339,6 +9406,11 @@@ interface path might change between reb
  
  B<number> means use the interface's number in guest.
  
 +B<Note:> this option determines also what field will be used for
 +filtering over interface device (filter value in B<InterfaceDevice>
 +will be applied to name, address or number).  More info about filtering
 +interfaces can be found in the description of B<InterfaceDevice>.
 +
  =item B<PluginInstanceFormat> B<name|uuid|metadata|none>
  
  When the virt plugin logs data, it sets the plugin_instance of the collected
@@@ -9493,18 -9421,6 +9493,18 @@@ B<Note>: I<perf> metrics can't be colle
  
  =item B<vcpupin>: report pinning of domain VCPUs to host physical CPUs.
  
 +=item B<disk_physical>: report 'disk_physical' statistic for disk device.
 +B<Note>: This statistic is only reported for disk devices with 'source'
 +property available.
 +
 +=item B<disk_allocation>: report 'disk_allocation' statistic for disk device.
 +B<Note>: This statistic is only reported for disk devices with 'source'
 +property available.
 +
 +=item B<disk_capacity>: report 'disk_capacity' statistic for disk device.
 +B<Note>: This statistic is only reported for disk devices with 'source'
 +property available.
 +
  =back
  
  =item B<PersistentNotification> B<true>|B<false>
@@@ -9594,7 -9510,6 +9594,7 @@@ Synopsis
       LogSendErrors true
       Prefix "collectd"
       UseTags false
 +     ReverseHost false
     </Node>
   </Plugin>
  
@@@ -9706,30 -9621,6 +9706,30 @@@ are not used
  
  Default value: B<false>.
  
 +=item B<ReverseHost> B<false>|B<true>
 +
 +If set to B<true>, the (dot separated) parts of the B<host> field of the
 +I<value list> will be rewritten in reverse order. The rewrite happens I<before>
 +special characters are replaced with the B<EscapeCharacter>.
 +
 +This option might be convenient if the metrics are presented with Graphite in a
 +DNS like tree structure (probably without replacing dots in hostnames).
 +
 +Example:
 + Hostname "node3.cluster1.example.com"
 + LoadPlugin "cpu"
 + LoadPlugin "write_graphite"
 + <Plugin "write_graphite">
 +  <Node "graphite.example.com">
 +   EscapeCharacter "."
 +   ReverseHost true
 +  </Node>
 + </Plugin>
 +
 + result on the wire: com.example.cluster1.node3.cpu-0.cpu-idle 99.900993 1543010932
 +
 +Default value: B<false>.
 +
  =back
  
  =head2 Plugin C<write_log>
@@@ -10705,6 -10596,141 +10705,141 @@@ C<https://monitoring.googleapis.com/v3>
  
  =back
  
+ =head2 Plugin C<write_syslog>
+ The C<write_syslog> plugin writes data in I<syslog> format log messages.
+ It implements the basic syslog protocol, RFC 5424, extends it with
+ content-based filtering, rich filtering capabilities,
+ flexible configuration options and adds features such as using TCP for transport.
+ The plugin can connect to a I<Syslog> daemon, like syslog-ng and rsyslog, that will
+ ingest metrics, transform and ship them to the specified output.
+ The plugin uses I<TCP> over the "line based" protocol with a default port 44514.
+ The data will be sent in blocks of at most 1428 bytes to minimize the number of
+ network packets.
+ Synopsis:
+  <Plugin write_syslog>
+    ResolveInterval 60
+    ResolveJitter 60
+    <Node "example">
+      Host "syslog-1.my.domain"
+      Port "44514"
+      Prefix "collectd"
+      MessageFormat "human"
+      HostTags ""
+    </Node>
+  </Plugin>
+ The configuration consists of one or more E<lt>B<Node>E<nbsp>I<Name>E<gt>
+ blocks and global directives.
+ Global directives are:
+ =over 4
+ =item B<ResolveInterval> I<seconds>
+ =item B<ResolveJitter> I<seconds>
+ When I<collectd> connects to a syslog node, it will request the hostname from
+ DNS. This can become a problem if the syslog node is unavailable or badly
+ configured because collectd will request DNS in order to reconnect for every
+ metric, which can flood your DNS. So you can cache the last value for
+ I<ResolveInterval> seconds.
+ Defaults to the I<Interval> of the I<write_syslog plugin>, e.g. 10E<nbsp>seconds.
+ You can also define a jitter, a random interval to wait in addition to
+ I<ResolveInterval>. This prevents all your collectd servers to resolve the
+ hostname at the same time when the connection fails.
+ Defaults to the I<Interval> of the I<write_syslog plugin>, e.g. 10E<nbsp>seconds.
+ B<Note:> If the DNS resolution has already been successful when the socket
+ closes, the plugin will try to reconnect immediately with the cached
+ information. DNS is queried only when the socket is closed for a longer than
+ I<ResolveInterval> + I<ResolveJitter> seconds.
+ =back
+ Inside the B<Node> blocks, the following options are recognized:
+ =over 4
+ =item B<Host> I<Address>
+ Hostname or address to connect to. Defaults to C<localhost>.
+ =item B<Port> I<Service>
+ Service name or port number to connect to. Defaults to C<44514>.
+ =item B<HostTags> I<String>
+ When set, I<HostTags> is added to the end of the metric.
+ It is intended to be used for adding additional metadata to tag the metric with.
+ Dots and whitespace are I<not> escaped in this string.
+ Examples:
+ When MessageFormat is set to "human".
+   ["prefix1" "example1"="example1_v"]["prefix2" "example2"="example2_v"]"
+ When MessageFormat is set to "JSON", text should be in JSON format.
+ Escaping the quotation marks is required.
+   HostTags "\"prefix1\": {\"example1\":\"example1_v\",\"example2\":\"example2_v\"}"
+ =item B<MessageFormat> I<String>
+ I<MessageFormat> selects the format in which messages are sent to the
+ syslog deamon, human or JSON. Defaults to human.
+ Syslog message format:
+ <priority>VERSION ISOTIMESTAMP HOSTNAME APPLICATION PID MESSAGEID STRUCTURED-DATA MSG
+ The difference between the message formats are in the STRUCTURED-DATA and MSG parts.
+ Human format:
+   <166>1 ISOTIMESTAMP HOSTNAME collectd PID MESSAGEID
+   ["collectd" "value": "v1" "plugin"="plugin_v" "plugin_instance"="plugin_instance_v"
+   "type_instance"="type_instance_v" "type"="type_v" "ds_name"="ds_name_v" "interval"="interval_v" ]
+   "host_tag_example"="host_tag_example_v" plugin_v.type_v.ds_name_v="v1"
+ JSON format:
+   <166>1 ISOTIMESTAMP HOSTNAME collectd PID MESSAGEID STRUCTURED-DATA
+   {
+     "collectd": {
+     "time": time_as_epoch, "interval": interval_v, "plugin": "plugin_v",
+     "plugin_instance": "plugin_instance_v", "type":"type_v",
+     "type_instance": "type_instance_v", "plugin_v": {"type_v": v1}
+     } , "host":"host_v", "host_tag_example": "host_tag_example_v"
+   }
+ =item B<StoreRates> B<false>|B<true>
+ If set to B<true>, convert counter values to rates. If set to B<false>
+ (the default) counter values are stored as is, as an increasing
+ integer number.
+ =item B<AlwaysAppendDS> B<false>|B<true>
+ If set to B<true>, append the name of the I<Data Source> (DS) to the "metric"
+ identifier. If set to B<false> (the default), this is only done when there is
+ more than one DS.
+ =item B<Prefix> I<String>
+ When set, I<Prefix> is added to all metrics names as a prefix. It is intended in
+ case you want to be able to define the source of the specific metric. Dots and
+ whitespace are I<not> escaped in this string.
+ =back
  =head2 Plugin C<xencpu>
  
  This plugin collects metrics of hardware CPU load for machine running Xen