From: Florian Forster Date: Tue, 6 Sep 2016 06:08:01 +0000 (+0200) Subject: Merge branch 'collectd-5.5' into collectd-5.6 X-Git-Tag: collectd-5.6.0~3 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=b847e8ff2fd928813397466a941947c8fce66d66;hp=c2349cf65ba6ddf9517def5ab1f73706f5ce8e01 Merge branch 'collectd-5.5' into collectd-5.6 --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..70f50ad5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: LLVM +IncludeCategories: + - Regex: '"collectd.h"' + - Priority: -1 diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 00000000..49d24b30 --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,16 @@ +* Version of collectd: +* Operating system / distribution: + +## Expected behavior + +(Description of the behavior / output that you expected) + +## Actual behavior + +(Description of the behavior / output that you observed) + +## Steps to reproduce + +* step 1 +* step 2 +* step 3 diff --git a/.gitignore b/.gitignore index 54eaa974..8154d733 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ Makefile config.log config.status libtool -src/.deps src/collectd.conf src/config.h src/libcollectdclient/libcollectdclient.pc @@ -31,7 +30,7 @@ src/stamp-h1 *.lo *.o .libs/ -src/collectd +.deps/ src/collectd-nagios src/collectd-tg src/collectdctl @@ -53,6 +52,9 @@ src/liboconfig/scanner.c # protobuf stuff: src/*.pb-c.[ch] +src/*.grpc.pb.cc +src/*.pb.cc +src/*.pb.h # make dist stuff: /collectd-*.tar.gz @@ -73,19 +75,23 @@ bindings/java/org/collectd/java/*.class # python stuff *.pyc -# tag stuff -src/tags - # backup stuff *~ -# tests stuff -src/tests/.deps/ -src/tests/mock/.deps/ -src/tests/.dirstamp -src/tests/mock/.dirstamp -test*.log -# new daemon repo -src/daemon/.deps/ -src/daemon/.dirstamp +# lint stuff +*.ln + +#ide stuff +.vscode + +# cscope stuff +cscope.* + +# Unit tests +src/daemon/test-suite.log +src/tests/ +src/test-suite.log +test_* + +# src/daemon/... src/daemon/collectd diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..03d9dded --- /dev/null +++ b/.travis.yml @@ -0,0 +1,56 @@ +sudo: required +dist: trusty +compiler: + - gcc + - clang +language: c +before_install: + - sudo apt-get update -qq + - sudo apt-get install -qq --no-install-recommends + iptables-dev + libatasmart-dev + libcap-dev + libcurl4-gnutls-dev + libdbi0-dev + libesmtp-dev + libganglia1-dev + libgcrypt11-dev + libglib2.0-dev + libhiredis-dev + libi2c-dev + libldap2-dev + libltdl-dev + liblvm2-dev + libmemcached-dev + libmnl-dev + libmodbus-dev + libmosquitto0-dev + libmysqlclient-dev + libnotify-dev + libopenipmi-dev + liboping-dev + libow-dev + libpcap-dev + libperl-dev + libpq-dev + libprotobuf-c0-dev + librabbitmq-dev + librdkafka-dev + librrd-dev + libsensors4-dev + libsigrok-dev + libsnmp-dev + libstatgrab-dev + libtokyocabinet-dev + libtokyotyrant-dev + libudev-dev + libupsclient-dev + libvarnish-dev + libvirt-dev + libxml2-dev + libyajl-dev + linux-libc-dev + perl + protobuf-c-compiler + python-dev +script: sh build.sh && ./configure --with-python=/usr/bin/python && make distcheck DISTCHECK_CONFIGURE_FLAGS="--with-python=/usr/bin/python" diff --git a/AUTHORS b/AUTHORS index 3f63c3dc..28220e79 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,9 +4,31 @@ Permanent project members Florian "octo" Forster - Initial author. +Marc Fournier + - Various fixes to the varnish plugin. + - RPM specfile maintenance. + - libmnl support in the netlink plugin. + - linux support in the zfs_arc plugin. + - openldap plugin. + - continuous integration system. + +Pierre-Yves Ritschard + - Write-Riemann plugin. + - Write-Graphite plugin: Notification support. + - Write-Kafka plugin. + - Log-Logstash plugin. + - Normalization in the CPU plugin. + - Relative values in the Load plugin. + +Ruben Kerkhof + - Bugfixes and enhancements in many places all around the project. + - Fedora and EPEL packages. + Sebastian "tokkee" Harl - Bugfixes and enhancements in many places all around the project. + - grpc plugin. - perl plugin. + - postgresql plugin. - users plugin. - vserver plugin. - Debian package. @@ -75,9 +97,16 @@ Christophe Kalt - The version 3 `log' mode. - Many Solaris related hints and fixes. +Claudius Zingerli + - chrony plugin. + Cyril Feraudet - ethstat plugin. +Dagobert Michelsen + - zone plugin. + - Many Solaris related hints and fixes. + Dan Berrange - uuid plugin. @@ -115,6 +144,9 @@ Flavio Stanchina Franck Lombardi - UNIX socket code for the memcached plugin. +Gergely Nagy + - Write-Riemann plugin. + Jason Pepas - nfs plugin. @@ -131,6 +163,9 @@ Jérôme Renard Jiri Tyr - fhcount plugin. +Julien Ammous + - Lua plugin. + Kevin Bowling - write_tsdb plugin for http://opentsdb.net/ @@ -162,18 +197,14 @@ Manuel Sanmartin + swap - Various AIX-related fixes and hacks. -Marc Fournier - - Various fixes to the varnish plugin. - - RPM specfile update. - - libmnl support in the netlink plugin. - - linux support in the zfs_arc plugin. - - openldap plugin. - Marco Chiappero - uptime plugin. - ip6tables support in the iptables plugin. - openvpn plugin (support for more status file formats) +Mathijs Möhlmann + - zone plugin. + Michael Hanselmann - md plugin. @@ -191,6 +222,9 @@ Michał Mirosław Mirko Buffoni - Port/Socket selection in the MySQL plugin. +Nicolas Jourden + - gps plugin. + Niki W. Waibel - Initial autotools fixes. - libltdl code. @@ -215,6 +249,10 @@ Paul Sadauskas - `ReportByDevice' option of the df plugin. - write_http plugin. +Pavel Rochnyack + - xencpu plugin. + - Bugfixes and enhancements in many places all around the project. + Peter Holik - cpufreq plugin. - multimeter plugin. @@ -225,14 +263,6 @@ Peter Holik Phoenix Kayo - pinba plugin. -Pierre-Yves Ritschard - - Write-Riemann plugin. - - Write-Graphite plugin: Notification support. - - Write-Kafka plugin. - - Log-Logstash plugin. - - Normalization in the CPU plugin. - - Relative values in the Load plugin. - Piotr Hosowicz - SMF manifest for collectd. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..eeb174ba --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,57 @@ +# Contribution guidelines + +Thanks for taking the time to contribute to the [collectd +project](https://collectd.org/)! This document tries to give some guidance to +make the process of contributing to *collectd* as pleasant and possible. + +## Bug reports + +Please report bugs as [GitHub +Issues](https://github.com/collectd/collectd/issues). Try to answer the +following questions: + +* Which version of *collectd* are you using? +* Which operating system (distribution) are you using at which version? +* What is the expected behavior / output? +* What is the actual (observed) behavior / output? +* How can we reproduce the problem you're having? +* If *collectd* crashes, try to get a + [stack trace](https://collectd.org/wiki/index.php/Core_file). + +Please monitor your issue for a couple of days and reply to questions. To keep +the project manageable have to do some housekeeping, meaning we will close +issues that have become stale. + +## Code contributions + +Please open a [GitHub Pull Request](https://github.com/collectd/collectd/pulls) +(PR) to contribute bug fixes, features, cleanups, new plugins, … Patches sent to +the mailing list have a tendency to fall through the cracks. + +* *Focus:* Fix *one thing* in your PR. The smaller your change, the faster it + will be reviewed and merged. +* *Coding style:* Please run `clang-format -style=file -i $FILE` on new files. + For existing files, please blend into surrounding code, i.e. mimic the + coding style of the code around your changes. +* *Documentation:* New config options need to be documented in two places: the + manpage (`src/collectd.conf.pod`) and the example config + (`src/collectd.conf.in`). +* *Continuous integration:* Once your PR is created, our continuous + integration environment will try to build it on a number of platforms. If + this reports a failure, please investigate and fix the problem. We will at + best do a very casual review for failing PRs. +* *Don't rebase:* Rebasing your branch destroys the review history. If a review + takes a long time, we may ask you to rebase on a more recent *master*, but + please don't do it without being asked. +* *types.db:* One of the most common mistakes made by new contributors is the + addition of (many) new *types* in the file `src/types.db`. The majority of + usecases can be met with one of the existing entries. If you plan to add new + entries to `src/types.db`, you should talk to us early in the design + process. + +## Other resources + +* [Mailing list](http://mailman.verplant.org/listinfo/collectd) +* [#collectd IRC channel](https://webchat.freenode.net/?channels=#collectd) + on *freenode*. +* [Old patch submission guideline](https://collectd.org/wiki/index.php/Submitting_patches) diff --git a/Makefile.am b/Makefile.am index b79ea1ca..03bdd39a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,11 +6,11 @@ if BUILD_INCLUDED_LTDL SUBDIRS += libltdl endif -SUBDIRS += src bindings . +SUBDIRS += proto src bindings . AM_CPPFLAGS = $(LTDLINCL) -EXTRA_DIST = contrib version-gen.sh +EXTRA_DIST = contrib version-gen.sh testwrapper.sh install-exec-hook: $(mkinstalldirs) $(DESTDIR)$(localstatedir)/run diff --git a/README b/README index 3e2c0233..ee909d64 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ collectd - System information collection daemon ================================================= -http://collectd.org/ +https://collectd.org/ About ----- @@ -51,6 +51,9 @@ Features - cgroups CPU accounting information for process groups under Linux. + - chrony + Chrony daemon statistics: Local clock drift, offset to peers, etc. + - conntrack Number of nf_conntrack entries. @@ -64,6 +67,9 @@ Features - cpufreq CPU frequency (For laptops with speed step or a similar technology) + - cpusleep + CPU sleep: Time spent in suspend (For mobile devices which enter suspend automatically) + - curl Parse statistics from websites using regular expressions. @@ -119,6 +125,12 @@ Features - gmond Receive multicast traffic from Ganglia instances. + - gps + Monitor gps related data through gpsd. + + - grpc + Receive values over the network using the gRPC framework. + - hddtemp Hard disk temperatures using hddtempd. @@ -156,6 +168,12 @@ Features Detailed CPU statistics of the “Logical Partitions” virtualization technique built into IBM's POWER processors. + - lua + The Lua plugin implements a Lua interpreter into collectd. This + makes it possible to write plugins in Lua which are executed by + collectd without the need to start a heavy interpreter every interval. + See collectd-lua(5) for details. + - lvm Size of “Logical Volumes” (LV) and “Volume Groups” (VG) of Linux' “Logical Volume Manager” (LVM). @@ -191,6 +209,9 @@ Features Reads values from Modbus/TCP enabled devices. Supports reading values from multiple "slaves" so gateway devices can be used. + - mqtt + Publishes and subscribes to MQTT topics. + - multimeter Information provided by serial multimeters, such as the `Metex M-4650CR'. @@ -379,12 +400,19 @@ Features - wireless Link quality of wireless cards. Linux only. + - xencpu + XEN Hypervisor CPU stats. + - xmms Bitrate and frequency of music played with XMMS. - zfs_arc Statistics for ZFS' “Adaptive Replacement Cache” (ARC). + - zone + Measures the percentage of cpu load per container (zone) under Solaris 10 + and higher + - zookeeper Read data from Zookeeper's MNTR command. @@ -400,6 +428,10 @@ Features diskspace but is extremely portable and can be analysed with almost every program that can analyse anything. Even Microsoft's Excel.. + - lua + It's possible to implement write plugins in Lua using the Lua + plugin. See collectd-lua(5) for details. + - network Send the data to a remote host to save the data somehow. This is useful for large setups where the data should be saved by a dedicated machine. @@ -495,6 +527,9 @@ Features Send an E-mail with the notification message to the configured recipients. + - notify_nagios + Submit notifications as passive check results to a local nagios instance. + - exec Execute a program or script to handle the notification. See collectd-exec(5). @@ -669,10 +704,19 @@ Prerequisites Used by the `gmond' plugin to process data received from Ganglia. + * libgrpc (optional) + Used by the `grpc' plugin. gRPC requires a C++ compiler supporting the + C++11 standard. + + * libgcrypt (optional) Used by the `network' plugin for encryption and authentication. + * libgps (optional) + Used by the `gps' plugin. + + * libhal (optional) If present, the `uuid' plugin will check for UUID from HAL. @@ -695,6 +739,10 @@ Prerequisites Used by the `openldap' plugin. + * liblua (optional) + Used by the `lua' plugin. Currently, Lua 5.1 and later are supported. + + * liblvm2 (optional) Used by the `lvm' plugin. @@ -758,14 +806,18 @@ Prerequisites The PostgreSQL C client library used by the `postgresql' plugin. + * libprotobuf, protoc 3.0+ (optional) + Used by the `grpc' plugin to generate service stubs and code to handle + network packets of collectd's protobuf-based network protocol. + + * libprotobuf-c, protoc-c (optional) Used by the `pinba' plugin to generate a parser for the network packets - sent by the Pinba PHP extension, and by the `write_riemann' plugin to - generate events to be sent to a Riemann server. + sent by the Pinba PHP extension. * libpython (optional) - Used by the `python' plugin. Currently, Python 2.3 and later and Python 3 + Used by the `python' plugin. Currently, Python 2.6 and later and Python 3 are supported. @@ -823,6 +875,10 @@ Prerequisites `virt' plugins. + * libxen (optional) + Used by the `xencpu' plugin. + + * libxmms (optional) @@ -836,6 +892,10 @@ Prerequisites `varnish' plugin. + * riemann-c-client (optional) + For the `write_riemann' plugin. + + Configuring / Compiling / Installing ------------------------------------ @@ -889,18 +949,19 @@ Configuring with libjvm library checks succeed. If this doesn't work for you, you have the possibility to specify CPP-flags, - C-flags and LD-flags for the ‘Java’ plugin by hand, using the following three - (environment) variables: + C-flags, LD-flags and LIBS for the ‘Java’ plugin by hand, using the + following environment variables: - JAVA_CPPFLAGS - JAVA_CFLAGS - JAVA_LDFLAGS + - JAVA_LIBS For example (shortened for demonstration purposes): ./configure JAVA_CPPFLAGS="-I$JAVA_HOME/include -I$JAVA_HOME/include/linux" - Adding "-ljvm" to the JAVA_LDFLAGS is done automatically, you don't have to + Adding "-ljvm" to JAVA_LIBS is done automatically, you don't have to do that. Generating the configure script @@ -917,6 +978,7 @@ To generate the `configure` script, you'll need the following dependencies: - bison - libtool - libtool-ltdl +- pkg-config The `build.sh' script takes no arguments. @@ -969,6 +1031,5 @@ Author Sebastian tokkee Harl , and many contributors (see `AUTHORS'). - Please send bug reports and patches to the mailing list, see `Contact' - above. - + Please use GitHub reporting bugs and submitting pull requests. + See CONTRIBUTING.md for details. diff --git a/bindings/java/org/collectd/java/GenericJMXConfConnection.java b/bindings/java/org/collectd/java/GenericJMXConfConnection.java index ea0f2fa2..887c2895 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfConnection.java +++ b/bindings/java/org/collectd/java/GenericJMXConfConnection.java @@ -52,7 +52,8 @@ class GenericJMXConfConnection private String _host = null; private String _instance_prefix = null; private String _service_url = null; - private MBeanServerConnection _jmx_connection = null; + private JMXConnector _jmx_connector = null; + private MBeanServerConnection _mbean_connection = null; private List _mbeans = null; /* @@ -92,55 +93,74 @@ class GenericJMXConfConnection return Collectd.getHostname(); } /* }}} String getHost */ -private void connect () /* {{{ */ -{ - JMXServiceURL service_url; - JMXConnector connector; - Map environment; + private void connect () /* {{{ */ + { + JMXServiceURL service_url; + Map environment; - if (_jmx_connection != null) - return; + // already connected + if (this._jmx_connector != null) { + return; + } - environment = null; - if (this._password != null) - { - String[] credentials; + environment = null; + if (this._password != null) + { + String[] credentials; - if (this._username == null) - this._username = new String ("monitorRole"); + if (this._username == null) + this._username = new String ("monitorRole"); - credentials = new String[] { this._username, this._password }; + credentials = new String[] { this._username, this._password }; - environment = new HashMap (); - environment.put (JMXConnector.CREDENTIALS, credentials); - environment.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, this.getClass().getClassLoader()); - } + environment = new HashMap (); + environment.put (JMXConnector.CREDENTIALS, credentials); + environment.put (JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, this.getClass().getClassLoader()); + } - try - { - service_url = new JMXServiceURL (this._service_url); - connector = JMXConnectorFactory.connect (service_url, environment); - _jmx_connection = connector.getMBeanServerConnection (); - } - catch (Exception e) + try + { + service_url = new JMXServiceURL (this._service_url); + this._jmx_connector = JMXConnectorFactory.connect (service_url, environment); + this._mbean_connection = _jmx_connector.getMBeanServerConnection (); + } + catch (Exception e) + { + Collectd.logError ("GenericJMXConfConnection: " + + "Creating MBean server connection failed: " + e); + disconnect (); + return; + } + } /* }}} void connect */ + + private void disconnect () /* {{{ */ { - Collectd.logError ("GenericJMXConfConnection: " - + "Creating MBean server connection failed: " + e); - return; - } -} /* }}} void connect */ + try + { + if (this._jmx_connector != null) { + this._jmx_connector.close(); + } + } + catch (Exception e) + { + // It's fine if close throws an exception + } -/* - * public methods - * - * - * Host "tomcat0.mycompany" - * ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:17264/jmxrmi" - * Collect "java.lang:type=GarbageCollector,name=Copy" - * Collect "java.lang:type=Memory" - * - * - */ + this._jmx_connector = null; + this._mbean_connection = null; + } /* }}} void disconnect */ + + /* + * public methods + * + * + * Host "tomcat0.mycompany" + * ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:17264/jmxrmi" + * Collect "java.lang:type=GarbageCollector,name=Copy" + * Collect "java.lang:type=Memory" + * + * + */ public GenericJMXConfConnection (OConfigItem ci) /* {{{ */ throws IllegalArgumentException { @@ -217,9 +237,10 @@ private void connect () /* {{{ */ { PluginData pd; + // try to connect connect (); - if (this._jmx_connection == null) + if (this._mbean_connection == null) return; Collectd.logDebug ("GenericJMXConfConnection.query: " @@ -234,11 +255,11 @@ private void connect () /* {{{ */ { int status; - status = this._mbeans.get (i).query (this._jmx_connection, pd, + status = this._mbeans.get (i).query (this._mbean_connection, pd, this._instance_prefix); if (status != 0) { - this._jmx_connection = null; + disconnect (); return; } } /* for */ diff --git a/bindings/java/org/collectd/java/GenericJMXConfValue.java b/bindings/java/org/collectd/java/GenericJMXConfValue.java index 4b42c911..63b76282 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfValue.java +++ b/bindings/java/org/collectd/java/GenericJMXConfValue.java @@ -28,6 +28,7 @@ package org.collectd.java; import java.util.Arrays; import java.util.List; +import java.util.Collection; import java.util.Set; import java.util.Iterator; import java.util.ArrayList; @@ -39,6 +40,7 @@ import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.management.openmbean.OpenType; import javax.management.openmbean.CompositeData; +import javax.management.openmbean.TabularData; import javax.management.openmbean.InvalidKeyException; import org.collectd.api.Collectd; @@ -68,6 +70,7 @@ class GenericJMXConfValue private List _attributes; private String _instance_prefix; private List _instance_from; + private String _plugin_name; private boolean _is_table; /** @@ -295,6 +298,45 @@ class GenericJMXConfValue { if (value instanceof CompositeData) return (queryAttributeRecursive ((CompositeData) value, attrName)); + else if (value instanceof TabularData) + return (queryAttributeRecursive ((TabularData) value, attrName)); + else + return (null); + } + } /* }}} queryAttributeRecursive */ + + private Object queryAttributeRecursive (TabularData parent, /* {{{ */ + List attrName) + { + String key; + Object value = null; + + key = attrName.remove (0); + + @SuppressWarnings("unchecked") + Collection table = (Collection) parent.values(); + for (CompositeData compositeData : table) + { + if (key.equals(compositeData.get("key"))) + { + value = compositeData.get("value"); + } + } + if (null == value) + { + return (null); + } + + if (attrName.size () == 0) + { + return (value); + } + else + { + if (value instanceof CompositeData) + return (queryAttributeRecursive ((CompositeData) value, attrName)); + else if (value instanceof TabularData) + return (queryAttributeRecursive ((TabularData) value, attrName)); else return (null); } @@ -341,6 +383,8 @@ class GenericJMXConfValue { if (value instanceof CompositeData) return (queryAttributeRecursive((CompositeData) value, attrNameList)); + else if (value instanceof TabularData) + return (queryAttributeRecursive((TabularData) value, attrNameList)); else if (value instanceof OpenType) { OpenType ot = (OpenType) value; @@ -351,7 +395,7 @@ class GenericJMXConfValue else { Collectd.logError ("GenericJMXConfValue: Received object of " - + "unknown class."); + + "unknown class. " + attrName + " " + ((value == null)?"null":value.getClass().getName())); return (null); } } @@ -436,6 +480,7 @@ class GenericJMXConfValue this._attributes = new ArrayList (); this._instance_prefix = null; this._instance_from = new ArrayList (); + this._plugin_name = null; this._is_table = false; /* @@ -485,6 +530,12 @@ class GenericJMXConfValue if (tmp != null) this._instance_from.add (tmp); } + else if (child.getKey ().equalsIgnoreCase ("PluginName")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._plugin_name = tmp; + } else throw (new IllegalArgumentException ("Unknown option: " + child.getKey ())); @@ -538,6 +589,10 @@ class GenericJMXConfValue vl = new ValueList (pd); vl.setType (this._ds_name); + if (this._plugin_name != null) + { + vl.setPlugin (this._plugin_name); + } /* * Build the instnace prefix from the fixed string prefix and the diff --git a/bindings/perl/lib/Collectd/Unixsock.pm b/bindings/perl/lib/Collectd/Unixsock.pm index 5e79d268..304bbbc3 100644 --- a/bindings/perl/lib/Collectd/Unixsock.pm +++ b/bindings/perl/lib/Collectd/Unixsock.pm @@ -137,13 +137,13 @@ sub _parse_identifier sub _escape_argument { - local $_ = shift; + my $arg = shift; - return $_ if /^\w+$/; + return $arg if $arg =~ /^\w+$/; - s#\\#\\\\#g; - s#"#\\"#g; - return "\"$_\""; + $arg =~ s#\\#\\\\#g; + $arg =~ s#"#\\"#g; + return "\"$arg\""; } # Send a command on a socket, including any required argument escaping. @@ -193,6 +193,32 @@ sub _socket_chat return $cbdata; } +# Send a raw message on a socket. +# Returns true upon success and false otherwise. +sub _send_message +{ + my ($self, $msg) = @_; + + my $fh = $self->{'sock'} or confess ('object has no filehandle'); + + $msg .= "\n" unless $msg =~/\n$/; + + #1024 is default buffer size at unixsock.c us_handle_client() + warn "Collectd::Unixsock->_send_message(\$msg): message is too long!" if length($msg) > 1024; + + _debug "-> $msg"; + $fh->print($msg); + + $msg = <$fh>; + chomp ($msg); + _debug "<- $msg\n"; + + my ($status, $error) = split / /, $msg, 2; + return 1 if $status == 0; + + $self->{error} = $error; + return; +} =head1 PUBLIC METHODS @@ -330,18 +356,8 @@ sub putval . _escape_argument ($identifier) . $interval . ' ' . _escape_argument ($values) . "\n"; - _debug "-> $msg"; - $fh->print($msg); - $msg = <$fh>; - chomp $msg; - _debug "<- $msg\n"; - - ($status, $msg) = split / /, $msg, 2; - return 1 if $status == 0; - - $self->{error} = $msg; - return; + return $self->_send_message($msg); } # putval =item I<$res> = I<$self>-EB ( C<%identifier> ) @@ -500,18 +516,7 @@ sub putnotif . join (' ', map { $_ . '=' . _escape_argument ($args{$_}) } keys %args) . "\n"; - _debug "-> $msg"; - $fh->print($msg); - - $msg = <$fh>; - chomp $msg; - _debug "<- $msg\n"; - - ($status, $msg) = split / /, $msg, 2; - return 1 if $status == 0; - - $self->{error} = $msg; - return; + return $self->_send_message($msg); } # putnotif =item I<$self>-EB (B =E I<$timeout>, B =E [...], B =E [...]); @@ -549,7 +554,6 @@ sub flush my $fh = $self->{sock} or confess; - my $status = 0; my $msg = "FLUSH"; $msg .= " timeout=$args{timeout}" if defined $args{timeout}; @@ -564,6 +568,7 @@ sub flush if ($args{identifier}) { + my $pre = $msg; for my $identifier (@{$args{identifier}}) { my $ident_str; @@ -576,24 +581,18 @@ sub flush } $ident_str = _create_identifier ($identifier) or return; - $msg .= ' identifier=' . _escape_argument ($ident_str); + $ident_str = ' identifier=' . _escape_argument ($ident_str); + + if (length($msg)+length($ident_str) >= 1023) { #1024 - 1 byte for \n + $self->_send_message($msg) or return; + $msg = $pre; + } + + $msg .= $ident_str; } } - - $msg .= "\n"; - - _debug "-> $msg"; - $fh->print($msg); - - $msg = <$fh>; - chomp ($msg); - _debug "<- $msg\n"; - - ($status, $msg) = split / /, $msg, 2; - return 1 if $status == 0; - - $self->{error} = $msg; - return; + + return $self->_send_message($msg); } sub error diff --git a/bindings/perl/t/01_methods.t b/bindings/perl/t/01_methods.t index 2f7818b1..4e94f8e8 100644 --- a/bindings/perl/t/01_methods.t +++ b/bindings/perl/t/01_methods.t @@ -16,7 +16,7 @@ sub test_query { my ($nresults, $resultdata) = @$results; my $r = $s->getval(%{Collectd::Unixsock::_parse_identifier($attr)}); is(ref $r, 'HASH', "Got a result for $attr"); - is(scalar keys $r, $nresults, "$nresults result result for $attr"); + is(scalar keys %$r, $nresults, "$nresults result result for $attr"); is_deeply($r, $resultdata, "Data or $attr matches"); } diff --git a/build.sh b/build.sh index 20854b13..57f3d444 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ EOF done } -check_for_application lex yacc autoheader aclocal automake autoconf +check_for_application lex bison autoheader aclocal automake autoconf # Actually we don't need the pkg-config executable, but we need the M4 macros. # We check for `pkg-config' here and hope that M4 macros will then be diff --git a/configure.ac b/configure.ac index d214d57a..9a6da11d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,7 @@ dnl Process this file with autoconf to produce a configure script. +AC_PREREQ([2.60]) AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)]) -AC_CONFIG_SRCDIR(src/) +AC_CONFIG_SRCDIR(src/target_set.c) AC_CONFIG_HEADERS(src/config.h) AC_CONFIG_AUX_DIR([libltdl/config]) @@ -31,7 +32,7 @@ m4_ifdef([LT_PACKAGE_VERSION], AM_CONDITIONAL([BUILD_INCLUDED_LTDL], [test "x$LTDLDEPS" != "x"]) -AM_INIT_AUTOMAKE([tar-pax dist-bzip2 foreign]) +AM_INIT_AUTOMAKE([subdir-objects tar-pax dist-bzip2 no-dist-gzip foreign]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_LANG(C) @@ -42,7 +43,10 @@ AC_SYS_LARGEFILE # # Checks for programs. # -AC_PROG_CC +AC_PROG_CC_C99([], + [AC_MSG_ERROR([No compiler found that supports C99])] +) +AC_PROG_CXX AC_PROG_CPP AC_PROG_EGREP AC_PROG_INSTALL @@ -56,6 +60,8 @@ AC_PROG_LIBTOOL AC_PROG_LEX AC_PROG_YACC +AC_PATH_PROG([VALGRIND], [valgrind]) + # Warn when pkg.m4 is missing m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config]) @@ -73,26 +79,33 @@ then AC_MSG_ERROR([bison is missing and you do not have ${srcdir}/src/liboconfig/parser.c. Please install bison]) fi -AC_CHECK_PROG([have_protoc_c], [protoc-c], [yes], [no]) -if test "x$have_protoc_c" = "xno" -then - have_protoc_c="no (protoc-c compiler not found)" +AC_ARG_VAR([PROTOC], [path to the protoc binary]) +AC_PATH_PROG([PROTOC], [protoc]) +have_protoc3="no" +if test "x$PROTOC" != "x"; then + AC_MSG_CHECKING([for protoc 3.0.0+]) + if $PROTOC --version | $EGREP libprotoc.3 >/dev/null; then + protoc3="yes (`$PROTOC --version`)" + have_protoc3="yes" + else + protoc3="no (`$PROTOC --version`)" + fi + AC_MSG_RESULT([$protoc3]) fi +AM_CONDITIONAL(HAVE_PROTOC3, test "x$have_protoc3" = "xyes") -if test "x$have_protoc_c" = "xyes" -then - AC_CHECK_HEADERS([protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c.h], - [have_protoc_c="yes"; break], - [have_protoc_c="no ( not found)"]) -fi -if test "x$have_protoc_c" = "xyes" -then - AC_CHECK_LIB([protobuf-c], [protobuf_c_message_pack], - [have_protoc_c="yes"], - [have_protoc_c="no (libprotobuf-c not found)"]) +AC_ARG_VAR([GRPC_CPP_PLUGIN], [path to the grpc_cpp_plugin binary]) +AC_PATH_PROG([GRPC_CPP_PLUGIN], [grpc_cpp_plugin]) +AM_CONDITIONAL(HAVE_GRPC_CPP, test "x$GRPC_CPP_PLUGIN" != "x") +AC_ARG_VAR([PROTOC_C], [path to the protoc-c binary]) +AC_PATH_PROG([PROTOC_C], [protoc-c]) +if test "x$PROTOC_C" = "x" +then + have_protoc_c="no (protoc-c compiler not found)" +else + have_protoc_c="yes" fi -AM_CONDITIONAL(HAVE_PROTOC_C, test "x$have_protoc_c" = "xyes") AC_MSG_CHECKING([for kernel type ($host_os)]) case $host_os in @@ -112,6 +125,10 @@ case $host_os in AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel]) ac_system="OpenBSD" ;; + *netbsd*) + AC_DEFINE([KERNEL_NETBSD], 1, [True if program is to be compiled for a NetBSD kernel]) + ac_system="NetBSD" + ;; *aix*) AC_DEFINE([KERNEL_AIX], 1, [True if program is to be compiled for a AIX kernel]) ac_system="AIX" @@ -125,12 +142,12 @@ case $host_os in esac AC_MSG_RESULT([$ac_system]) -AM_CONDITIONAL([BUILD_LINUX],[test "x$ac_system" = "xLinux"]) -AM_CONDITIONAL([BUILD_SOLARIS],[test "x$ac_system" = "xSolaris"]) -AM_CONDITIONAL([BUILD_DARWIN],[test "x$ac_system" = "xDarwin"]) -AM_CONDITIONAL([BUILD_OPENBSD],[test "x$ac_system" = "xOpenBSD"]) -AM_CONDITIONAL([BUILD_AIX],[test "x$ac_system" = "xAIX"]) -AM_CONDITIONAL([BUILD_FREEBSD],[test "x$ac_system" = "xFreeBSD"]) +AM_CONDITIONAL([BUILD_AIX], [test "x$ac_system" = "xAIX"]) +AM_CONDITIONAL([BUILD_DARWIN], [test "x$ac_system" = "xDarwin"]) +AM_CONDITIONAL([BUILD_FREEBSD], [test "x$ac_system" = "xFreeBSD"]) +AM_CONDITIONAL([BUILD_LINUX], [test "x$ac_system" = "xLinux"]) +AM_CONDITIONAL([BUILD_OPENBSD], [test "x$ac_system" = "xOpenBSD"]) +AM_CONDITIONAL([BUILD_SOLARIS], [test "x$ac_system" = "xSolaris"]) if test "x$ac_system" = "xLinux" then @@ -199,6 +216,19 @@ AC_HEADER_STDBOOL AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h fnmatch.h libgen.h) +# For entropy plugin on newer NetBSD +AC_CHECK_HEADERS(sys/rndio.h, [], [], +[#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_SYS_IOCTL_H +# include +#endif +#if HAVE_SYS_PARAM_H +# include +#endif +]) + # For ping library AC_CHECK_HEADERS(netinet/in_systm.h, [], [], [#if HAVE_STDINT_H @@ -413,7 +443,7 @@ AC_CHECK_HEADERS(sys/sysctl.h, [], [], AC_MSG_CHECKING([for sysctl kern.cp_times]) if test -x /sbin/sysctl then - /sbin/sysctl kern.cp_times 2>/dev/null + /sbin/sysctl kern.cp_times >/dev/null 2>&1 if test $? -eq 0 then AC_MSG_RESULT([yes]) @@ -426,6 +456,22 @@ else AC_MSG_RESULT([no]) fi +AC_MSG_CHECKING([for sysctl kern.cp_time]) +if test -x /sbin/sysctl +then + /sbin/sysctl kern.cp_time >/dev/null 2>&1 + if test $? -eq 0 + then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_SYSCTL_KERN_CP_TIME, 1, + [Define if sysctl supports kern.cp_time]) + else + AC_MSG_RESULT([no]) + fi +else + AC_MSG_RESULT([no]) +fi + # For hddtemp module AC_CHECK_HEADERS(linux/major.h) @@ -445,7 +491,7 @@ else have_linux_raid_md_u_h="no" fi -# For the swap module +# For the wireless module have_linux_wireless_h="no" if test "x$ac_system" = "xLinux" then @@ -637,10 +683,26 @@ AC_CHECK_HEADERS([ \ wordexp.h \ ]) -AC_CHECK_HEADERS([xfs/xqm.h], [], [], -[ -#define _GNU_SOURCE -]) +# --enable-xfs {{{ +AC_ARG_ENABLE([xfs], + [AS_HELP_STRING([--enable-xfs], [xfs support in df plugin @<:@default=yes@:>@])], + [], + [enable_xfs="auto"] +) + +if test "x$enable_xfs" != "xno"; then + AC_CHECK_HEADERS([xfs/xqm.h], + [], + [ + if test "x$enable_xfs" = "xyes"; then + AC_MSG_ERROR([xfs/xqm.h not found]) + fi + ], + [[#define _GNU_SOURCE]] + ) +fi + +# }}} # For the dns plugin AC_CHECK_HEADERS(arpa/nameser.h) @@ -680,8 +742,6 @@ AC_CHECK_HEADERS(netinet/if_ether.h, [], [], #endif ]) -AC_CHECK_HEADERS(netinet/ip_compat.h) - have_net_pfvar_h="no" AC_CHECK_HEADERS(net/pfvar.h, [have_net_pfvar_h="yes"], @@ -705,6 +765,23 @@ AC_CHECK_HEADERS(net/pfvar.h, have_termios_h="no" AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"]) +# For cpusleep plugin +AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported], + [c_cv_have_clock_boottime_monotonic], + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( +[[ +#include +]], +[[ + struct timespec b, m; + clock_gettime(CLOCK_BOOTTIME, &b ); + clock_gettime(CLOCK_MONOTONIC, &m ); +]] + )], + [c_cv_have_clock_boottime_monotonic="yes"], + [c_cv_have_clock_boottime_monotonic="no"])) + + # For the turbostat plugin have_asm_msrindex_h="no" AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"]) @@ -736,23 +813,30 @@ AC_CHECK_HEADERS(sys/capability.h) # Checks for typedefs, structures, and compiler characteristics. # AC_C_CONST -AC_C_INLINE -AC_TYPE_OFF_T AC_TYPE_PID_T AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T AC_TYPE_UID_T -AC_TYPE_UINT32_T AC_HEADER_TIME # # Checks for library functions. # -AC_PROG_GCC_TRADITIONAL -AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale) +AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale asprintf) AC_FUNC_STRERROR_R +test_cxx_flags() { + AC_LANG_PUSH([C++]) + AC_LANG_CONFTEST([ + AC_LANG_SOURCE([[int main(void){}]]) + ]) + $CXX -c conftest.cpp $CXXFLAGS $@ > /dev/null 2> /dev/null + ret=$? + rm -f conftest.o + AC_LANG_POP([C++]) + return $ret +} + SAVE_CFLAGS="$CFLAGS" # Emulate behavior of src/Makefile.am if test "x$GCC" = "xyes" @@ -852,8 +936,6 @@ fi if test "x$have_clock_gettime" = "xyes" then AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if the clock_gettime(2) function is available.]) -else - AC_MSG_WARN(cannot find clock_gettime) fi nanosleep_needs_rt="no" @@ -1305,6 +1387,20 @@ AC_ARG_WITH(useragent, [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User a # }}} +# --with-data-max-name-len {{{ +AC_ARG_WITH(data-max-name-len, [AS_HELP_STRING([--with-data-max-name-len@<:@=VALUE@:>@], [Maximum length of data buffers])], +[ + if test "x$withval" != "x" && test $withval -gt 0 + then + AC_DEFINE_UNQUOTED(DATA_MAX_NAME_LEN, [$withval], [Maximum length of data buffers]) + else + AC_MSG_ERROR([DATA_MAX_NAME_LEN must be a positive integer -- $withval given]) + fi +], +[ AC_DEFINE(DATA_MAX_NAME_LEN, 128, [Maximum length of data buffers])] +) +# }}} + have_getfsstat="no" AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"]) have_getvfsstat="no" @@ -1382,15 +1478,15 @@ if test "x$have_getmntent" = "xc"; then fi if test "x$have_getmntent" = "xsun"; then AC_DEFINE(HAVE_SUN_GETMNTENT, 1, - [Define if the function getmntent exists. It's the version from libsun.]) + [Define if the function getmntent exists. It is the version from libsun.]) fi if test "x$have_getmntent" = "xseq"; then AC_DEFINE(HAVE_SEQ_GETMNTENT, 1, - [Define if the function getmntent exists. It's the version from libseq.]) + [Define if the function getmntent exists. It is the version from libseq.]) fi if test "x$have_getmntent" = "xgen"; then AC_DEFINE(HAVE_GEN_GETMNTENT, 1, - [Define if the function getmntent exists. It's the version from libgen.]) + [Define if the function getmntent exists. It is the version from libgen.]) fi # Check for htonll @@ -1481,6 +1577,24 @@ AC_CHECK_MEMBERS([struct kinfo_proc.p_pid, struct kinfo_proc.p_vm_rssize], #include ]) + +AC_CHECK_MEMBERS([struct kinfo_proc2.p_pid, struct kinfo_proc2.p_uru_maxrss], + [ + AC_DEFINE(HAVE_STRUCT_KINFO_PROC2_NETBSD, 1, + [Define if struct kinfo_proc2 exists in the NetBSD variant.]) + have_struct_kinfo_proc2_netbsd="yes" + ], + [ + have_struct_kinfo_proc2_netbsd="no" + ], + [ +#include +#include +#include + ]) + + + AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [], [#define _BSD_SOURCE #define _DEFAULT_SOURCE @@ -1548,18 +1662,48 @@ AC_CHECK_LIB(resolv, res_search, AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes") dnl Check for HAL (hardware abstraction library) -with_libhal="yes" -AC_CHECK_LIB(hal,libhal_device_property_exists, - [AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if you have 'hal' library])], - [with_libhal="no"]) -if test "x$with_libhal" = "xyes"; then - if test "x$PKG_CONFIG" != "x"; then - BUILD_WITH_LIBHAL_CFLAGS="`$PKG_CONFIG --cflags hal`" - BUILD_WITH_LIBHAL_LIBS="`$PKG_CONFIG --libs hal`" - AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS) - AC_SUBST(BUILD_WITH_LIBHAL_LIBS) - fi -fi +with_libhal="no" +PKG_CHECK_MODULES([HAL], [hal], + [ + SAVE_LIBS="$LIBS" + LIBS="$HAL_LIBS $LIBS" + AC_CHECK_LIB([hal], [libhal_device_property_exists], + [ + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$HAL_CFLAGS $CPPFLAGS" + AC_CHECK_HEADERS([libhal.h], + [ + with_libhal="yes" + BUILD_WITH_LIBHAL_CFLAGS="$HAL_CFLAGS" + BUILD_WITH_LIBHAL_LIBS="$HAL_LIBS" + ]) + CPPFLAGS="$SAVE_CPPFLAGS" + ], + [ : ] + ) + LIBS="$SAVE_LIBS" + ], + [ : ] +) +AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS) +AC_SUBST(BUILD_WITH_LIBHAL_LIBS) + + +SAVE_LIBS="$LIBS" +AC_CHECK_LIB([pthread], + [pthread_create], + [], + [AC_MSG_ERROR([Symbol 'pthread_create' not found in libpthread"])], + [] +) +PTHREAD_LIBS="$LIBS" +LIBS="$SAVE_LIBS" + +AC_CHECK_HEADERS([pthread.h], + [], + [AC_MSG_ERROR([pthread.h not found])] +) +AC_SUBST([PTHREAD_LIBS]) m4_divert_once([HELP_WITH], [ collectd additional packages:]) @@ -1859,6 +2003,36 @@ then fi if test "x$with_libcurl" = "xyes" then + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + CPPFLAGS="$CPPFLAGS $with_curl_cflags" + LDFLAGS="$LDFLAGS $with_curl_libs" + AC_CACHE_CHECK([for CURLINFO_APPCONNECT_TIME], + [c_cv_have_curlinfo_appconnect_time], + AC_LINK_IFELSE([AC_LANG_PROGRAM( +[[ +#include +]], +[[ +int val = CURLINFO_APPCONNECT_TIME; +return val; +]] + )], + [c_cv_have_curlinfo_appconnect_time="yes"], + [c_cv_have_curlinfo_appconnect_time="no"] + ) + ) + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" +fi +AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes") +if test "x$c_cv_have_curlinfo_appconnect_time" = "xyes" +then + AC_DEFINE(HAVE_CURLINFO_APPCONNECT_TIME, 1, [Define if curl.h defines CURLINFO_APPCONNECT_TIME.]) +fi + +if test "x$with_libcurl" = "xyes" +then BUILD_WITH_LIBCURL_CFLAGS="$with_curl_cflags" BUILD_WITH_LIBCURL_LIBS="$with_curl_libs" AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS) @@ -1874,7 +2048,6 @@ then AC_DEFINE(HAVE_CURLOPT_TIMEOUT_MS, 1, [Define if libcurl supports CURLOPT_TIMEOUT_MS option.]) fi fi -AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes") # }}} # --with-libdbi {{{ @@ -2111,12 +2284,6 @@ then AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer, [with_libgcrypt="yes"], [with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"]) - - if test "$with_libgcrypt" != "no"; then - m4_ifdef([AM_PATH_LIBGCRYPT],[AM_PATH_LIBGCRYPT(1:1.2.0,,with_libgcrypt="no (version 1.2.0+ required)")]) - GCRYPT_CPPFLAGS="$LIBGCRYPT_CPPFLAGS $LIBGCRYPT_CFLAGS" - GCRYPT_LIBS="$LIBGCRYPT_LIBS" - fi fi CPPFLAGS="$SAVE_CPPFLAGS" @@ -2134,6 +2301,146 @@ AC_SUBST(GCRYPT_LIBS) AM_CONDITIONAL(BUILD_WITH_LIBGCRYPT, test "x$with_libgcrypt" = "xyes") # }}} +# --with-libgps {{{ +with_libgps_cflags="" +with_libgps_ldflags="" +AC_ARG_WITH(libgps, [AS_HELP_STRING([--with-libgps@<:@=PREFIX@:>@], [Path to libgps.])], +[ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libgps_cflags="-I$withval/include" + with_libgps_ldflags="-L$withval/lib" + with_libgps="yes" + else + with_libgps="$withval" + fi +], +[ + with_libgps="yes" +]) +if test "x$with_libgps" = "xyes" +then + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $with_libgps_cflags" + + AC_CHECK_HEADERS(gps.h, [with_libgps="yes"], [with_libgps="no (gps.h not found)"]) + + CFLAGS="$SAVE_CFLAGS" +fi +if test "x$with_libgps" = "xyes" +then + SAVE_CFLAGS="$CFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + CFLAGS="$CFLAGS $with_libgps_cflags" + LDFLAGS="$LDFLAGS $with_libgps_ldflags" + + AC_CHECK_LIB(gps, gps_open, [with_libgps="yes"], [with_libgps="no (symbol gps_open not found)"]) + + CFLAGS="$SAVE_CFLAGS" + LDFLAGS="$SAVE_LDFLAGS" +fi +if test "x$with_libgps" = "xyes" +then + BUILD_WITH_LIBGPS_CFLAGS="$with_libgps_cflags" + BUILD_WITH_LIBGPS_LDFLAGS="$with_libgps_ldflags" + BUILD_WITH_LIBGPS_LIBS="-lgps" + AC_SUBST(BUILD_WITH_LIBGPS_CFLAGS) + AC_SUBST(BUILD_WITH_LIBGPS_LDFLAGS) + AC_SUBST(BUILD_WITH_LIBGPS_LIBS) +fi +AM_CONDITIONAL(BUILD_WITH_LIBGPS, test "x$with_libgps" = "xyes") +# }}} + +# --with-libgrpc++ {{{ +with_libgrpcpp_cppflags="" +with_libgrpcpp_ldflags="" +AC_ARG_WITH([libgrpc++], [AS_HELP_STRING([--with-libgrpc++@<:@=PREFIX@:>@], [Path to libgrpc++.])], + [ + with_grpcpp="$withval" + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libgrpcpp_cppflags="-I$withval/include" + with_libgrpcpp_ldflags="-L$withval/lib" + with_libgrpcpp="yes" + fi + if test "x$withval" = "xno" + then + with_libgrpcpp="no (disabled on command line)" + fi + ], + [withval="yes"] +) +if test "x$withval" = "xyes" +then +PKG_CHECK_MODULES([GRPCPP], [grpc++], + [with_libgrpcpp="yes"], + [with_libgrpcpp="no (pkg-config could not find libgrpc++)"] +) +fi + +if test "x$withval" != "xno" +then + AC_MSG_CHECKING([whether $CXX accepts -std=c++11]) + if test_cxx_flags -std=c++11; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + with_libgrpcpp="no (requires C++11 support)" + fi +fi + +if test "x$with_libgrpcpp" = "xyes" +then + AC_LANG_PUSH(C++) + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS" + AC_CHECK_HEADERS([grpc++/grpc++.h], [], + [with_libgrpcpp="no ( not found)"] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + AC_LANG_POP(C++) +fi +if test "x$with_libgrpcpp" = "xyes" +then + AC_LANG_PUSH(C++) + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS" + LDFLAGS="$with_libgrpcpp_ldflags" + if test "x$GRPCPP_LIBS" = "x" + then + LIBS="-lgrpc++" + else + LIBS="$GRPCPP_LIBS" + fi + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[grpc::ServerBuilder sb;]] + )], + [ + with_libgrpcpp="yes" + if test "x$GRPCPP_LIBS" = "x" + then + GRPCPP_LIBS="-lgrpc++" + fi + ], + [with_libgrpcpp="no (libgrpc++ not found)"] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" + AC_LANG_POP(C++) +fi +BUILD_WITH_LIBGRPCPP_CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS" +BUILD_WITH_LIBGRPCPP_LDFLAGS="$with_libgrpcpp_ldflags" +BUILD_WITH_LIBGRPCPP_LIBS="$GRPCPP_LIBS" +AC_SUBST([BUILD_WITH_LIBGRPCPP_CPPFLAGS]) +AC_SUBST([BUILD_WITH_LIBGRPCPP_LDFLAGS]) +AC_SUBST([BUILD_WITH_LIBGRPCPP_LIBS]) +# }}} + # --with-libiptc {{{ AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])], [ @@ -2158,11 +2465,6 @@ AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to l fi ]) -if test "x$with_libiptc" = "xpkgconfig" && test "x$PKG_CONFIG" = "x" -then - with_libiptc="no (Don't have pkg-config)" -fi - if test "x$with_libiptc" = "xpkgconfig" then $PKG_CONFIG --exists 'libiptc' 2>/dev/null @@ -2235,9 +2537,6 @@ if test "x$with_java_home" = "x" then with_java_home="/usr/lib/jvm" fi -with_java_vmtype="client" -with_java_cflags="" -with_java_libs="" JAVAC="$JAVAC" JAR="$JAR" AC_ARG_WITH(java, [AS_HELP_STRING([--with-java@<:@=PREFIX@:>@], [Path to Java home.])], @@ -2330,6 +2629,10 @@ if test "x$JAVA_LDFLAGS" != "x" then AC_MSG_NOTICE([Building with JAVA_LDFLAGS set to: $JAVA_LDFLAGS]) fi +if test "x$JAVA_LIBS" != "x" +then + AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS]) +fi if test "x$JAVAC" = "x" then with_javac_path="$PATH" @@ -2370,9 +2673,11 @@ fi SAVE_CPPFLAGS="$CPPFLAGS" SAVE_CFLAGS="$CFLAGS" SAVE_LDFLAGS="$LDFLAGS" +SAVE_LIBS="$LIBS" CPPFLAGS="$CPPFLAGS $JAVA_CPPFLAGS" CFLAGS="$CFLAGS $JAVA_CFLAGS" LDFLAGS="$LDFLAGS $JAVA_LDFLAGS" +LIBS="$LIBS $JAVA_LIBS" if test "x$with_java" = "xyes" then @@ -2382,8 +2687,8 @@ if test "x$with_java" = "xyes" then AC_CHECK_LIB(jvm, JNI_CreateJavaVM, [with_java="yes"], - [with_java="no (libjvm not found)"], - [$JAVA_LIBS]) + [with_java="no (Symbol 'JNI_CreateJavaVM' not found)"], + [$JAVA_LIBS $PTHREAD_LIBS]) fi if test "x$with_java" = "xyes" then @@ -2394,6 +2699,7 @@ fi CPPFLAGS="$SAVE_CPPFLAGS" CFLAGS="$SAVE_CFLAGS" LDFLAGS="$SAVE_LDFLAGS" +LIBS="$SAVE_LIBS" AC_SUBST(JAVA_CPPFLAGS) AC_SUBST(JAVA_CFLAGS) @@ -2460,22 +2766,110 @@ fi AM_CONDITIONAL(BUILD_WITH_LIBLDAP, test "x$with_libldap" = "xyes") # }}} +# --with-liblua {{{ +AC_ARG_VAR([LIBLUA_PKG_CONFIG_NAME], [Name of liblua used by pkg-config]) +if test "x$LIBLUA_PKG_CONFIG_NAME" != "x" +then + PKG_CHECK_MODULES([LUA], [$LIBLUA_PKG_CONFIG_NAME], + [with_liblua="yes"], + [with_liblua="no"] + ) +else + PKG_CHECK_MODULES([LUA], [lua], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua-5.3], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua5.3], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua-5.2], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua5.2], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua-5.1], + [with_liblua="yes"], + [ + PKG_CHECK_MODULES([LUA], [lua5.1], + [with_liblua="yes"], + [with_liblua="no (pkg-config cannot find liblua)"] + ) + ] + ) + ] + ) + ] + ) + ] + ) + ] + ) + ] + ) +fi + +if test "x$with_liblua" = "xyes" +then + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $LUA_CFLAGS" + + AC_CHECK_HEADERS([lua.h lauxlib.h lualib.h], + [with_liblua="yes"], + [with_liblua="no (header not found)"] + ) + + CFLAGS="$SAVE_CFLAGS" +fi + +if test "x$with_liblua" = "xyes" +then + SAVE_LIBS="$LIBS" + LIBS="$LIBS $LUA_LIBS" + + AC_CHECK_FUNC([lua_settop], + [with_liblua="yes"], + [with_liblua="no (symbol 'lua_settop' not found)"] + ) + + LIBS="$SAVE_LIBS" +fi + +if test "x$with_liblua" = "xyes" +then + BUILD_WITH_LIBLUA_CFLAGS="$LUA_CFLAGS" + BUILD_WITH_LIBLUA_LIBS="$LUA_LIBS" +fi +AC_SUBST(BUILD_WITH_LIBLUA_CFLAGS) +AC_SUBST(BUILD_WITH_LIBLUA_LIBS) +# }}} + # --with-liblvm2app {{{ with_liblvm2app_cppflags="" with_liblvm2app_ldflags="" AC_ARG_WITH(liblvm2app, [AS_HELP_STRING([--with-liblvm2app@<:@=PREFIX@:>@], [Path to liblvm2app.])], [ - if test "x$withval" != "xno" && test "x$withval" != "xyes" - then - with_liblvm2app_cppflags="-I$withval/include" - with_liblvm2app_ldflags="-L$withval/lib" - with_liblvm2app="yes" - else - with_liblvm2app="$withval" + if test "x$withval" = "xno" + then + with_liblvm2app="no" + else + with_liblvm2app="yes" + if test "x$withval" != "xyes" + then + with_liblvm2app_cppflags="-I$withval/include" + with_liblvm2app_ldflags="-L$withval/lib" + fi fi ], [ - with_liblvm2app="yes" + if test "x$ac_system" = "xLinux" + then + with_liblvm2app="yes" + else + with_liblvm2app="no (Linux only library)" + fi ]) if test "x$with_liblvm2app" = "xyes" then @@ -2588,13 +2982,6 @@ AC_ARG_WITH(libmodbus, [AS_HELP_STRING([--with-libmodbus@<:@=PREFIX@:>@], [Path # configure using pkg-config if test "x$with_libmodbus" = "xuse_pkgconfig" then - if test "x$PKG_CONFIG" = "x" - then - with_libmodbus="no (Don't have pkg-config)" - fi -fi -if test "x$with_libmodbus" = "xuse_pkgconfig" -then AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG]) $PKG_CONFIG --exists 'libmodbus' 2>/dev/null if test $? -ne 0 @@ -2718,31 +3105,80 @@ fi AM_CONDITIONAL(BUILD_WITH_LIBMONGOC, test "x$with_libmongoc" = "xyes") # }}} -# --with-libmysql {{{ -with_mysql_config="mysql_config" -with_mysql_cflags="" -with_mysql_libs="" -AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])], +# --with-libmosquitto {{{ +with_libmosquitto_cppflags="" +with_libmosquitto_ldflags="" +AC_ARG_WITH(libmosquitto, [AS_HELP_STRING([--with-libmosquitto@<:@=PREFIX@:>@], [Path to libmosquitto.])], [ - if test "x$withval" = "xno" - then - with_libmysql="no" - else if test "x$withval" = "xyes" + if test "x$withval" != "xno" && test "x$withval" != "xyes" then - with_libmysql="yes" + with_libmosquitto_cppflags="-I$withval/include" + with_libmosquitto_ldflags="-L$withval/lib" + with_libmosquitto="yes" else - if test -f "$withval" && test -x "$withval"; - then - with_mysql_config="$withval" - else if test -x "$withval/bin/mysql_config" - then - with_mysql_config="$withval/bin/mysql_config" - fi; fi - with_libmysql="yes" - fi; fi + with_libmosquitto="$withval" + fi ], [ - with_libmysql="yes" + with_libmosquitto="yes" +]) +if test "x$with_libmosquitto" = "xyes" +then + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags" + + AC_CHECK_HEADERS(mosquitto.h, [with_libmosquitto="yes"], [with_libmosquitto="no (mosquitto.h not found)"]) + + CPPFLAGS="$SAVE_CPPFLAGS" +fi +if test "x$with_libmosquitto" = "xyes" +then + SAVE_LDFLAGS="$LDFLAGS" + SAVE_CPPFLAGS="$CPPFLAGS" + LDFLAGS="$LDFLAGS $with_libmosquitto_ldflags" + CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags" + + AC_CHECK_LIB(mosquitto, mosquitto_connect, [with_libmosquitto="yes"], [with_libmosquitto="no (libmosquitto not found)"]) + + LDFLAGS="$SAVE_LDFLAGS" + CPPFLAGS="$SAVE_CPPFLAGS" +fi +if test "x$with_libmosquitto" = "xyes" +then + BUILD_WITH_LIBMOSQUITTO_CPPFLAGS="$with_libmosquitto_cppflags" + BUILD_WITH_LIBMOSQUITTO_LDFLAGS="$with_libmosquitto_ldflags" + BUILD_WITH_LIBMOSQUITTO_LIBS="-lmosquitto" + AC_SUBST(BUILD_WITH_LIBMOSQUITTO_CPPFLAGS) + AC_SUBST(BUILD_WITH_LIBMOSQUITTO_LDFLAGS) + AC_SUBST(BUILD_WITH_LIBMOSQUITTO_LIBS) +fi +# }}} + +# --with-libmysql {{{ +with_mysql_config="mysql_config" +with_mysql_cflags="" +with_mysql_libs="" +AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])], +[ + if test "x$withval" = "xno" + then + with_libmysql="no" + else if test "x$withval" = "xyes" + then + with_libmysql="yes" + else + if test -f "$withval" && test -x "$withval"; + then + with_mysql_config="$withval" + else if test -x "$withval/bin/mysql_config" + then + with_mysql_config="$withval/bin/mysql_config" + fi; fi + with_libmysql="yes" + fi; fi +], +[ + with_libmysql="yes" ]) if test "x$with_libmysql" = "xyes" then @@ -2836,10 +3272,6 @@ AC_ARG_WITH(libmnl, [AS_HELP_STRING([--with-libmnl@<:@=PREFIX@:>@], [Path to lib with_libmnl="no (Linux only library)" fi ]) -if test "x$PKG_CONFIG" = "x" -then - with_libmnl="no (Don't have pkg-config)" -fi if test "x$with_libmnl" = "xyes" then if $PKG_CONFIG --exists libmnl 2>/dev/null; then @@ -2970,7 +3402,7 @@ then if test "x$LIBNETAPP_LIBS" = "x" then - LIBNETAPP_LIBS="-lpthread -lxml -ladt -lssl -lm -lcrypto -lz" + LIBNETAPP_LIBS="$PTHREAD_LIBS -lxml -ladt -lssl -lm -lcrypto -lz" fi AC_MSG_NOTICE([netapp LIBS: $LIBNETAPP_LIBS]) @@ -2996,9 +3428,6 @@ AM_CONDITIONAL(BUILD_WITH_LIBNETAPP, test "x$with_libnetapp" = "xyes") # }}} # --with-libnetsnmp {{{ -with_snmp_config="net-snmp-config" -with_snmp_cflags="" -with_snmp_libs="" AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])], [ if test "x$withval" = "xno" @@ -3008,57 +3437,42 @@ AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Pat then with_libnetsnmp="yes" else - if test -x "$withval" - then - with_snmp_config="$withval" - with_libnetsnmp="yes" - else - with_snmp_config="$withval/bin/net-snmp-config" - with_libnetsnmp="yes" - fi + with_libnetsnmp_cppflags="-I$withval/include" + with_libnetsnmp_ldflags="-I$withval/lib" + with_libnetsnmp="yes" fi; fi ], [with_libnetsnmp="yes"]) if test "x$with_libnetsnmp" = "xyes" then - with_snmp_cflags=`$with_snmp_config --cflags 2>/dev/null` - snmp_config_status=$? - - if test $snmp_config_status -ne 0 - then - with_libnetsnmp="no ($with_snmp_config failed)" - else - SAVE_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $with_snmp_cflags" + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libnetsnmp_cppflags" - AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]) + AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]) - CPPFLAGS="$SAVE_CPPFLAGS" - fi + CPPFLAGS="$SAVE_CPPFLAGS" fi if test "x$with_libnetsnmp" = "xyes" then - with_snmp_libs=`$with_snmp_config --libs 2>/dev/null` - snmp_config_status=$? + SAVE_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags" - if test $snmp_config_status -ne 0 - then - with_libnetsnmp="no ($with_snmp_config failed)" - else - AC_CHECK_LIB(netsnmp, init_snmp, + AC_CHECK_LIB(netsnmp, init_snmp, [with_libnetsnmp="yes"], [with_libnetsnmp="no (libnetsnmp not found)"], [$with_snmp_libs]) - fi + + LDFLAGS="$SAVE_LDFLAGS" fi if test "x$with_libnetsnmp" = "xyes" then - BUILD_WITH_LIBSNMP_CFLAGS="$with_snmp_cflags" - BUILD_WITH_LIBSNMP_LIBS="$with_snmp_libs" - AC_SUBST(BUILD_WITH_LIBSNMP_CFLAGS) - AC_SUBST(BUILD_WITH_LIBSNMP_LIBS) + BUILD_WITH_LIBNETSNMP_CPPFLAGS="$with_libnetsnmp_cppflags" + BUILD_WITH_LIBNETSNMP_LDFLAGS="$with_libnetsnmp_ldflags" + BUILD_WITH_LIBNETSNMP_LIBS="-lnetsnmp" fi -AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes") +AC_SUBST(BUILD_WITH_LIBNETSNMP_CPPFLAGS) +AC_SUBST(BUILD_WITH_LIBNETSNMP_LDFLAGS) +AC_SUBST(BUILD_WITH_LIBNETSNMP_LIBS) # }}} # --with-liboconfig {{{ @@ -3091,7 +3505,7 @@ save_LDFLAGS="$LDFLAGS" save_CPPFLAGS="$CPPFLAGS" LDFLAGS="$liboconfig_LDFLAGS" CPPFLAGS="$liboconfig_CPPFLAGS" -AC_CHECK_LIB(oconfig, oconfig_parse_fh, +AC_CHECK_LIB(oconfig, oconfig_parse_file, [ with_liboconfig="yes" with_own_liboconfig="no" @@ -3229,22 +3643,22 @@ then fi if test "x$with_oracle" = "xyes" then - BUILD_WITH_ORACLE_CFLAGS="$with_oracle_cppflags" + BUILD_WITH_ORACLE_CPPFLAGS="$with_oracle_cppflags" BUILD_WITH_ORACLE_LIBS="$with_oracle_libs" - AC_SUBST(BUILD_WITH_ORACLE_CFLAGS) + AC_SUBST(BUILD_WITH_ORACLE_CPPFLAGS) AC_SUBST(BUILD_WITH_ORACLE_LIBS) fi # }}} # --with-libowcapi {{{ with_libowcapi_cppflags="" -with_libowcapi_libs="-lowcapi" +with_libowcapi_ldflags="" AC_ARG_WITH(libowcapi, [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path to libowcapi.])], [ if test "x$withval" != "xno" && test "x$withval" != "xyes" then with_libowcapi_cppflags="-I$withval/include" - with_libowcapi_libs="-L$withval/lib -lowcapi" + with_libowcapi_ldflags="-L$withval/lib" with_libowcapi="yes" else with_libowcapi="$withval" @@ -3256,7 +3670,7 @@ AC_ARG_WITH(libowcapi, [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path if test "x$with_libowcapi" = "xyes" then SAVE_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$with_libowcapi_cppflags" + CPPFLAGS="$CPPFLAGS $with_libowcapi_cppflags" AC_CHECK_HEADERS(owcapi.h, [with_libowcapi="yes"], [with_libowcapi="no (owcapi.h not found)"]) @@ -3266,7 +3680,7 @@ if test "x$with_libowcapi" = "xyes" then SAVE_LDFLAGS="$LDFLAGS" SAVE_CPPFLAGS="$CPPFLAGS" - LDFLAGS="$with_libowcapi_libs" + LDFLAGS="$LDFLAGS $with_libowcapi_ldflags" CPPFLAGS="$with_libowcapi_cppflags" AC_CHECK_LIB(owcapi, OW_get, [with_libowcapi="yes"], [with_libowcapi="no (libowcapi not found)"]) @@ -3277,8 +3691,10 @@ fi if test "x$with_libowcapi" = "xyes" then BUILD_WITH_LIBOWCAPI_CPPFLAGS="$with_libowcapi_cppflags" - BUILD_WITH_LIBOWCAPI_LIBS="$with_libowcapi_libs" + BUILD_WITH_LIBOWCAPI_LDFLAGS="$with_libowcapi_ldflags" + BUILD_WITH_LIBOWCAPI_LIBS="-lowcapi" AC_SUBST(BUILD_WITH_LIBOWCAPI_CPPFLAGS) + AC_SUBST(BUILD_WITH_LIBOWCAPI_LDFLAGS) AC_SUBST(BUILD_WITH_LIBOWCAPI_LIBS) fi # }}} @@ -3373,7 +3789,7 @@ then SAVE_CFLAGS="$CFLAGS" SAVE_LIBS="$LIBS" dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string) - PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ccopts` + PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e perl_inc` PERL_LIBS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ldopts` CFLAGS="$CFLAGS $PERL_CFLAGS" LIBS="$LIBS $PERL_LIBS" @@ -3607,161 +4023,197 @@ fi AM_CONDITIONAL(BUILD_WITH_LIBPQ, test "x$with_libpq" = "xyes") # }}} -# --with-libpthread {{{ -AC_ARG_WITH(libpthread, [AS_HELP_STRING([--with-libpthread=@<:@=PREFIX@:>@], [Path to libpthread.])], -[ if test "x$withval" != "xno" \ - && test "x$withval" != "xyes" - then - LDFLAGS="$LDFLAGS -L$withval/lib" - CPPFLAGS="$CPPFLAGS -I$withval/include" - with_libpthread="yes" - else - if test "x$withval" = "xno" - then - with_libpthread="no (disabled)" - fi - fi -], [with_libpthread="yes"]) -if test "x$with_libpthread" = "xyes" +# --with-libprotobuf {{{ +with_libprotobuf_cppflags="" +with_libprotobuf_ldflags="" +AC_ARG_WITH([libprotobuf], [AS_HELP_STRING([--with-libprotobuf@<:@=PREFIX@:>@], [Path to libprotobuf.])], + [ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libprotobuf_cppflags="-I$withval/include" + with_libprotobuf_ldflags="-L$withval/lib" + with_libprotobuf="yes" + fi + if test "x$withval" = "xno" + then + with_libprotobuf="no (disabled on command line)" + fi + ], + [withval="yes"] +) +if test "x$withval" = "xyes" then - AC_CHECK_LIB(pthread, pthread_create, [with_libpthread="yes"], [with_libpthread="no (libpthread not found)"], []) +PKG_CHECK_MODULES([PROTOBUF], [protobuf], + [with_libprotobuf="yes"], + [with_libprotobuf="no (pkg-config could not find libprotobuf)"] +) fi -if test "x$with_libpthread" = "xyes" -then - AC_CHECK_HEADERS(pthread.h,, [with_libpthread="no (pthread.h not found)"]) -fi -if test "x$with_libpthread" = "xyes" +if test "x$withval" != "xno" then - collect_pthread=1 -else - collect_pthread=0 + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + LDFLAGS="$with_libprotobuf_ldflags" + LIBS="$PROTOBUF_LIBS $LIBS" + AC_LANG_PUSH([C++]) + AC_CHECK_LIB([protobuf], [main], + [ + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$with_libprotobuf_cppflags $PROTOBUF_CFLAGS" + if test "x$PROTOBUF_LIBS" = "x" + then + PROTOBUF_LIBS="-lprotobuf" + fi + AC_CHECK_HEADERS([google/protobuf/util/time_util.h], + [with_libprotobuf="yes"], + [with_libprotobuf="no ( not found)"] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + ], + [with_libprotobuf="no (libprotobuf not found)"] + ) + AC_LANG_POP([C++]) + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" fi -AC_DEFINE_UNQUOTED(HAVE_LIBPTHREAD, [$collect_pthread], - [Wether or not to use pthread (POSIX threads) library]) -AM_CONDITIONAL(BUILD_WITH_LIBPTHREAD, test "x$with_libpthread" = "xyes") +BUILD_WITH_LIBPROTOBUF_CPPFLAGS="$with_libprotobuf_cppflags $PROTOBUF_CFLAGS" +BUILD_WITH_LIBPROTOBUF_LDFLAGS="$with_libprotobuf_ldflags" +BUILD_WITH_LIBPROTOBUF_LIBS="$PROTOBUF_LIBS" +AC_SUBST([BUILD_WITH_LIBPROTOBUF_CPPFLAGS]) +AC_SUBST([BUILD_WITH_LIBPROTOBUF_LDFLAGS]) +AC_SUBST([BUILD_WITH_LIBPROTOBUF_LIBS]) # }}} -# --with-python {{{ -with_python_prog="" -with_python_path="$PATH" -AC_ARG_WITH(python, [AS_HELP_STRING([--with-python@<:@=PREFIX@:>@], [Path to the python interpreter.])], -[ - if test "x$withval" = "xyes" || test "x$withval" = "xno" - then - with_python="$withval" - else if test -x "$withval" - then - with_python_prog="$withval" - with_python_path="`dirname \"$withval\"`$PATH_SEPARATOR$with_python_path" - with_python="yes" - else if test -d "$withval" - then - with_python_path="$withval$PATH_SEPARATOR$with_python_path" - with_python="yes" - else - AC_MSG_WARN([Argument not recognized: $withval]) - fi; fi; fi -], [with_python="yes"]) - -SAVE_PATH="$PATH" -SAVE_CPPFLAGS="$CPPFLAGS" -SAVE_LDFLAGS="$LDFLAGS" -SAVE_LIBS="$LIBS" - -PATH="$with_python_path" - -if test "x$with_python" = "xyes" && test "x$with_python_prog" = "x" -then - AC_MSG_CHECKING([for python]) - with_python_prog="`which python 2>/dev/null`" - if test "x$with_python_prog" = "x" - then - AC_MSG_RESULT([not found]) - with_python="no (interpreter not found)" - else - AC_MSG_RESULT([$with_python_prog]) - fi -fi - -if test "x$with_python" = "xyes" -then - AC_MSG_CHECKING([for Python CPPFLAGS]) - python_include_path=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_python_inc())" | "$with_python_prog" 2>&1` - python_config_status=$? - - if test "$python_config_status" -ne 0 || test "x$python_include_path" = "x" - then - AC_MSG_RESULT([failed with status $python_config_status (output: $python_include_path)]) - with_python="no" - else - AC_MSG_RESULT([$python_include_path]) - fi -fi - -if test "x$with_python" = "xyes" +# --with-libprotobuf-c {{{ +with_libprotobuf_c_cppflags="" +with_libprotobuf_c_ldflags="" +AC_ARG_WITH([libprotobuf-c], [AS_HELP_STRING([--with-libprotobuf-c@<:@=PREFIX@:>@], [Path to libprotobuf-c.])], + [ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libprotobuf_c_cppflags="-I$withval/include" + with_libprotobuf_c_ldflags="-L$withval/lib" + with_libprotobuf_c="yes" + fi + if test "x$withval" = "xno" + then + with_libprotobuf_c="no (disabled on command line)" + fi + ], + [withval="yes"] +) +if test "x$withval" = "xyes" then - CPPFLAGS="-I$python_include_path $CPPFLAGS" - AC_CHECK_HEADERS(Python.h, - [with_python="yes"], - [with_python="no ('Python.h' not found)"]) +PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c], + [with_libprotobuf_c="yes"], + [with_libprotobuf_c="no (pkg-config could not find libprotobuf-c)"] +) fi -if test "x$with_python" = "xyes" +if test "x$withval" != "xno" then - AC_MSG_CHECKING([for Python LDFLAGS]) - python_library_path=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_config_vars(\"LIBDIR\").__getitem__(0))" | "$with_python_prog" 2>&1` - python_config_status=$? - - if test "$python_config_status" -ne 0 || test "x$python_library_path" = "x" - then - AC_MSG_RESULT([failed with status $python_config_status (output: $python_library_path)]) - with_python="no" - else - AC_MSG_RESULT([$python_library_path]) - fi + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + LDFLAGS="$with_libprotobuf_c_ldflags" + LIBS="$PROTOBUF_C_LIBS $LIBS" + AC_CHECK_LIB([protobuf-c], [protobuf_c_message_pack], + [ + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$with_libprotobuf_c_cppflags $PROTOBUF_C_CFLAGS" + if test "x$PROTOBUF_C_LIBS" = "x" + then + PROTOBUF_C_LIBS="-lprotobuf-c" + fi + AC_CHECK_HEADERS([protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c.h], + [ + with_libprotobuf_c="yes" + break + ], + [with_libprotobuf_c="no ( not found)"] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + ], + [with_libprotobuf_c="no (libprotobuf-c not found)"] + ) + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" fi +BUILD_WITH_LIBPROTOBUF_C_CPPFLAGS="$with_libprotobuf_c_cppflags $PROTOBUF_C_CFLAGS" +BUILD_WITH_LIBPROTOBUF_C_LDFLAGS="$with_libprotobuf_c_ldflags" +BUILD_WITH_LIBPROTOBUF_C_LIBS="$PROTOBUF_C_LIBS" +AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_CPPFLAGS]) +AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_LDFLAGS]) +AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_LIBS]) +# }}} -if test "x$with_python" = "xyes" -then - AC_MSG_CHECKING([for Python LIBS]) - python_library_flags=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_config_vars(\"BLDLIBRARY\").__getitem__(0))" | "$with_python_prog" 2>&1` - python_config_status=$? +# --with-libpython {{{ +AC_ARG_VAR([LIBPYTHON_CPPFLAGS], [Preprocessor flags for libpython]) +AC_ARG_VAR([LIBPYTHON_LDFLAGS], [Linker flags for libpython]) +AC_ARG_VAR([LIBPYTHON_LIBS], [Libraries for libpython]) - if test "$python_config_status" -ne 0 || test "x$python_library_flags" = "x" - then - AC_MSG_RESULT([failed with status $python_config_status (output: $python_library_flags)]) - with_python="no" - else - AC_MSG_RESULT([$python_library_flags]) - fi +AC_ARG_WITH([libpython], + [AS_HELP_STRING([--with-libpython], + [if we should build with libpython @<:@default=yes@:>@]) + ], + [with_libpython="$withval"], + [with_libpython="check"] +) +if test "$with_libpython" != "no"; then + if test "$LIBPYTHON_CPPFLAGS" = "" && test "$LIBPYTHON_LDFLAGS" = ""; then + AC_ARG_VAR([PYTHON_CONFIG], [path to python-config]) + AC_PATH_PROGS([PYTHON_CONFIG], + [python3-config python2-config python-config] + ) + if test "$PYTHON_CONFIG" = ""; then + if test "$with_libpython" = "yes"; then + AC_MSG_ERROR([Unable to find python-config]) + fi + with_libpython="no" + fi + fi fi -if test "x$with_python" = "xyes" -then - LDFLAGS="-L$python_library_path $LDFLAGS" - LIBS="$python_library_flags $LIBS" - - AC_CHECK_FUNC(PyObject_CallFunction, - [with_python="yes"], - [with_python="no (Symbol 'PyObject_CallFunction' not found)"]) +if test "$PYTHON_CONFIG" != ""; then + LIBPYTHON_CPPFLAGS="`${PYTHON_CONFIG} --includes`" + if test $? -ne 0; then + with_libpython="no" + fi + LIBPYTHON_LDFLAGS="`${PYTHON_CONFIG} --ldflags`" + if test $? -ne 0; then + with_libpython="no" + fi + LIBPYTHON_LIBS="`${PYTHON_CONFIG} --libs`" + if test $? -ne 0; then + with_libpython="no" + fi fi -PATH="$SAVE_PATH" -CPPFLAGS="$SAVE_CPPFLAGS" -LDFLAGS="$SAVE_LDFLAGS" -LIBS="$SAVE_LIBS" - -if test "x$with_python" = "xyes" -then - BUILD_WITH_PYTHON_CPPFLAGS="-I$python_include_path" - BUILD_WITH_PYTHON_LDFLAGS="-L$python_library_path" - BUILD_WITH_PYTHON_LIBS="$python_library_flags" - AC_SUBST(BUILD_WITH_PYTHON_CPPFLAGS) - AC_SUBST(BUILD_WITH_PYTHON_LDFLAGS) - AC_SUBST(BUILD_WITH_PYTHON_LIBS) +if test "$with_libpython" != "xno"; then + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + CPPFLAGS="$LIBPYTHON_CPPFLAGS $CPPFLAGS" + LDFLAGS="$LIBPYTHON_LDFLAGS $LDFLAGS" + LIBS="$LIBPYTHON_LIBS $LIBS" + AC_CHECK_HEADERS([Python.h], + [ + AC_MSG_CHECKING([for libpython]) + AC_LINK_IFELSE([AC_LANG_PROGRAM( + [[#include ]], + [[Py_Initialize();]]) + ], + [with_libpython="yes"], + [with_libpython="no"] + ) + AC_MSG_RESULT([$with_libpython]) + ], + [with_libpython="no"] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" fi -# }}} --with-python +# }}} --with-libpython # --with-librabbitmq {{{ with_librabbitmq_cppflags="" @@ -4114,11 +4566,6 @@ then SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $with_sensors_cflags" -# AC_CHECK_HEADERS(sensors/sensors.h, -# [ -# AC_DEFINE(HAVE_SENSORS_SENSORS_H, 1, [Define to 1 if you have the header file.]) -# ], -# [with_libsensors="no (sensors/sensors.h not found)"]) AC_CHECK_HEADERS(sensors/sensors.h, [], [with_libsensors="no (sensors/sensors.h not found)"]) CPPFLAGS="$SAVE_CPPFLAGS" @@ -4149,74 +4596,13 @@ fi AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_libsensors" = "xyes") # }}} -# --with-libsigrok {{{ -with_libsigrok_cflags="" -with_libsigrok_ldflags="" -AC_ARG_WITH(libsigrok, [AS_HELP_STRING([--with-libsigrok@<:@=PREFIX@:>@], [Path to libsigrok.])], -[ - if test "x$withval" = "xno" - then - with_libsigrok="no" - else - with_libsigrok="yes" - if test "x$withval" != "xyes" - then - with_libsigrok_cflags="-I$withval/include" - with_libsigrok_ldflags="-L$withval/lib" - fi - fi -],[with_libsigrok="yes"]) - -# libsigrok has a glib dependency -if test "x$with_libsigrok" = "xyes" -then -m4_ifdef([AM_PATH_GLIB_2_0], - [ - AM_PATH_GLIB_2_0([2.28.0], - [with_libsigrok_cflags="$with_libsigrok_cflags $GLIB_CFLAGS"; with_libsigrok_ldflags="$with_libsigrok_ldflags $GLIB_LIBS"]) - ], - [ - with_libsigrok="no (glib not available)" - ] +# libsigrok {{{ +AC_SUBST([LIBSIGROK_CFLAGS]) +AC_SUBST([LIBSIGROK_LIBS]) +PKG_CHECK_MODULES([LIBSIGROK], [libsigrok < 0.4], + [with_libsigrok="yes"], + [with_libsigrok="no (pkg-config could not find libsigrok)"] ) -fi - -# libsigrok headers -if test "x$with_libsigrok" = "xyes" -then - SAVE_CPPFLAGS="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags" - - AC_CHECK_HEADERS(libsigrok/libsigrok.h, [], [with_libsigrok="no (libsigrok/libsigrok.h not found)"]) - - CPPFLAGS="$SAVE_CPPFLAGS" -fi - -# libsigrok library -if test "x$with_libsigrok" = "xyes" -then - SAVE_CPPFLAGS="$CPPFLAGS" - SAVE_LDFLAGS="$LDFLAGS" - CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags" - LDFLAGS="$LDFLAGS $with_libsigrok_ldflags" - - AC_CHECK_LIB(sigrok, sr_init, - [ - AC_DEFINE(HAVE_LIBSIGROK, 1, [Define to 1 if you have the sigrok library (-lsigrok).]) - ], - [with_libsigrok="no (libsigrok not found)"]) - - CPPFLAGS="$SAVE_CPPFLAGS" - LDFLAGS="$SAVE_LDFLAGS" -fi -if test "x$with_libsigrok" = "xyes" -then - BUILD_WITH_LIBSIGROK_CFLAGS="$with_libsigrok_cflags" - BUILD_WITH_LIBSIGROK_LDFLAGS="$with_libsigrok_ldflags" - AC_SUBST(BUILD_WITH_LIBSIGROK_CFLAGS) - AC_SUBST(BUILD_WITH_LIBSIGROK_LDFLAGS) -fi -AM_CONDITIONAL(BUILD_WITH_LIBSIGROK, test "x$with_libsigrok" = "xyes") # }}} # --with-libstatgrab {{{ @@ -4244,23 +4630,16 @@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [P if test "x$with_libstatgrab" = "xyes" \ && test "x$with_libstatgrab_pkg_config" = "xyes" then - if test "x$PKG_CONFIG" != "x" + AC_MSG_CHECKING([pkg-config for libstatgrab]) + temp_result="found" + $PKG_CONFIG --exists libstatgrab 2>/dev/null + if test "$?" != "0" then - AC_MSG_CHECKING([pkg-config for libstatgrab]) - temp_result="found" - $PKG_CONFIG --exists libstatgrab 2>/dev/null - if test "$?" != "0" - then - with_libstatgrab_pkg_config="no" - with_libstatgrab="no (pkg-config doesn't know libstatgrab)" - temp_result="not found" - fi - AC_MSG_RESULT([$temp_result]) - else - AC_MSG_NOTICE([pkg-config not available, trying to guess flags for the statgrab library.]) with_libstatgrab_pkg_config="no" - with_libstatgrab_ldflags="$with_libstatgrab_ldflags -lstatgrab" + with_libstatgrab="no (pkg-config doesn't know libstatgrab)" + temp_result="not found" fi + AC_MSG_RESULT([$temp_result]) fi if test "x$with_libstatgrab" = "xyes" \ @@ -4326,6 +4705,7 @@ fi if test "x$with_libstatgrab" = "xyes" then SAVE_CFLAGS="$CFLAGS" + SAVE_LDFLAGS="$LDFLAGS" SAVE_LIBS="$LIBS" CFLAGS="$CFLAGS $with_libstatgrab_cflags" @@ -4558,13 +4938,6 @@ fi # configure using pkg-config if test "x$with_libupsclient" = "xuse_pkgconfig" then - if test "x$PKG_CONFIG" = "x" - then - with_libupsclient="no (Don't have pkg-config)" - fi -fi -if test "x$with_libupsclient" = "xuse_pkgconfig" -then AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG]) $PKG_CONFIG --exists 'libupsclient' 2>/dev/null if test $? -ne 0 @@ -4637,6 +5010,51 @@ then fi # }}} +# --with-libxenctrl {{{ +with_libxenctrl_cppflags="" +with_libxenctrl_ldflags="" +AC_ARG_WITH(libxenctrl, [AS_HELP_STRING([--with-libxenctrl@<:@=PREFIX@:>@], [Path to libxenctrl.])], +[ + if test "x$withval" != "xno" && test "x$withval" != "xyes" + then + with_libxenctrl_cppflags="-I$withval/include" + with_libxenctrl_ldflags="-L$withval/lib" + with_libxenctrl="yes" + else + with_libxenctrl="$withval" + fi +], +[ + with_libxenctrl="yes" +]) +if test "x$with_libxenctrl" = "xyes" +then + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags" + + AC_CHECK_HEADERS(xenctrl.h, [with_libxenctrl="yes"], [with_libxenctrl="no (xenctrl.h not found)"]) + + CPPFLAGS="$SAVE_CPPFLAGS" +fi +if test "x$with_libxenctrl" = "xyes" +then + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags" + LDFLAGS="$LDFLAGS $with_libxenctrl_ldflags" + + #Xen versions older than 3.4 has no xc_getcpuinfo() + AC_CHECK_LIB(xenctrl, xc_getcpuinfo, [with_libxenctrl="yes"], [with_libxenctrl="no (symbol 'xc_getcpuinfo' not found)"], []) + + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" + LIBXENCTL_CPPFLAGS="$with_libxenctl_cppflags" + LIBXENCTL_LDFLAGS="$with_libxenctl_ldflags" + AC_SUBST(LIBXENCTL_CPPFLAGS) + AC_SUBST(LIBXENCTL_LDFLAGS) +fi +# }}} + # --with-libxmms {{{ with_xmms_config="xmms-config" with_xmms_cflags="" @@ -4776,7 +5194,7 @@ AC_ARG_WITH(mic,[AS_HELP_STRING([--with-mic@<:@=PREFIX@:>@], [Path to Intel MIC AC_MSG_NOTICE([Not checking for Intel Mic: Manually configured]) with_mic_cflags="-I$withval/include" with_mic_ldpath="-L$withval/lib/Linux" - with_mic_libs="-lMicAccessSDK -lscif -lpthread" + with_mic_libs="$PTHREAD_LIBS -lMicAccessSDK -lscif" with_mic="yes" fi; fi; fi ], @@ -4798,8 +5216,8 @@ then AC_CHECK_LIB(MicAccessSDK, MicInitAPI, [with_mic_ldpath="$with_mic_ldpath" - with_mic_libs="-lMicAccessSDK -lscif -lpthread"], - [with_mic="no (symbol MicInitAPI not found)"],[-lscif -lpthread]) + with_mic_libs="$PTHREAD_LIBS -lMicAccessSDK -lscif"], + [with_mic="no (symbol MicInitAPI not found)"],[$PTHREAD_LIBS -lscif]) CPPFLAGS="$SAVE_CPPFLAGS" LDFLAGS="$SAVE_LDFLAGS" @@ -4841,13 +5259,6 @@ AC_ARG_WITH(libvarnish, [AS_HELP_STRING([--with-libvarnish@<:@=PREFIX@:>@], [Pat # configure using pkg-config if test "x$with_libvarnish" = "xuse_pkgconfig" then - if test "x$PKG_CONFIG" = "x" - then - with_libvarnish="no (Don't have pkg-config)" - fi -fi -if test "x$with_libvarnish" = "xuse_pkgconfig" -then AC_MSG_NOTICE([Checking for varnishapi using $PKG_CONFIG]) $PKG_CONFIG --exists 'varnishapi' 2>/dev/null if test $? -ne 0 @@ -4907,23 +5318,20 @@ with_libxml2_ldflags="" with_libvirt="no (pkg-config isn't available)" with_libvirt_cflags="" with_libvirt_ldflags="" -if test "x$PKG_CONFIG" != "x" +$PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null +if test "$?" = "0" then - $PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null - if test "$?" = "0" - then - with_libxml2="yes" - else - with_libxml2="no (pkg-config doesn't know libxml-2.0)" - fi + with_libxml2="yes" +else + with_libxml2="no (pkg-config doesn't know libxml-2.0)" +fi - $PKG_CONFIG --exists libvirt 2>/dev/null - if test "$?" = "0" - then - with_libvirt="yes" - else - with_libvirt="no (pkg-config doesn't know libvirt)" - fi +$PKG_CONFIG --exists libvirt 2>/dev/null +if test "$?" = "0" +then + with_libvirt="yes" +else + with_libvirt="no (pkg-config doesn't know libvirt)" fi if test "x$with_libxml2" = "xyes" then @@ -5022,17 +5430,6 @@ with_libopenipmipthread="yes" with_libopenipmipthread_cflags="" with_libopenipmipthread_libs="" -AC_MSG_CHECKING([for pkg-config]) -temp_result="no" -if test "x$PKG_CONFIG" = "x" -then - with_libopenipmipthread="no" - temp_result="no" -else - temp_result="$PKG_CONFIG" -fi -AC_MSG_RESULT([$temp_result]) - if test "x$with_libopenipmipthread" = "xyes" then AC_MSG_CHECKING([for libOpenIPMIpthread]) @@ -5156,11 +5553,12 @@ AM_CONDITIONAL(BUILD_WITH_LIBATASMART, test "x$with_libatasmart" = "xyes") PKG_CHECK_MODULES([LIBNOTIFY], [libnotify], [with_libnotify="yes"], - [if test "x$LIBNOTIFY_PKG_ERRORS" = "x"; then - with_libnotify="no" - else - with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)" - fi]) + [with_libnotify="no (pkg-config doesn't know libnotify)"] +) + +PKG_CHECK_MODULES([LIBRIEMANN_CLIENT], [riemann-client >= 1.6.0], + [with_libriemann_client="yes"], + [with_libriemann_client="no (pkg-config doesn't know libriemann-client)"]) # Check for enabled/disabled features # @@ -5253,7 +5651,7 @@ AC_DEFUN( then enable_plugin="yes" else - enable_plugin="no" + enable_plugin="$2" fi else enable_plugin="$enable_all_plugins" @@ -5270,7 +5668,7 @@ AC_DEFUN( fi else # User passed "yes" but dependency checking yielded "no" => Dependency problem. dependency_error="yes" - enable_plugin="no (dependency error)" + enable_plugin="$2 (dependency error)" fi fi AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), test "x$enable_plugin" = "xyes") @@ -5284,6 +5682,7 @@ collectd features:]) AC_COLLECTD([debug], [enable], [feature], [debugging]) AC_COLLECTD([daemon], [disable], [feature], [daemon mode]) AC_COLLECTD([getifaddrs],[enable], [feature], [getifaddrs under Linux]) +AC_COLLECTD([werror], [disable], [feature], [building with -Werror]) dependency_warning="no" dependency_error="no" @@ -5298,6 +5697,7 @@ plugin_conntrack="no" plugin_contextswitch="no" plugin_cpu="no" plugin_cpufreq="no" +plugin_cpusleep="no" plugin_curl_json="no" plugin_curl_xml="no" plugin_df="no" @@ -5307,6 +5707,8 @@ plugin_entropy="no" plugin_ethstat="no" plugin_fhcount="no" plugin_fscache="no" +plugin_gps="no" +plugin_grpc="no" plugin_interface="no" plugin_ipmi="no" plugin_ipvs="no" @@ -5318,8 +5720,10 @@ plugin_multimeter="no" plugin_nfs="no" plugin_numa="no" plugin_perl="no" +plugin_pinba="no" plugin_processes="no" plugin_protocols="no" +plugin_python="no" plugin_serial="no" plugin_smart="no" plugin_swap="no" @@ -5334,16 +5738,18 @@ plugin_virt="no" plugin_vmem="no" plugin_vserver="no" plugin_wireless="no" +plugin_xencpu="no" plugin_zfs_arc="no" +plugin_zone="no" plugin_zookeeper="no" # Linux if test "x$ac_system" = "xLinux" then plugin_battery="yes" + plugin_cgroups="yes" plugin_conntrack="yes" plugin_contextswitch="yes" - plugin_cgroups="yes" plugin_cpu="yes" plugin_cpufreq="yes" plugin_disk="yes" @@ -5379,6 +5785,11 @@ then then plugin_turbostat="yes" fi + + if test "x$c_cv_have_clock_boottime_monotonic" = "xyes" + then + plugin_cpusleep="yes" + fi fi if test "x$ac_system" = "xOpenBSD" @@ -5386,6 +5797,14 @@ then plugin_tcpconns="yes" fi +if test "x$ac_system" = "xNetBSD" +then + plugin_disk="yes" + plugin_entropy="yes" + plugin_irq="yes" + plugin_processes="yes" +fi + # Mac OS X devices if test "x$with_libiokit" = "xyes" then @@ -5397,27 +5816,28 @@ fi if test "x$ac_system" = "xAIX" then - plugin_tcpconns="yes" plugin_ipc="yes" + plugin_tcpconns="yes" fi # FreeBSD if test "x$ac_system" = "xFreeBSD" then + plugin_disk="yes" plugin_zfs_arc="yes" fi if test "x$with_perfstat" = "xyes" then - plugin_cpu="yes" plugin_contextswitch="yes" + plugin_cpu="yes" plugin_disk="yes" - plugin_memory="yes" - plugin_swap="yes" plugin_interface="yes" plugin_load="yes" + plugin_memory="yes" + plugin_swap="yes" plugin_uptime="yes" fi @@ -5433,6 +5853,7 @@ then plugin_processes="yes" plugin_uptime="yes" plugin_zfs_arc="yes" + plugin_zone="yes" fi if test "x$with_devinfo$with_kstat" = "xyesyes" @@ -5445,7 +5866,6 @@ then fi # libi2c-dev -with_libi2c="no" if test "x$ac_system" = "xLinux" then AC_CHECK_DECL(i2c_smbus_read_i2c_block_data, @@ -5453,6 +5873,8 @@ AC_CHECK_DECL(i2c_smbus_read_i2c_block_data, [with_libi2c="no (symbol i2c_smbus_read_i2c_block_data not found - have you installed libi2c-dev ?)"], [[#include #include ]]) +else + with_libi2c="no (Linux only)" fi if test "x$with_libi2c" = "xyes" @@ -5569,11 +5991,21 @@ then plugin_ethstat="yes" fi +if test "x$with_libgrpcpp" = "xyes" && test "x$with_libprotobuf" = "xyes" && test "x$have_protoc3" = "xyes" && test "x$GRPC_CPP_PLUGIN" != "x" +then + plugin_grpc="yes" +fi + if test "x$have_getifaddrs" = "xyes" then plugin_interface="yes" fi +if test "x$with_libgps" = "xyes" +then + plugin_gps="yes" +fi + if test "x$have_getloadavg" = "xyes" then plugin_load="yes" @@ -5589,6 +6021,11 @@ then plugin_perl="yes" fi +if test "x$have_protoc_c" = "xyes" && test "x$with_libprotobuf_c" = "xyes" +then + plugin_pinba="yes" +fi + # Mac OS X memory interface if test "x$have_host_statistics" = "xyes" then @@ -5619,6 +6056,11 @@ then plugin_processes="yes" fi +if test "x$with_libpython" != "xno" +then + plugin_python="yes" +fi + if test "x$with_libatasmart" = "xyes" && test "x$with_libudev" = "xyes" then plugin_smart="yes" @@ -5634,6 +6076,11 @@ then plugin_swap="yes" fi +if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes" +then + plugin_swap="yes" +fi + if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes" then plugin_tcpconns="yes" @@ -5653,6 +6100,10 @@ then plugin_virt="yes" fi +if test "x$with_libxenctrl" = "xyes" +then + plugin_xencpu="yes" +fi m4_divert_once([HELP_ENABLE], [ collectd plugins:]) @@ -5674,141 +6125,150 @@ AC_ARG_ENABLE([all-plugins], m4_divert_once([HELP_ENABLE], []) -AC_PLUGIN([aggregation], [yes], [Aggregation plugin]) -AC_PLUGIN([amqp], [$with_librabbitmq], [AMQP output plugin]) -AC_PLUGIN([apache], [$with_libcurl], [Apache httpd statistics]) -AC_PLUGIN([apcups], [yes], [Statistics of UPSes by APC]) -AC_PLUGIN([apple_sensors], [$with_libiokit], [Apple's hardware sensors]) -AC_PLUGIN([aquaero], [$with_libaquaero5], [Aquaero's hardware sensors]) -AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player statistics]) -AC_PLUGIN([barometer], [$plugin_barometer], [Barometer sensor on I2C]) -AC_PLUGIN([battery], [$plugin_battery], [Battery statistics]) -AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics]) -AC_PLUGIN([ceph], [$plugin_ceph], [Ceph daemon statistics]) -AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics]) -AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics]) -AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics]) -AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics]) -AC_PLUGIN([csv], [yes], [CSV output plugin]) -AC_PLUGIN([curl], [$with_libcurl], [CURL generic web statistics]) -AC_PLUGIN([curl_json], [$plugin_curl_json], [CouchDB statistics]) -AC_PLUGIN([curl_xml], [$plugin_curl_xml], [CURL generic xml statistics]) -AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting]) -AC_PLUGIN([dbi], [$with_libdbi], [General database statistics]) -AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics]) -AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics]) -AC_PLUGIN([drbd], [$plugin_drbd], [DRBD statistics]) -AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis]) -AC_PLUGIN([email], [yes], [EMail statistics]) -AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics]) -AC_PLUGIN([ethstat], [$plugin_ethstat], [Stats from NIC driver]) -AC_PLUGIN([exec], [yes], [Execution of external programs]) -AC_PLUGIN([fhcount], [$plugin_fhcount], [File handles statistics]) -AC_PLUGIN([filecount], [yes], [Count files in directories]) -AC_PLUGIN([fscache], [$plugin_fscache], [fscache statistics]) -AC_PLUGIN([gmond], [$with_libganglia], [Ganglia plugin]) -AC_PLUGIN([hddtemp], [yes], [Query hddtempd]) -AC_PLUGIN([interface], [$plugin_interface], [Interface traffic statistics]) -AC_PLUGIN([ipc], [$plugin_ipc], [IPC statistics]) -AC_PLUGIN([ipmi], [$plugin_ipmi], [IPMI sensor statistics]) -AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters]) -AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics]) -AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics]) -AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine]) -AC_PLUGIN([load], [$plugin_load], [System load]) -AC_PLUGIN([logfile], [yes], [File logging plugin]) -AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging]) -AC_PLUGIN([lpar], [$with_perfstat], [AIX logical partitions statistics]) -AC_PLUGIN([lvm], [$with_liblvm2app], [LVM statistics]) -AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics]) -AC_PLUGIN([match_empty_counter], [yes], [The empty counter match]) -AC_PLUGIN([match_hashed], [yes], [The hashed match]) -AC_PLUGIN([match_regex], [yes], [The regex match]) -AC_PLUGIN([match_timediff], [yes], [The timediff match]) -AC_PLUGIN([match_value], [yes], [The value match]) -AC_PLUGIN([mbmon], [yes], [Query mbmond]) -AC_PLUGIN([md], [$have_linux_raid_md_u_h], [md (Linux software RAID) devices]) -AC_PLUGIN([memcachec], [$with_libmemcached], [memcachec statistics]) -AC_PLUGIN([memcached], [yes], [memcached statistics]) -AC_PLUGIN([memory], [$plugin_memory], [Memory usage]) -AC_PLUGIN([mic], [$with_mic], [Intel Many Integrated Core stats]) -AC_PLUGIN([modbus], [$with_libmodbus], [Modbus plugin]) -AC_PLUGIN([multimeter], [$plugin_multimeter], [Read multimeter values]) -AC_PLUGIN([mysql], [$with_libmysql], [MySQL statistics]) -AC_PLUGIN([netapp], [$with_libnetapp], [NetApp plugin]) -AC_PLUGIN([netlink], [$with_libmnl], [Enhanced Linux network statistics]) -AC_PLUGIN([network], [yes], [Network communication plugin]) -AC_PLUGIN([nfs], [$plugin_nfs], [NFS statistics]) -AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics]) -AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications]) -AC_PLUGIN([notify_email], [$with_libesmtp], [Email notifier]) -AC_PLUGIN([ntpd], [yes], [NTPd statistics]) -AC_PLUGIN([numa], [$plugin_numa], [NUMA virtual memory statistics]) -AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics]) -AC_PLUGIN([olsrd], [yes], [olsrd statistics]) -AC_PLUGIN([onewire], [$with_libowcapi], [OneWire sensor statistics]) -AC_PLUGIN([openldap], [$with_libldap], [OpenLDAP statistics]) -AC_PLUGIN([openvpn], [yes], [OpenVPN client statistics]) -AC_PLUGIN([oracle], [$with_oracle], [Oracle plugin]) -AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter]) -AC_PLUGIN([pf], [$have_net_pfvar_h], [BSD packet filter (PF) statistics]) +AC_PLUGIN([aggregation], [yes], [Aggregation plugin]) +AC_PLUGIN([amqp], [$with_librabbitmq], [AMQP output plugin]) +AC_PLUGIN([apache], [$with_libcurl], [Apache httpd statistics]) +AC_PLUGIN([apcups], [yes], [Statistics of UPSes by APC]) +AC_PLUGIN([apple_sensors], [$with_libiokit], [Apple hardware sensors]) +AC_PLUGIN([aquaero], [$with_libaquaero5], [Aquaero hardware sensors]) +AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player statistics]) +AC_PLUGIN([barometer], [$plugin_barometer], [Barometer sensor on I2C]) +AC_PLUGIN([battery], [$plugin_battery], [Battery statistics]) +AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics]) +AC_PLUGIN([ceph], [$plugin_ceph], [Ceph daemon statistics]) +AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting]) +AC_PLUGIN([chrony], [yes], [Chrony statistics]) +AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics]) +AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics]) +AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics]) +AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics]) +AC_PLUGIN([cpusleep], [$plugin_cpusleep], [CPU sleep statistics]) +AC_PLUGIN([csv], [yes], [CSV output plugin]) +AC_PLUGIN([curl], [$with_libcurl], [CURL generic web statistics]) +AC_PLUGIN([curl_json], [$plugin_curl_json], [CouchDB statistics]) +AC_PLUGIN([curl_xml], [$plugin_curl_xml], [CURL generic xml statistics]) +AC_PLUGIN([dbi], [$with_libdbi], [General database statistics]) +AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics]) +AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics]) +AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis]) +AC_PLUGIN([drbd], [$plugin_drbd], [DRBD statistics]) +AC_PLUGIN([email], [yes], [EMail statistics]) +AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics]) +AC_PLUGIN([ethstat], [$plugin_ethstat], [Stats from NIC driver]) +AC_PLUGIN([exec], [yes], [Execution of external programs]) +AC_PLUGIN([fhcount], [$plugin_fhcount], [File handles statistics]) +AC_PLUGIN([filecount], [yes], [Count files in directories]) +AC_PLUGIN([fscache], [$plugin_fscache], [fscache statistics]) +AC_PLUGIN([gmond], [$with_libganglia], [Ganglia plugin]) +AC_PLUGIN([gps], [$plugin_gps], [GPS plugin]) +AC_PLUGIN([grpc], [$plugin_grpc], [gRPC plugin]) +AC_PLUGIN([hddtemp], [yes], [Query hddtempd]) +AC_PLUGIN([interface], [$plugin_interface], [Interface traffic statistics]) +AC_PLUGIN([ipc], [$plugin_ipc], [IPC statistics]) +AC_PLUGIN([ipmi], [$plugin_ipmi], [IPMI sensor statistics]) +AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters]) +AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics]) +AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics]) +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]) +AC_PLUGIN([logfile], [yes], [File logging plugin]) +AC_PLUGIN([lpar], [$with_perfstat], [AIX logical partitions statistics]) +AC_PLUGIN([lua], [$with_liblua], [Lua plugin]) +AC_PLUGIN([lvm], [$with_liblvm2app], [LVM statistics]) +AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics]) +AC_PLUGIN([match_empty_counter], [yes], [The empty counter match]) +AC_PLUGIN([match_hashed], [yes], [The hashed match]) +AC_PLUGIN([match_regex], [yes], [The regex match]) +AC_PLUGIN([match_timediff], [yes], [The timediff match]) +AC_PLUGIN([match_value], [yes], [The value match]) +AC_PLUGIN([mbmon], [yes], [Query mbmond]) +AC_PLUGIN([md], [$have_linux_raid_md_u_h], [md (Linux software RAID) devices]) +AC_PLUGIN([memcachec], [$with_libmemcached], [memcachec statistics]) +AC_PLUGIN([memcached], [yes], [memcached statistics]) +AC_PLUGIN([memory], [$plugin_memory], [Memory usage]) +AC_PLUGIN([mic], [$with_mic], [Intel Many Integrated Core stats]) +AC_PLUGIN([modbus], [$with_libmodbus], [Modbus plugin]) +AC_PLUGIN([mqtt], [$with_libmosquitto], [MQTT output plugin]) +AC_PLUGIN([multimeter], [$plugin_multimeter], [Read multimeter values]) +AC_PLUGIN([mysql], [$with_libmysql], [MySQL statistics]) +AC_PLUGIN([netapp], [$with_libnetapp], [NetApp plugin]) +AC_PLUGIN([netlink], [$with_libmnl], [Enhanced Linux network statistics]) +AC_PLUGIN([network], [yes], [Network communication plugin]) +AC_PLUGIN([nfs], [$plugin_nfs], [NFS statistics]) +AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics]) +AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications]) +AC_PLUGIN([notify_email], [$with_libesmtp], [Email notifier]) +AC_PLUGIN([notify_nagios], [yes], [Nagios notification plugin]) +AC_PLUGIN([ntpd], [yes], [NTPd statistics]) +AC_PLUGIN([numa], [$plugin_numa], [NUMA virtual memory statistics]) +AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics]) +AC_PLUGIN([olsrd], [yes], [olsrd statistics]) +AC_PLUGIN([onewire], [$with_libowcapi], [OneWire sensor statistics]) +AC_PLUGIN([openldap], [$with_libldap], [OpenLDAP statistics]) +AC_PLUGIN([openvpn], [yes], [OpenVPN client statistics]) +AC_PLUGIN([oracle], [$with_oracle], [Oracle plugin]) +AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter]) +AC_PLUGIN([pf], [$have_net_pfvar_h], [BSD packet filter (PF) statistics]) # FIXME: Check for libevent, too. -AC_PLUGIN([pinba], [$have_protoc_c], [Pinba statistics]) -AC_PLUGIN([ping], [$with_liboping], [Network latency statistics]) -AC_PLUGIN([postgresql], [$with_libpq], [PostgreSQL database statistics]) -AC_PLUGIN([powerdns], [yes], [PowerDNS statistics]) -AC_PLUGIN([processes], [$plugin_processes], [Process statistics]) -AC_PLUGIN([protocols], [$plugin_protocols], [Protocol (IP, TCP, ...) statistics]) -AC_PLUGIN([python], [$with_python], [Embed a Python interpreter]) -AC_PLUGIN([redis], [$with_libhiredis], [Redis plugin]) -AC_PLUGIN([routeros], [$with_librouteros], [RouterOS plugin]) -AC_PLUGIN([rrdcached], [$librrd_rrdc_update], [RRDTool output plugin]) -AC_PLUGIN([rrdtool], [$with_librrd], [RRDTool output plugin]) -AC_PLUGIN([sensors], [$with_libsensors], [lm_sensors statistics]) -AC_PLUGIN([serial], [$plugin_serial], [serial port traffic]) -AC_PLUGIN([sigrok], [$with_libsigrok], [sigrok acquisition sources]) -AC_PLUGIN([smart], [$plugin_smart], [SMART statistics]) -AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin]) -AC_PLUGIN([statsd], [yes], [StatsD plugin]) -AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics]) -AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin]) -AC_PLUGIN([table], [yes], [Parsing of tabular data]) -AC_PLUGIN([tail], [yes], [Parsing of logfiles]) -AC_PLUGIN([tail_csv], [yes], [Parsing of CSV files]) -AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics]) -AC_PLUGIN([target_notification], [yes], [The notification target]) -AC_PLUGIN([target_replace], [yes], [The replace target]) -AC_PLUGIN([target_scale],[yes], [The scale target]) -AC_PLUGIN([target_set], [yes], [The set target]) -AC_PLUGIN([target_v5upgrade], [yes], [The v5upgrade target]) -AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics]) -AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics]) -AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values]) -AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics]) -AC_PLUGIN([threshold], [yes], [Threshold checking plugin]) -AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics]) -AC_PLUGIN([turbostat], [$plugin_turbostat], [Advanced statistic on Intel cpu states]) -AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin]) -AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics]) -AC_PLUGIN([users], [$plugin_users], [User statistics]) -AC_PLUGIN([uuid], [yes], [UUID as hostname plugin]) -AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics]) -AC_PLUGIN([virt], [$plugin_virt], [Virtual machine statistics]) -AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics]) -AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics]) -AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics]) -AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin]) -AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin]) -AC_PLUGIN([write_kafka], [$with_librdkafka], [Kafka output plugin]) -AC_PLUGIN([write_log], [yes], [Log output plugin]) -AC_PLUGIN([write_mongodb], [$with_libmongoc], [MongoDB output plugin]) -AC_PLUGIN([write_redis], [$with_libhiredis], [Redis output plugin]) -AC_PLUGIN([write_riemann], [$have_protoc_c], [Riemann output plugin]) -AC_PLUGIN([write_sensu], [yes], [Sensu output plugin]) -AC_PLUGIN([write_tsdb], [yes], [TSDB output plugin]) -AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics]) -AC_PLUGIN([zfs_arc], [$plugin_zfs_arc], [ZFS ARC statistics]) -AC_PLUGIN([zookeeper], [yes], [Zookeeper statistics]) +AC_PLUGIN([pinba], [$plugin_pinba], [Pinba statistics]) +AC_PLUGIN([ping], [$with_liboping], [Network latency statistics]) +AC_PLUGIN([postgresql], [$with_libpq], [PostgreSQL database statistics]) +AC_PLUGIN([powerdns], [yes], [PowerDNS statistics]) +AC_PLUGIN([processes], [$plugin_processes], [Process statistics]) +AC_PLUGIN([protocols], [$plugin_protocols], [Protocol (IP, TCP, ...) statistics]) +AC_PLUGIN([python], [$plugin_python], [Embed a Python interpreter]) +AC_PLUGIN([redis], [$with_libhiredis], [Redis plugin]) +AC_PLUGIN([routeros], [$with_librouteros], [RouterOS plugin]) +AC_PLUGIN([rrdcached], [$librrd_rrdc_update], [RRDTool output plugin]) +AC_PLUGIN([rrdtool], [$with_librrd], [RRDTool output plugin]) +AC_PLUGIN([sensors], [$with_libsensors], [lm_sensors statistics]) +AC_PLUGIN([serial], [$plugin_serial], [serial port traffic]) +AC_PLUGIN([sigrok], [$with_libsigrok], [sigrok acquisition sources]) +AC_PLUGIN([smart], [$plugin_smart], [SMART statistics]) +AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin]) +AC_PLUGIN([statsd], [yes], [StatsD plugin]) +AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics]) +AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin]) +AC_PLUGIN([table], [yes], [Parsing of tabular data]) +AC_PLUGIN([tail], [yes], [Parsing of logfiles]) +AC_PLUGIN([tail_csv], [yes], [Parsing of CSV files]) +AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics]) +AC_PLUGIN([target_notification], [yes], [The notification target]) +AC_PLUGIN([target_replace], [yes], [The replace target]) +AC_PLUGIN([target_scale], [yes], [The scale target]) +AC_PLUGIN([target_set], [yes], [The set target]) +AC_PLUGIN([target_v5upgrade], [yes], [The v5upgrade target]) +AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics]) +AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics]) +AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values]) +AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics]) +AC_PLUGIN([threshold], [yes], [Threshold checking plugin]) +AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics]) +AC_PLUGIN([turbostat], [$plugin_turbostat], [Advanced statistic on Intel cpu states]) +AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin]) +AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics]) +AC_PLUGIN([users], [$plugin_users], [User statistics]) +AC_PLUGIN([uuid], [yes], [UUID as hostname plugin]) +AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics]) +AC_PLUGIN([virt], [$plugin_virt], [Virtual machine statistics]) +AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics]) +AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics]) +AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics]) +AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin]) +AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin]) +AC_PLUGIN([write_kafka], [$with_librdkafka], [Kafka output plugin]) +AC_PLUGIN([write_log], [yes], [Log output plugin]) +AC_PLUGIN([write_mongodb], [$with_libmongoc], [MongoDB output plugin]) +AC_PLUGIN([write_redis], [$with_libhiredis], [Redis output plugin]) +AC_PLUGIN([write_riemann], [$with_libriemann_client], [Riemann output plugin]) +AC_PLUGIN([write_sensu], [yes], [Sensu 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]) +AC_PLUGIN([zfs_arc], [$plugin_zfs_arc], [ZFS ARC statistics]) +AC_PLUGIN([zone], [$plugin_zone], [Solaris container statistics]) +AC_PLUGIN([zookeeper], [yes], [Zookeeper statistics]) dnl Default configuration file # Load either syslog or logfile @@ -5933,6 +6393,18 @@ AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@ with_perl_bindings="no (no perl interpreter found)" fi ]) + +if test "x$with_perl_bindings" = "xyes" +then + AC_MSG_CHECKING([for the ExtUtils::MakeMaker module]) + if $PERL -MExtUtils::MakeMaker -e '' 2>/dev/null; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + with_perl_bindings="no (ExtUtils::MakeMaker not found)" + fi +fi + if test "x$with_perl_bindings" = "xyes" then PERL_BINDINGS="perl" @@ -5959,7 +6431,17 @@ AC_SUBST(LCC_VERSION_STRING) AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h) -AC_CONFIG_FILES([Makefile src/Makefile src/daemon/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile]) +AM_CFLAGS="-Wall" +AM_CXXFLAGS="-Wall" +if test "x$enable_werror" != "xno" +then + AM_CFLAGS="$AM_CFLAGS -Werror" + AM_CXXFLAGS="$AM_CXXFLAGS -Werror" +fi +AC_SUBST([AM_CFLAGS]) +AC_SUBST([AM_CXXFLAGS]) + +AC_CONFIG_FILES([Makefile proto/Makefile src/Makefile src/daemon/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile]) AC_OUTPUT if test "x$with_librrd" = "xyes" \ @@ -5986,208 +6468,237 @@ then with_perl_bindings="yes ($PERL_BINDINGS_OPTIONS)" fi -cat <{'get_files_by_ident'}{$cache_key})) @@ -496,7 +498,20 @@ sub get_files_by_ident return ($ret) } - $all_files = _get_all_files (); + if ($ident->{'hostname'}) + { + $all_files = []; + $hosts = $ident->{'hostname'}; + foreach (@$hosts) + { + $temp = get_files_for_host ($_); + push (@$all_files, @$temp); + } + } + else + { + $all_files = _get_all_files (); + } @ret = grep { _filter_ident ($ident, $_) == 0 } (@$all_files); diff --git a/contrib/examples/myplugin.c b/contrib/examples/myplugin.c index 9539062c..e1b89f6c 100644 --- a/contrib/examples/myplugin.c +++ b/contrib/examples/myplugin.c @@ -39,6 +39,7 @@ #endif /* ! HAVE_CONFIG */ #include + #include #include diff --git a/contrib/fedora/collectd.spec b/contrib/fedora/collectd.spec deleted file mode 100644 index a35923c0..00000000 --- a/contrib/fedora/collectd.spec +++ /dev/null @@ -1,376 +0,0 @@ -Summary: Statistics collection daemon for filling RRD files. -Name: collectd -Version: 4.2.0 -Release: 1.fc6 -Source: http://collectd.org/files/%{name}-%{version}.tar.gz -License: GPL -Group: System Environment/Daemons -BuildRoot: %{_tmppath}/%{name}-%{version}-root -BuildPrereq: lm_sensors-devel -BuildPrereq: mysql-devel -BuildPrereq: rrdtool-devel -BuildPrereq: net-snmp-devel -Requires: rrdtool -Requires: perl-Regexp-Common -Packager: Florian octo Forster -Vendor: Florian octo Forster - -%description -collectd is a small daemon written in C for performance. It reads various -system statistics and updates RRD files, creating them if neccessary. -Since the daemon doesn't need to startup every time it wants to update the -files it's very fast and easy on the system. Also, the statistics are very -fine grained since the files are updated every 10 seconds. - -%package apache -Summary: apache-plugin for collectd. -Group: System Environment/Daemons -Requires: collectd = %{version}, curl -%description apache -This plugin collectd data provided by Apache's `mod_status'. - -%package email -Summary: email-plugin for collectd. -Group: System Environment/Daemons -Requires: collectd = %{version}, spamassassin -%description email -This plugin collectd data provided by spamassassin. - -%package mysql -Summary: mysql-module for collectd. -Group: System Environment/Daemons -Requires: collectd = %{version}, mysql -%description mysql -MySQL querying plugin. This plugins provides data of issued commands, -called handlers and database traffic. - -%package sensors -Summary: libsensors-module for collectd. -Group: System Environment/Daemons -Requires: collectd = %{version}, lm_sensors -%description sensors -This plugin for collectd provides querying of sensors supported by -lm_sensors. - -%prep -rm -rf $RPM_BUILD_ROOT -%setup - -%build -./configure --prefix=%{_prefix} --sbindir=%{_sbindir} --mandir=%{_mandir} --libdir=%{_libdir} --sysconfdir=%{_sysconfdir} -make - -%install -make install DESTDIR=$RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d -mkdir -p $RPM_BUILD_ROOT/var/www/cgi-bin -cp src/collectd.conf $RPM_BUILD_ROOT/etc/collectd.conf -cp contrib/fedora/init.d-collectd $RPM_BUILD_ROOT/etc/rc.d/init.d/collectd -cp contrib/collection.cgi $RPM_BUILD_ROOT/var/www/cgi-bin -cp contrib/collection.conf $RPM_BUILD_ROOT/etc/collection.conf -mkdir -p $RPM_BUILD_ROOT/var/lib/collectd - -%clean -rm -rf $RPM_BUILD_ROOT - -%post -/sbin/chkconfig --add collectd -/sbin/chkconfig collectd on - -%preun -if [ "$1" = 0 ]; then - /sbin/chkconfig collectd off - /etc/init.d/collectd stop - /sbin/chkconfig --del collectd -fi -exit 0 - -%postun -if [ "$1" -ge 1 ]; then - /etc/init.d/collectd restart -fi -exit 0 - -%files -%defattr(-,root,root) -%doc AUTHORS COPYING ChangeLog INSTALL NEWS README -%attr(0644,root,root) %config(noreplace) /etc/collectd.conf -%attr(0644,root,root) %config(noreplace) /etc/collection.conf -%attr(0755,root,root) /etc/rc.d/init.d/collectd -%attr(0755,root,root) /var/www/cgi-bin/collection.cgi -%attr(0755,root,root) %{_sbindir}/collectd -%attr(0755,root,root) %{_bindir}/collectd-nagios -%attr(0644,root,root) %{_mandir}/man1/* -%attr(0644,root,root) %{_mandir}/man5/* - -%attr(0644,root,root) /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod -%attr(0644,root,root) /usr/lib/perl5/site_perl/5.8.8/Collectd.pm -%attr(0644,root,root) /usr/lib/perl5/site_perl/5.8.8/Collectd/Unixsock.pm -%attr(0644,root,root) /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Collectd/.packlist -%attr(0644,root,root) %{_mandir}/man3/Collectd::Unixsock.3pm.gz - -%attr(0644,root,root) %{_libdir}/%{name}/apcups.so* -%attr(0644,root,root) %{_libdir}/%{name}/apcups.la - -# FIXME!!! -#%attr(0644,root,root) %{_libdir}/%{name}/apple_sensors.so* -#%attr(0644,root,root) %{_libdir}/%{name}/apple_sensors.la - -%attr(0644,root,root) %{_libdir}/%{name}/battery.so* -%attr(0644,root,root) %{_libdir}/%{name}/battery.la - -%attr(0644,root,root) %{_libdir}/%{name}/conntrack.so* -%attr(0644,root,root) %{_libdir}/%{name}/conntrack.la - -%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.so* -%attr(0644,root,root) %{_libdir}/%{name}/cpufreq.la - -%attr(0644,root,root) %{_libdir}/%{name}/cpu.so* -%attr(0644,root,root) %{_libdir}/%{name}/cpu.la - -%attr(0644,root,root) %{_libdir}/%{name}/csv.so* -%attr(0644,root,root) %{_libdir}/%{name}/csv.la - -%attr(0644,root,root) %{_libdir}/%{name}/df.so* -%attr(0644,root,root) %{_libdir}/%{name}/df.la - -%attr(0644,root,root) %{_libdir}/%{name}/disk.so* -%attr(0644,root,root) %{_libdir}/%{name}/disk.la - -%attr(0644,root,root) %{_libdir}/%{name}/dns.so* -%attr(0644,root,root) %{_libdir}/%{name}/dns.la - -%attr(0644,root,root) %{_libdir}/%{name}/entropy.so* -%attr(0644,root,root) %{_libdir}/%{name}/entropy.la - -%attr(0644,root,root) %{_libdir}/%{name}/exec.so* -%attr(0644,root,root) %{_libdir}/%{name}/exec.la - -%attr(0644,root,root) %{_libdir}/%{name}/hddtemp.so* -%attr(0644,root,root) %{_libdir}/%{name}/hddtemp.la - -%attr(0644,root,root) %{_libdir}/%{name}/interface.so* -%attr(0644,root,root) %{_libdir}/%{name}/interface.la - -%attr(0644,root,root) %{_libdir}/%{name}/iptables.so* -%attr(0644,root,root) %{_libdir}/%{name}/iptables.la - -%attr(0644,root,root) %{_libdir}/%{name}/irq.so* -%attr(0644,root,root) %{_libdir}/%{name}/irq.la - -%attr(0644,root,root) %{_libdir}/%{name}/load.so* -%attr(0644,root,root) %{_libdir}/%{name}/load.la - -%attr(0644,root,root) %{_libdir}/%{name}/logfile.so* -%attr(0644,root,root) %{_libdir}/%{name}/logfile.la - -%attr(0644,root,root) %{_libdir}/%{name}/mbmon.so* -%attr(0644,root,root) %{_libdir}/%{name}/mbmon.la - -%attr(0644,root,root) %{_libdir}/%{name}/memcached.so* -%attr(0644,root,root) %{_libdir}/%{name}/memcached.la - -%attr(0644,root,root) %{_libdir}/%{name}/memory.so* -%attr(0644,root,root) %{_libdir}/%{name}/memory.la - -%attr(0644,root,root) %{_libdir}/%{name}/multimeter.so* -%attr(0644,root,root) %{_libdir}/%{name}/multimeter.la - -%attr(0644,root,root) %{_libdir}/%{name}/network.so* -%attr(0644,root,root) %{_libdir}/%{name}/network.la - -%attr(0644,root,root) %{_libdir}/%{name}/nfs.so* -%attr(0644,root,root) %{_libdir}/%{name}/nfs.la - -%attr(0644,root,root) %{_libdir}/%{name}/nginx.so* -%attr(0644,root,root) %{_libdir}/%{name}/nginx.la - -%attr(0644,root,root) %{_libdir}/%{name}/ntpd.so* -%attr(0644,root,root) %{_libdir}/%{name}/ntpd.la - -# FIXME!!! -#%attr(0644,root,root) %{_libdir}/%{name}/nut.so* -#%attr(0644,root,root) %{_libdir}/%{name}/nut.la - -%attr(0644,root,root) %{_libdir}/%{name}/perl.so* -%attr(0644,root,root) %{_libdir}/%{name}/perl.la - -%attr(0644,root,root) %{_libdir}/%{name}/ping.so* -%attr(0644,root,root) %{_libdir}/%{name}/ping.la - -%attr(0644,root,root) %{_libdir}/%{name}/processes.so* -%attr(0644,root,root) %{_libdir}/%{name}/processes.la - -%attr(0644,root,root) %{_libdir}/%{name}/rrdtool.so* -%attr(0644,root,root) %{_libdir}/%{name}/rrdtool.la - -%attr(0644,root,root) %{_libdir}/%{name}/serial.so* -%attr(0644,root,root) %{_libdir}/%{name}/serial.la - -%attr(0644,root,root) %{_libdir}/%{name}/swap.so* -%attr(0644,root,root) %{_libdir}/%{name}/swap.la - -%attr(0644,root,root) %{_libdir}/%{name}/snmp.so* -%attr(0644,root,root) %{_libdir}/%{name}/snmp.la - -%attr(0644,root,root) %{_libdir}/%{name}/syslog.so* -%attr(0644,root,root) %{_libdir}/%{name}/syslog.la - -# FIXME!!! -#%attr(0644,root,root) %{_libdir}/%{name}/tape.so* -#%attr(0644,root,root) %{_libdir}/%{name}/tape.la - -%attr(0644,root,root) %{_libdir}/%{name}/tcpconns.so* -%attr(0644,root,root) %{_libdir}/%{name}/tcpconns.la - -%attr(0644,root,root) %{_libdir}/%{name}/unixsock.so* -%attr(0644,root,root) %{_libdir}/%{name}/unixsock.la - -%attr(0644,root,root) %{_libdir}/%{name}/users.so* -%attr(0644,root,root) %{_libdir}/%{name}/users.la - -%attr(0644,root,root) %{_libdir}/%{name}/vserver.so* -%attr(0644,root,root) %{_libdir}/%{name}/vserver.la - -%attr(0644,root,root) %{_libdir}/%{name}/wireless.so* -%attr(0644,root,root) %{_libdir}/%{name}/wireless.la - -%attr(0644,root,root) %{_datadir}/%{name}/types.db - -%dir /var/lib/collectd - -%files apache -%attr(0644,root,root) %{_libdir}/%{name}/apache.so* -%attr(0644,root,root) %{_libdir}/%{name}/apache.la - -%files email -%attr(0644,root,root) %{_libdir}/%{name}/email.so* -%attr(0644,root,root) %{_libdir}/%{name}/email.la - -%files mysql -%attr(0644,root,root) %{_libdir}/%{name}/mysql.so* -%attr(0644,root,root) %{_libdir}/%{name}/mysql.la - -%files sensors -%attr(0644,root,root) %{_libdir}/%{name}/sensors.so* -%attr(0644,root,root) %{_libdir}/%{name}/sensors.la - -%changelog -* Wed Oct 31 2007 Iain Lea 4.2.0 -- New major release -- Changes to support 4.2.0 (ie. contrib/collection.conf) - -* Mon Aug 06 2007 Kjell Randa 4.0.6 -- New upstream version - -* Wed Jul 25 2007 Kjell Randa 4.0.5 -- New major release -- Changes to support 4.0.5 - -* Wed Jan 11 2007 Iain Lea 3.11.0-0 -- fixed spec file to build correctly on fedora core -- added improved init.d script to work with chkconfig -- added %post and %postun to call chkconfig automatically - -* Sun Jul 09 2006 Florian octo Forster 3.10.0-1 -- New upstream version - -* Tue Jun 25 2006 Florian octo Forster 3.9.4-1 -- New upstream version - -* Tue Jun 01 2006 Florian octo Forster 3.9.3-1 -- New upstream version - -* Tue May 09 2006 Florian octo Forster 3.9.2-1 -- New upstream version - -* Tue May 09 2006 Florian octo Forster 3.8.5-1 -- New upstream version - -* Fri Apr 21 2006 Florian octo Forster 3.9.1-1 -- New upstream version - -* Fri Apr 14 2006 Florian octo Forster 3.9.0-1 -- New upstream version -- Added the `apache' package. - -* Thu Mar 14 2006 Florian octo Forster 3.8.2-1 -- New upstream version - -* Thu Mar 13 2006 Florian octo Forster 3.8.1-1 -- New upstream version - -* Thu Mar 09 2006 Florian octo Forster 3.8.0-1 -- New upstream version - -* Sat Feb 18 2006 Florian octo Forster 3.7.2-1 -- Include `tape.so' so the build doesn't terminate because of missing files.. -- New upstream version - -* Sat Feb 04 2006 Florian octo Forster 3.7.1-1 -- New upstream version - -* Mon Jan 30 2006 Florian octo Forster 3.7.0-1 -- New upstream version -- Removed the extra `hddtemp' package - -* Tue Jan 24 2006 Florian octo Forster 3.6.2-1 -- New upstream version - -* Fri Jan 20 2006 Florian octo Forster 3.6.1-1 -- New upstream version - -* Fri Jan 20 2006 Florian octo Forster 3.6.0-1 -- New upstream version -- Added config file, `collectd.conf(5)', `df.so' -- Added package `collectd-mysql', dependency on `mysqlclient10 | mysql' - -* Wed Dec 07 2005 Florian octo Forster 3.5.0-1 -- New upstream version - -* Sat Nov 26 2005 Florian octo Forster 3.4.0-1 -- New upstream version - -* Sat Nov 05 2005 Florian octo Forster 3.3.0-1 -- New upstream version - -* Tue Oct 26 2005 Florian octo Forster 3.2.0-1 -- New upstream version -- Added statement to remove the `*.la' files. This fixes a problem when - `Unpackaged files terminate build' is in effect. -- Added `processes.so*' to the main package - -* Fri Oct 14 2005 Florian octo Forster 3.1.0-1 -- New upstream version -- Added package `collectd-hddtemp' - -* Fri Sep 30 2005 Florian octo Forster 3.0.0-1 -- New upstream version -- Split the package into `collectd' and `collectd-sensors' - -* Fri Sep 16 2005 Florian octo Forster 2.1.0-1 -- New upstream version - -* Mon Sep 10 2005 Florian octo Forster 2.0.0-1 -- New upstream version - -* Mon Aug 29 2005 Florian octo Forster 1.8.0-1 -- New upstream version - -* Sun Aug 25 2005 Florian octo Forster 1.7.0-1 -- New upstream version - -* Sun Aug 21 2005 Florian octo Forster 1.6.0-1 -- New upstream version - -* Sun Jul 17 2005 Florian octo Forster 1.5.1-1 -- New upstream version - -* Sun Jul 17 2005 Florian octo Forster 1.5-1 -- New upstream version - -* Mon Jul 11 2005 Florian octo Forster 1.4.2-1 -- New upstream version - -* Sat Jul 09 2005 Florian octo Forster 1.4-1 -- Built on RedHat 7.3 diff --git a/contrib/fedora/init.d-collectd b/contrib/fedora/init.d-collectd deleted file mode 100644 index ea8662ad..00000000 --- a/contrib/fedora/init.d-collectd +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# -# collectd Startup script for the Collectd statistics gathering daemon -# chkconfig: - 86 15 -# description: Collectd is a statistics gathering daemon used to collect \ -# system information ie. cpu, memory, disk, network -# processname: collectd -# config: /etc/collectd.conf -# config: /etc/sysconfig/collectd -# pidfile: /var/run/collectd.pid - -# Source function library. -. /etc/init.d/functions - -RETVAL=0 -ARGS="" -prog="collectd" -CONFIG=/etc/collectd.conf - -if [ -r /etc/default/$prog ]; then - . /etc/default/$prog -fi - -start () { - echo -n $"Starting $prog: " - if [ -r "$CONFIG" ] - then - daemon /usr/sbin/collectd -C "$CONFIG" - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog - fi -} -stop () { - echo -n $"Stopping $prog: " - killproc $prog - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog -} -# See how we were called. -case "$1" in - start) - start - ;; - stop) - stop - ;; - status) - status $prog - ;; - restart|reload) - stop - start - ;; - condrestart) - [ -f /var/lock/subsys/$prog ] && stop && start || : - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" - exit 1 -esac - -exit $? - -# vim:syntax=sh diff --git a/contrib/redhat/collectd.spec b/contrib/redhat/collectd.spec index 4f6306be..20615733 100644 --- a/contrib/redhat/collectd.spec +++ b/contrib/redhat/collectd.spec @@ -38,37 +38,6 @@ %global _hardened_build 1 %{?perl_default_filter} -# plugins only buildable on RHEL6 -# (NB: %{elN} macro is not available on RHEL < 6) -%{?el6:%global _has_libyajl 1} -%{?el6:%global _has_recent_libpcap 1} -%{?el6:%global _has_recent_sockios_h 1} -%{?el6:%global _has_recent_libganglia 1} -%{?el6:%global _has_working_libiptc 1} -%{?el6:%global _has_ip_vs_h 1} -%{?el6:%global _has_lvm2app_h 1} -%{?el6:%global _has_libmodbus 1} -%{?el6:%global _has_libudev 1} -%{?el6:%global _has_iproute 1} -%{?el6:%global _has_atasmart 1} -%{?el6:%global _has_hiredis 1} -%{?el6:%global _has_asm_msr_index 1} - -%{?el7:%global _has_libyajl 1} -%{?el7:%global _has_recent_libpcap 1} -%{?el7:%global _has_recent_sockios_h 1} -%{?el7:%global _has_working_libiptc 1} -%{?el7:%global _has_ip_vs_h 1} -%{?el7:%global _has_lvm2app_h 1} -%{?el7:%global _has_libudev 1} -%{?el7:%global _has_recent_librrd 1} -%{?el7:%global _has_iproute 1} -%{?el7:%global _has_atasmart 1} -%{?el7:%global _has_hiredis 1} -%{?el7:%global _has_asm_msr_index 1} -%{?el7:%global _has_libmodbus 1} -%{?el7:%global _has_xmms 1} - # plugins enabled by default %define with_aggregation 0%{!?_without_aggregation:1} %define with_amqp 0%{!?_without_amqp:1} @@ -77,57 +46,62 @@ %define with_ascent 0%{!?_without_ascent:1} %define with_battery 0%{!?_without_battery:1} %define with_bind 0%{!?_without_bind:1} -%define with_ceph 0%{!?_without_ceph:0%{?_has_libyajl}} +%define with_ceph 0%{!?_without_ceph:1} %define with_cgroups 0%{!?_without_cgroups:1} +%define with_chrony 0%{!?_without_chrony:1} %define with_conntrack 0%{!?_without_conntrack:1} %define with_contextswitch 0%{!?_without_contextswitch:1} %define with_cpu 0%{!?_without_cpu:1} %define with_cpufreq 0%{!?_without_cpufreq:1} +%define with_cpusleep 0%{!?_without_cpusleep:1} %define with_csv 0%{!?_without_csv:1} %define with_curl 0%{!?_without_curl:1} -%define with_curl_json 0%{!?_without_curl_json:0%{?_has_libyajl}} +%define with_curl_json 0%{!?_without_curl_json:1} %define with_curl_xml 0%{!?_without_curl_xml:1} %define with_dbi 0%{!?_without_dbi:1} %define with_df 0%{!?_without_df:1} %define with_disk 0%{!?_without_disk:1} -%define with_dns 0%{!?_without_dns:0%{?_has_recent_libpcap}} +%define with_dns 0%{!?_without_dns:1} %define with_drbd 0%{!?_without_drbd:1} %define with_email 0%{!?_without_email:1} %define with_entropy 0%{!?_without_entropy:1} -%define with_ethstat 0%{!?_without_ethstat:0%{?_has_recent_sockios_h}} +%define with_ethstat 0%{!?_without_ethstat:1} %define with_exec 0%{!?_without_exec:1} %define with_fhcount 0%{!?_without_fhcount:1} %define with_filecount 0%{!?_without_filecount:1} %define with_fscache 0%{!?_without_fscache:1} -%define with_gmond 0%{!?_without_gmond:0%{?_has_recent_libganglia}} +%define with_gmond 0%{!?_without_gmond:1} +%define with_gps 0%{!?_without_gps:1} %define with_hddtemp 0%{!?_without_hddtemp:1} %define with_interface 0%{!?_without_interface:1} %define with_ipc 0%{!?_without_ipc:1} %define with_ipmi 0%{!?_without_ipmi:1} -%define with_iptables 0%{!?_without_iptables:0%{?_has_working_libiptc}} -%define with_ipvs 0%{!?_without_ipvs:0%{?_has_ip_vs_h}} +%define with_iptables 0%{!?_without_iptables:1} +%define with_ipvs 0%{!?_without_ipvs:1} %define with_irq 0%{!?_without_irq:1} %define with_java 0%{!?_without_java:1} -%define with_virt 0%{!?_without_virt:1} %define with_load 0%{!?_without_load:1} +%define with_log_logstash 0%{!?_without_log_logstash:1} %define with_logfile 0%{!?_without_logfile:1} -%define with_log_logstash 0%{!?_without_log_logstash:0%{?_has_libyajl}} -%define with_lvm 0%{!?_without_lvm:0%{?_has_lvm2app_h}} +%define with_lua 0%{!?_without_lua:1} +%define with_lvm 0%{!?_without_lvm:1} %define with_madwifi 0%{!?_without_madwifi:1} %define with_mbmon 0%{!?_without_mbmon:1} %define with_md 0%{!?_without_md:1} %define with_memcachec 0%{!?_without_memcachec:1} %define with_memcached 0%{!?_without_memcached:1} %define with_memory 0%{!?_without_memory:1} +%define with_modbus 0%{!?_without_modbus:1} +%define with_mqtt 0%{!?_without_mqtt:1} %define with_multimeter 0%{!?_without_multimeter:1} -%define with_modbus 0%{!?_without_modbus:0%{?_has_libmodbus}} %define with_mysql 0%{!?_without_mysql:1} -%define with_netlink 0%{!?_without_netlink:0%{?_has_iproute}} +%define with_netlink 0%{!?_without_netlink:1} %define with_network 0%{!?_without_network:1} %define with_nfs 0%{!?_without_nfs:1} %define with_nginx 0%{!?_without_nginx:1} %define with_notify_desktop 0%{!?_without_notify_desktop:1} %define with_notify_email 0%{!?_without_notify_email:1} +%define with_notify_nagios 0%{!?_without_notify_nagios:1} %define with_ntpd 0%{!?_without_ntpd:1} %define with_numa 0%{!?_without_numa:1} %define with_nut 0%{!?_without_nut:1} @@ -142,12 +116,12 @@ %define with_processes 0%{!?_without_processes:1} %define with_protocols 0%{!?_without_protocols:1} %define with_python 0%{!?_without_python:1} -%define with_redis 0%{!?_without_redis:0%{?_has_hiredis}} -%define with_rrdcached 0%{!?_without_rrdcached:0%{?_has_recent_librrd}} +%define with_redis 0%{!?_without_redis:1} +%define with_rrdcached 0%{!?_without_rrdcached:1} %define with_rrdtool 0%{!?_without_rrdtool:1} %define with_sensors 0%{!?_without_sensors:1} %define with_serial 0%{!?_without_serial:1} -%define with_smart 0%{!?_without_smart:0%{?_has_atasmart}} +%define with_smart 0%{!?_without_smart:1} %define with_snmp 0%{!?_without_snmp:1} %define with_statsd 0%{!?_without_statsd:1} %define with_swap 0%{!?_without_swap:1} @@ -160,20 +134,20 @@ %define with_ted 0%{!?_without_ted:1} %define with_thermal 0%{!?_without_thermal:1} %define with_threshold 0%{!?_without_threshold:1} -%define with_turbostat 0%{!?_without_turbostat:0%{?_has_asm_msr_index}} +%define with_turbostat 0%{!?_without_turbostat:1} %define with_unixsock 0%{!?_without_unixsock:1} %define with_uptime 0%{!?_without_uptime:1} %define with_users 0%{!?_without_users:1} %define with_uuid 0%{!?_without_uuid:1} %define with_varnish 0%{!?_without_varnish:1} +%define with_virt 0%{!?_without_virt:1} %define with_vmem 0%{!?_without_vmem:1} %define with_vserver 0%{!?_without_vserver:1} %define with_wireless 0%{!?_without_wireless:1} %define with_write_graphite 0%{!?_without_write_graphite:1} %define with_write_http 0%{!?_without_write_http:1} %define with_write_log 0%{!?_without_write_log:1} -%define with_write_redis 0%{!?_without_write_redis:0%{?_has_hiredis}} -%define with_write_riemann 0%{!?_without_write_riemann:1} +%define with_write_redis 0%{!?_without_write_redis:1} %define with_write_sensu 0%{!?_without_write_sensu:1} %define with_write_tsdb 0%{!?_without_write_tsdb:1} %define with_xmms 0%{!?_without_xmms:0%{?_has_xmms}} @@ -189,6 +163,8 @@ %define with_aquaero 0%{!?_without_aquaero:0} # plugin barometer disabled, requires a libi2c %define with_barometer 0%{!?_without_barometer:0} +# plugin grpc disabled, requires protobuf-compiler >= 3.0 +%define with_grpc 0%{!?_without_grpc:0} # plugin lpar disabled, requires AIX %define with_lpar 0%{!?_without_lpar:0} # plugin mic disabled, requires Mic @@ -213,24 +189,56 @@ %define with_write_kafka 0%{!?_without_write_kafka:0} # plugin write_mongodb disabled, requires libmongoc %define with_write_mongodb 0%{!?_without_write_mongodb:0} - -Summary: statistics collection and monitoring daemon +# plugin write_riemann disabled, requires a new enough riemann_c_client +%define with_write_riemann 0%{!?_without_write_riemann:0} +# plugin xencpu disabled, requires xen-devel from non-default repo +%define with_xencpu 0%{!?_without_xencpu:0} +# plugin zone disabled, requires Solaris +%define with_zone 0%{!?_without_zone:0} + +# Plugins not buildable on RHEL < 6 +%if 0%{?rhel} && 0%{?rhel} < 6 +%define with_ceph 0 +%define with_curl_json 0 +%define with_log_logstash 0 +%define with_dns 0 +%define with_ethstat 0 +%define with_gmond 0 +%define with_iptables 0 +%define with_ipvs 0 +%define with_lvm 0 +%define with_modbus 0 +%define with_netlink 0 +%define with_redis 0 +%define with_smart 0 +%define with_turbostat 0 +%define with_write_redis 0 +%endif + +# Plugins not buildable on RHEL < 7 +%if 0%{?rhel} && 0%{?rhel} < 7 +%define with_cpusleep 0 +%define with_gps 0 +%define with_mqtt 0 +%define with_rrdcached 0 +%define with_xmms 0 +%endif + +Summary: Statistics collection and monitoring daemon Name: collectd -Version: 5.5.2 -Release: 1%{?dist} +Version: 5.6.0 +Release: 2%{?dist} URL: https://collectd.org Source: https://collectd.org/files/%{name}-%{version}.tar.bz2 License: GPLv2 Group: System Environment/Daemons BuildRoot: %{_tmppath}/%{name}-%{version}-root -BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel +BuildRequires: libgcrypt-devel, kernel-headers, libtool-ltdl-devel, libcap-devel, which Vendor: collectd development team -%if 0%{?el7:1} -Requires(pre): initscripts -Requires(post): systemd -Requires(preun): systemd -Requires(postun): systemd +%if 0%{?fedora} || 0%{?rhel} >= 7 +%{?systemd_requires} +BuildRequires: systemd %else Requires(post): chkconfig Requires(preun): chkconfig, initscripts @@ -317,6 +325,15 @@ BuildRequires: yajl-devel Ceph plugin for collectd %endif +%if %{with_chrony} +%package chrony +Summary: Chrony plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +%description chrony +Chrony plugin for collectd +%endif + %if %{with_curl} %package curl Summary: Curl plugin for collectd @@ -404,6 +421,26 @@ The gmond plugin subscribes to a Multicast group to receive data from gmond, the client daemon of the Ganglia project. %endif +%if %{with_gps} +%package gps +Summary: GPS plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +BuildRequires: gpsd-devel +%description gps +This plugin monitor gps related data through gpsd. +%endif + +%if %{with_grpc} +%package grpc +Summary: GRPC plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +BuildRequires: protobuf-compiler +%description grpc +This plugin embeds a gRPC server into Collectd. +%endif + %if %{with_hddtemp} %package hddtemp Summary: Hddtemp plugin for collectd @@ -459,6 +496,17 @@ BuildRequires: yajl-devel This plugin logs in logstash JSON format %endif +%if %{with_lua} +%package lua +Summary: Lua plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +BuildRequires: lua-devel +%description lua +The Lua plugin embeds a Lua interpreter into collectd and exposes the +application programming interface (API) to Lua scripts. +%endif + %if %{with_lvm} %package lvm Summary: LVM plugin for collectd @@ -513,6 +561,16 @@ MySQL querying plugin. This plugin provides data of issued commands, called handlers and database traffic. %endif +%if %{with_mqtt} +%package mqtt +Summary: mqtt plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +BuildRequires: mosquitto-devel +%description mqtt +The MQTT plugin publishes and subscribes to MQTT topics. +%endif + %if %{with_netlink} %package netlink Summary: netlink plugin for collectd @@ -581,10 +639,10 @@ Summary: Perl plugin for collectd Group: System Environment/Daemons Requires: %{name}%{?_isa} = %{version}-%{release} Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version)) - %if 0%{?rhel} >= 6 -BuildRequires: perl-ExtUtils-Embed - %else + %if 0%{?rhel} && 0%{?rhel} < 6 BuildRequires: perl + %else +BuildRequires: perl-ExtUtils-Embed %endif %description perl The Perl plugin embeds a Perl interpreter into collectd and exposes the @@ -629,10 +687,10 @@ database. Summary: Python plugin for collectd Group: System Environment/Daemons Requires: %{name}%{?_isa} = %{version}-%{release} - %if 0%{?rhel} >= 6 -BuildRequires: python-devel - %else + %if 0%{?rhel} && 0%{?rhel} < 6 BuildRequires: python26-devel + %else +BuildRequires: python-devel %endif %description python The Python plugin embeds a Python interpreter into collectd and exposes the @@ -749,7 +807,7 @@ using HTTP POST requests. Summary: Write-kafka plugin for collectd Group: System Environment/Daemons Requires: %{name}%{?_isa} = %{version}-%{release} -BuildRequires: rdkafka-devel +BuildRequires: librdkafka-devel %description write_kafka The write_kafka plugin sends values to kafka, a distributed messaging system. %endif @@ -774,6 +832,16 @@ BuildRequires: protobuf-c-devel The riemann plugin submits values to Riemann, an event stream processor. %endif +%if %{with_xencpu} +%package xencpu +Summary: xencpu plugin for collectd +Group: System Environment/Daemons +Requires: %{name}%{?_isa} = %{version}-%{release} +BuildRequires: xen-devel +%description xencpu +The xencpu plugin collects CPU statistics from Xen. +%endif + %if %{with_xmms} %package xmms Summary: XMMS plugin for collectd @@ -904,6 +972,12 @@ Collectd utilities %define _with_cgroups --disable-cgroups %endif +%if %{with_chrony} +%define _with_chrony --enable-chrony +%else +%define _with_chrony --disable-chrony +%endif + %if %{with_conntrack} %define _with_conntrack --enable-conntrack %else @@ -928,6 +1002,12 @@ Collectd utilities %define _with_cpufreq --disable-cpufreq %endif +%if %{with_cpusleep} +%define _with_cpusleep --enable-cpusleep +%else +%define _with_cpusleep --disable-cpusleep +%endif + %if %{with_csv} %define _with_csv --enable-csv %else @@ -1036,6 +1116,18 @@ Collectd utilities %define _with_gmond --disable-gmond %endif +%if %{with_gps} +%define _with_gps --enable-gps +%else +%define _with_gps --disable-gps +%endif + +%if %{with_grpc} +%define _with_grpc --enable-grpc +%else +%define _with_grpc --disable-grpc +%endif + %if %{with_hddtemp} %define _with_hddtemp --enable-hddtemp %else @@ -1114,6 +1206,12 @@ Collectd utilities %define _with_lpar --disable-lpar %endif +%if %{with_lua} +%define _with_lua --enable-lua +%else +%define _with_lua --disable-lua +%endif + %if %{with_lvm} %define _with_lvm --enable-lvm %else @@ -1174,6 +1272,12 @@ Collectd utilities %define _with_multimeter --disable-multimeter %endif +%if %{with_mqtt} +%define _with_mqtt --enable-mqtt +%else +%define _with_mqtt --disable-mqtt +%endif + %if %{with_mysql} %define _with_mysql --enable-mysql %else @@ -1222,6 +1326,12 @@ Collectd utilities %define _with_notify_email --disable-notify_email %endif +%if %{with_notify_nagios} +%define _with_notify_nagios --enable-notify_nagios +%else +%define _with_notify_nagios --disable-notify_nagios +%endif + %if %{with_ntpd} %define _with_ntpd --enable-ntpd %else @@ -1319,10 +1429,11 @@ Collectd utilities %endif %if %{with_python} - %if 0%{?rhel} >= 6 -%define _with_python --enable-python - %else + %if 0%{?rhel} && 0%{?rhel} < 6 %define _with_python --enable-python --with-python=%{_bindir}/python2.6 +%define _python_config PYTHON_CONFIG="%{_bindir}/python2.6-config" + %else +%define _with_python --enable-python %endif %else %define _with_python --disable-python @@ -1568,6 +1679,12 @@ Collectd utilities %define _with_write_tsdb --disable-write_tsdb %endif +%if %{with_xencpu} +%define _with_xencpu --enable-xencpu +%else +%define _with_xencpu --disable-xencpu +%endif + %if %{with_xmms} %define _with_xmms --enable-xmms %else @@ -1580,6 +1697,12 @@ Collectd utilities %define _with_zfs_arc --disable-zfs_arc %endif +%if %{with_zone} +%define _with_zone --enable-zone +%else +%define _with_zone --disable-zone +%endif + %if %{with_zookeeper} %define _with_zookeeper --enable-zookeeper %else @@ -1587,6 +1710,7 @@ Collectd utilities %endif %configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \ + %{?_python_config} \ --disable-static \ --without-included-ltdl \ --enable-all-plugins=yes \ @@ -1612,14 +1736,16 @@ Collectd utilities %{?_with_bind} \ %{?_with_ceph} \ %{?_with_cgroups} \ + %{?_with_chrony} \ %{?_with_conntrack} \ %{?_with_contextswitch} \ - %{?_with_cpu} \ %{?_with_cpufreq} \ + %{?_with_cpusleep} \ + %{?_with_cpu} \ %{?_with_csv} \ - %{?_with_curl} \ %{?_with_curl_json} \ %{?_with_curl_xml} \ + %{?_with_curl} \ %{?_with_dbi} \ %{?_with_df} \ %{?_with_disk} \ @@ -1633,98 +1759,105 @@ Collectd utilities %{?_with_filecount} \ %{?_with_fscache} \ %{?_with_gmond} \ + %{?_with_gps} \ + %{?_with_grpc} \ %{?_with_hddtemp} \ %{?_with_interface} \ %{?_with_ipc} \ %{?_with_ipmi} \ %{?_with_iptables} \ %{?_with_ipvs} \ + %{?_with_irq} \ %{?_with_java} \ - %{?_with_virt} \ + %{?_with_load} \ %{?_with_log_logstash} \ + %{?_with_logfile} \ %{?_with_lpar} \ + %{?_with_lua} \ %{?_with_lvm} \ + %{?_with_madwifi} \ + %{?_with_mbmon} \ + %{?_with_md} \ %{?_with_memcachec} \ + %{?_with_memcached} \ + %{?_with_memory} \ %{?_with_mic} \ %{?_with_modbus} \ + %{?_with_mqtt} \ %{?_with_multimeter} \ %{?_with_mysql} \ %{?_with_netapp} \ %{?_with_netlink} \ + %{?_with_network} \ + %{?_with_nfs} \ %{?_with_nginx} \ %{?_with_notify_desktop} \ %{?_with_notify_email} \ + %{?_with_notify_nagios} \ + %{?_with_ntpd} \ + %{?_with_numa} \ %{?_with_nut} \ + %{?_with_olsrd} \ %{?_with_onewire} \ %{?_with_openldap} \ + %{?_with_openvpn} \ %{?_with_oracle} \ %{?_with_perl} \ %{?_with_pf} \ %{?_with_pinba} \ %{?_with_ping} \ %{?_with_postgresql} \ + %{?_with_powerdns} \ + %{?_with_processes} \ + %{?_with_protocols} \ %{?_with_python} \ %{?_with_redis} \ %{?_with_routeros} \ %{?_with_rrdcached} \ %{?_with_rrdtool} \ %{?_with_sensors} \ + %{?_with_serial} \ %{?_with_sigrok} \ %{?_with_smart} \ %{?_with_snmp} \ - %{?_with_tape} \ - %{?_with_tokyotyrant} \ - %{?_with_varnish} \ - %{?_with_write_http} \ - %{?_with_write_kafka} \ - %{?_with_write_mongodb} \ - %{?_with_write_redis} \ - %{?_with_xmms} \ - %{?_with_zfs_arc} \ - %{?_with_zookeeper} \ - %{?_with_irq} \ - %{?_with_load} \ - %{?_with_logfile} \ - %{?_with_madwifi} \ - %{?_with_mbmon} \ - %{?_with_md} \ - %{?_with_memcached} \ - %{?_with_memory} \ - %{?_with_network} \ - %{?_with_nfs} \ - %{?_with_ntpd} \ - %{?_with_numa} \ - %{?_with_olsrd} \ - %{?_with_openvpn} \ - %{?_with_powerdns} \ - %{?_with_processes} \ - %{?_with_protocols} \ - %{?_with_serial} \ %{?_with_statsd} \ %{?_with_swap} \ %{?_with_syslog} \ %{?_with_table} \ - %{?_with_tail} \ %{?_with_tail_csv} \ + %{?_with_tail} \ + %{?_with_tape} \ %{?_with_tcpconns} \ %{?_with_teamspeak2} \ %{?_with_ted} \ %{?_with_thermal} \ %{?_with_threshold} \ + %{?_with_tokyotyrant} \ %{?_with_turbostat} \ %{?_with_unixsock} \ %{?_with_uptime} \ %{?_with_users} \ %{?_with_uuid} \ + %{?_with_varnish} \ + %{?_with_virt} \ %{?_with_vmem} \ %{?_with_vserver} \ %{?_with_wireless}\ %{?_with_write_graphite} \ %{?_with_write_http} \ + %{?_with_write_http} \ + %{?_with_write_kafka} \ %{?_with_write_log} \ + %{?_with_write_mongodb} \ + %{?_with_write_redis} \ %{?_with_write_riemann} \ %{?_with_write_sensu} \ - %{?_with_write_tsdb} + %{?_with_write_tsdb} \ + %{?_with_xencpu} \ + %{?_with_xmms} \ + %{?_with_zfs_arc} \ + %{?_with_zone} \ + %{?_with_zookeeper} %{__make} %{?_smp_mflags} @@ -1733,7 +1866,7 @@ Collectd utilities %install rm -rf %{buildroot} %{__make} install DESTDIR=%{buildroot} -%if 0%{?el7:1} +%if 0%{?fedora} || 0%{?rhel} >= 7 %{__install} -Dp -m0644 contrib/systemd.collectd.service %{buildroot}%{_unitdir}/collectd.service %else %{__install} -Dp -m0755 contrib/redhat/init.d-collectd %{buildroot}%{_initrddir}/collectd @@ -1767,6 +1900,10 @@ rm -f %{buildroot}%{_datadir}/collectd/java/generic-jmx.jar rm -f %{buildroot}%{_mandir}/man5/collectd-java.5* %endif +%if ! %{with_lua} +rm -f %{buildroot}%{_mandir}/man5/collectd-lua.5* +%endif + %if ! %{with_perl} rm -f %{buildroot}%{_mandir}/man5/collectd-perl.5* rm -f %{buildroot}%{_mandir}/man3/Collectd::Unixsock.3pm* @@ -1789,26 +1926,15 @@ rm -f %{buildroot}%{_mandir}/man5/collectd-snmp.5* %clean rm -rf %{buildroot} -%pre -%if 0%{?el7:1} -# stop sysv-based instance before upgrading to systemd -if [ $1 -eq 2 ] && [ -f /var/lock/subsys/collectd ]; then - SYSTEMCTL_SKIP_REDIRECT=1 %{_initddir}/collectd stop >/dev/null 2>&1 || : -fi -%endif - %post -%if 0%{?el7:1} -if [ $1 -eq 2 ]; then - /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || : -fi +%if 0%{?fedora} || 0%{?rhel} >= 7 %systemd_post collectd.service %else /sbin/chkconfig --add collectd || : %endif %preun -%if 0%{?el7:1} +%if 0%{?fedora} || 0%{?rhel} >= 7 %systemd_preun collectd.service %else # stop collectd only when uninstalling @@ -1819,7 +1945,7 @@ fi %endif %postun -%if 0%{?el7:1} +%if 0%{?fedora} || 0%{?rhel} >= 7 %systemd_postun_with_restart collectd.service %else # restart collectd only when upgrading @@ -1835,7 +1961,7 @@ fi %files %doc AUTHORS COPYING ChangeLog README %config(noreplace) %{_sysconfdir}/collectd.conf -%if 0%{?el7:1} +%if 0%{?fedora} || 0%{?rhel} >= 7 %{_unitdir}/collectd.service %else %{_initrddir}/collectd @@ -1889,6 +2015,9 @@ fi %if %{with_cpufreq} %{_libdir}/%{name}/cpufreq.so %endif +%if %{with_cpusleep} +%{_libdir}/%{name}/cpusleep.so +%endif %if %{with_csv} %{_libdir}/%{name}/csv.so %endif @@ -1958,6 +2087,9 @@ fi %if %{with_nfs} %{_libdir}/%{name}/nfs.so %endif +%if %{with_notify_nagios} +%{_libdir}/%{name}/notify_nagios.so +%endif %if %{with_ntpd} %{_libdir}/%{name}/ntpd.so %endif @@ -2112,6 +2244,11 @@ fi %{_libdir}/%{name}/ceph.so %endif +%if %{with_chrony} +%files chrony +%{_libdir}/%{name}/chrony.so +%endif + %if %{with_curl} %files curl %{_libdir}/%{name}/curl.so @@ -2152,6 +2289,16 @@ fi %{_libdir}/%{name}/gmond.so %endif +%if %{with_gps} +%files gps +%{_libdir}/%{name}/gps.so +%endif + +%if %{with_grpc} +%files grpc +%{_libdir}/%{name}/grpc.so +%endif + %if %{with_hddtemp} %files hddtemp %{_libdir}/%{name}/hddtemp.so @@ -2185,6 +2332,12 @@ fi %{_libdir}/%{name}/log_logstash.so %endif +%if %{with_lua} +%files lua +%{_mandir}/man5/collectd-lua* +%{_libdir}/%{name}/lua.so +%endif + %if %{with_lvm} %files lvm %{_libdir}/%{name}/lvm.so @@ -2205,6 +2358,11 @@ fi %{_libdir}/%{name}/modbus.so %endif +%if %{with_mqtt} +%files mqtt +%{_libdir}/%{name}/mqtt.so +%endif + %if %{with_mysql} %files mysql %{_libdir}/%{name}/mysql.so @@ -2332,6 +2490,11 @@ fi %{_libdir}/%{name}/write_riemann.so %endif +%if %{with_xencpu} +%files xencpu +%{_libdir}/%{name}/xencpu.so +%endif + %if %{with_xmms} %files xmms %{_libdir}/%{name}/xmms.so @@ -2349,6 +2512,11 @@ fi %doc contrib/ %changelog +* Sun Aug 14 2016 Ruben Kerkhof - 5.6.0-1 +- New PRE-RELEASE version +- New plugins enabled by default: chrony, cpusleep, gps, lua, mqtt, notify_nagios +- New plugins disabled by default: grpc, xencpu, zone + * Tue Jul 26 2016 Ruben Kerkhof - 5.5.2-1 - New upstream version - Contains fix for CVE-2016-6254 diff --git a/contrib/systemd.collectd.service b/contrib/systemd.collectd.service index c7806fed..d0f1bdea 100644 --- a/contrib/systemd.collectd.service +++ b/contrib/systemd.collectd.service @@ -1,7 +1,8 @@ [Unit] -Description=Collectd -After=local-fs.target network.target -Requires=local-fs.target network.target +Description=Collectd statistics daemon +Documentation=man:collectd(1) man:collectd.conf(5) +After=local-fs.target network-online.target +Requires=local-fs.target network-online.target [Service] ExecStart=/usr/sbin/collectd @@ -33,7 +34,7 @@ NoNewPrivileges=true # socket once the daemon is ready. See systemd.service(5) for more details. Type=notify -# Restart the collectd daemon after a 10 seconds delay, in case it crashes. +# Restart the collectd daemon when it fails. Restart=on-failure [Install] diff --git a/proto/Makefile.am b/proto/Makefile.am new file mode 100644 index 00000000..3c0bfd7f --- /dev/null +++ b/proto/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = collectd.proto types.proto diff --git a/proto/collectd.proto b/proto/collectd.proto new file mode 100644 index 00000000..917c5deb --- /dev/null +++ b/proto/collectd.proto @@ -0,0 +1,62 @@ +// collectd - proto/collectd.proto +// Copyright (C) 2015-2016 Sebastian Harl +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// Authors: +// Sebastian Harl + +syntax = "proto3"; + +package collectd; +option go_package = "collectd.org/rpc/proto"; + +import "types.proto"; + +service Collectd { + // DispatchValues reads the value lists from the DispatchValuesRequest stream. + // The gRPC server embedded into collectd will inject them into the system + // just like the network plugin. + rpc DispatchValues(stream DispatchValuesRequest) + returns (DispatchValuesResponse); + + // QueryValues returns a stream of matching value lists from collectd's + // internal cache. + rpc QueryValues(QueryValuesRequest) returns (stream QueryValuesResponse); +} + +// The arguments to DispatchValues. +message DispatchValuesRequest { + // value_list is the metric to be sent to the server. + collectd.types.ValueList value_list = 1; +} + +// The response from DispatchValues. +message DispatchValuesResponse {} + +// The arguments to QueryValues. +message QueryValuesRequest { + // Query by the fields of the identifier. Only return values matching the + // specified shell wildcard patterns (see fnmatch(3)). Use '*' to match + // any value. + collectd.types.Identifier identifier = 1; +} + +// The response from QueryValues. +message QueryValuesResponse { collectd.types.ValueList value_list = 1; } diff --git a/proto/types.proto b/proto/types.proto new file mode 100644 index 00000000..952c5418 --- /dev/null +++ b/proto/types.proto @@ -0,0 +1,59 @@ +// collectd - proto/types.proto +// Copyright (C) 2015-2016 Sebastian Harl +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// Authors: +// Sebastian Harl + +syntax = "proto3"; + +package collectd.types; +option go_package = "collectd.org/rpc/proto/types"; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +message Identifier { + string host = 1; + string plugin = 2; + string plugin_instance = 3; + string type = 4; + string type_instance = 5; +} + +message Value { + oneof value { + uint64 counter = 1; + double gauge = 2; + int64 derive = 3; + uint64 absolute = 4; + }; +} + +message ValueList { + repeated Value values = 1; + + google.protobuf.Timestamp time = 2; + google.protobuf.Duration interval = 3; + + Identifier identifier = 4; + + repeated string ds_names = 5; +} diff --git a/src/Makefile.am b/src/Makefile.am index dc07cb74..dbd5bb91 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,10 +6,6 @@ SUBDIRS += daemon PLUGIN_LDFLAGS = -module -avoid-version -export-symbols-regex '\' -if COMPILER_IS_GCC -AM_CFLAGS = -Wall -Werror -endif - AM_CPPFLAGS = -I$(srcdir)/daemon AM_CPPFLAGS += -DPREFIX='"${prefix}"' AM_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"' @@ -21,25 +17,69 @@ endif AM_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"' AM_CPPFLAGS += -DPKGDATADIR='"${pkgdatadir}"' -AUTOMAKE_OPTIONS = subdir-objects - -noinst_LTLIBRARIES = libmount.la liblookup.la +LOG_COMPILER = env VALGRIND="@VALGRIND@" $(abs_top_srcdir)/testwrapper.sh + +V_PROTOC = $(v_protoc_@AM_V@) +v_protoc_ = $(v_protoc_@AM_DEFAULT_V@) +v_protoc_0 = @echo " PROTOC " $@; + +noinst_LTLIBRARIES = +check_PROGRAMS = +TESTS = + +noinst_LTLIBRARIES += libformat_json.la +libformat_json_la_SOURCES = utils_format_json.c utils_format_json.h +libformat_json_la_CPPFLAGS = $(AM_CPPFLAGS) +libformat_json_la_LDFLAGS = $(AM_LDFLAGS) +libformat_json_la_LIBADD = +if BUILD_WITH_LIBYAJL +libformat_json_la_CPPFLAGS += $(BUILD_WITH_LIBYAJL_CPPFLAGS) +libformat_json_la_LDFLAGS += $(BUILD_WITH_LIBYAJL_LDFLAGS) +libformat_json_la_LIBADD += $(BUILD_WITH_LIBYAJL_LIBS) +check_PROGRAMS += test_format_json +TESTS += test_format_json +test_format_json_SOURCES = utils_format_json_test.c testing.h +test_format_json_LDADD = libformat_json.la daemon/libmetadata.la daemon/libplugin_mock.la -lm +endif + +noinst_LTLIBRARIES += liblatency.la +liblatency_la_SOURCES = utils_latency.c utils_latency.h +check_PROGRAMS += test_utils_latency +TESTS += test_utils_latency +test_utils_latency_SOURCES = utils_latency_test.c testing.h +test_utils_latency_LDADD = liblatency.la daemon/libplugin_mock.la -lm + +noinst_LTLIBRARIES += liblookup.la +liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h +liblookup_la_LIBADD = daemon/libavltree.la +check_PROGRAMS += test_utils_vl_lookup +TESTS += test_utils_vl_lookup +test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h +test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la +if BUILD_WITH_LIBKSTAT +test_utils_vl_lookup_LDADD += -lkstat +endif +noinst_LTLIBRARIES += libmount.la libmount_la_SOURCES = utils_mount.c utils_mount.h -libmount_la_LIBADD = daemon/libcommon.la - -liblookup_la_SOURCES = utils_vl_lookup.c utils_vl_lookup.h -liblookup_la_LIBADD = daemon/libavltree.la daemon/libcommon.la +check_PROGRAMS += test_utils_mount +TESTS += test_utils_mount +test_utils_mount_SOURCES = utils_mount_test.c testing.h +test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la +if BUILD_WITH_LIBKSTAT +test_utils_mount_LDADD += -lkstat +endif sbin_PROGRAMS = collectdmon bin_PROGRAMS = collectd-nagios collectdctl collectd-tg collectdmon_SOURCES = collectdmon.c -collectdmon_CPPFLAGS = $(AM_CPPFLAGS) collectd_nagios_SOURCES = collectd-nagios.c -collectd_nagios_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd -collectd_nagios_LDADD = +collectd_nagios_CPPFLAGS = $(AM_CPPFLAGS) \ + -I$(top_srcdir)/src/libcollectdclient/collectd \ + -I$(top_builddir)/src/libcollectdclient/collectd +collectd_nagios_LDADD = libcollectdclient/libcollectdclient.la if BUILD_WITH_LIBSOCKET collectd_nagios_LDADD += -lsocket endif @@ -47,26 +87,28 @@ if BUILD_AIX collectd_nagios_LDADD += -lm endif -collectd_nagios_LDADD += libcollectdclient/libcollectdclient.la -collectd_nagios_DEPENDENCIES = libcollectdclient/libcollectdclient.la - collectdctl_SOURCES = collectdctl.c -collectdctl_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd -collectdctl_LDADD = +collectdctl_CPPFLAGS = $(AM_CPPFLAGS) \ + -I$(top_srcdir)/src/libcollectdclient/collectd \ + -I$(top_builddir)/src/libcollectdclient/collectd +collectdctl_LDADD = libcollectdclient/libcollectdclient.la if BUILD_WITH_LIBSOCKET collectdctl_LDADD += -lsocket endif if BUILD_AIX collectdctl_LDADD += -lm endif -collectdctl_LDADD += libcollectdclient/libcollectdclient.la -collectdctl_DEPENDENCIES = libcollectdclient/libcollectdclient.la + collectd_tg_SOURCES = collectd-tg.c collectd_tg_CPPFLAGS = $(AM_CPPFLAGS) \ - -I$(top_srcdir)/src/libcollectdclient/collectd -I$(top_builddir)/src/libcollectdclient/collectd -collectd_tg_LDADD = daemon/libheap.la + -I$(top_srcdir)/src/libcollectdclient/collectd \ + -I$(top_builddir)/src/libcollectdclient/collectd +collectd_tg_LDADD = \ + $(PTHREAD_LIBS) \ + daemon/libheap.la \ + libcollectdclient/libcollectdclient.la if BUILD_WITH_LIBSOCKET collectd_tg_LDADD += -lsocket endif @@ -76,11 +118,6 @@ endif if BUILD_AIX collectd_tg_LDADD += -lm endif -if BUILD_WITH_LIBPTHREAD -collectd_tg_LDADD += -lpthread -endif -collectd_tg_LDADD += libcollectdclient/libcollectdclient.la -collectd_tg_DEPENDENCIES = libcollectdclient/libcollectdclient.la pkglib_LTLIBRARIES = @@ -88,6 +125,24 @@ pkglib_LTLIBRARIES = BUILT_SOURCES = CLEANFILES = +if HAVE_PROTOC3 +if HAVE_GRPC_CPP +BUILT_SOURCES += collectd.grpc.pb.cc collectd.pb.cc types.pb.cc +CLEANFILES += collectd.grpc.pb.cc collectd.pb.cc types.pb.cc \ + collectd.grpc.pb.h collectd.pb.h types.pb.h + +collectd.grpc.pb.cc: $(top_srcdir)/proto/collectd.proto $(top_srcdir)/proto/types.proto + $(V_PROTOC)@PROTOC@ -I$(top_srcdir)/proto \ + --grpc_out=$(builddir) --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN) $< + +collectd.pb.cc: $(top_srcdir)/proto/collectd.proto $(top_srcdir)/proto/types.proto + $(V_PROTOC)@PROTOC@ -I$(top_srcdir)/proto --cpp_out=$(builddir) $< + +types.pb.cc: $(top_srcdir)/proto/types.proto + $(V_PROTOC)@PROTOC@ -I$(top_srcdir)/proto --cpp_out=$(builddir) $< +endif +endif + if BUILD_PLUGIN_AGGREGATION pkglib_LTLIBRARIES += aggregation.la aggregation_la_SOURCES = aggregation.c \ @@ -100,26 +155,22 @@ if BUILD_PLUGIN_AMQP pkglib_LTLIBRARIES += amqp.la amqp_la_SOURCES = amqp.c \ utils_cmd_putval.c utils_cmd_putval.h \ - utils_parse_option.c utils_parse_option.h \ - utils_format_graphite.c utils_format_graphite.h \ - utils_format_json.c utils_format_json.h + utils_parse_option.c utils_parse_option.h \ + utils_format_graphite.c utils_format_graphite.h amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS) amqp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRABBITMQ_CPPFLAGS) -amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS) +amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS) libformat_json.la endif if BUILD_PLUGIN_APACHE pkglib_LTLIBRARIES += apache.la apache_la_SOURCES = apache.c apache_la_LDFLAGS = $(PLUGIN_LDFLAGS) -apache_la_CFLAGS = $(AM_CFLAGS) -apache_la_LIBADD = -if BUILD_WITH_LIBCURL -apache_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS) -apache_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS) -endif +apache_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) +apache_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) endif + if BUILD_PLUGIN_APCUPS pkglib_LTLIBRARIES += apcups.la apcups_la_SOURCES = apcups.c @@ -133,16 +184,15 @@ endif if BUILD_PLUGIN_APPLE_SENSORS pkglib_LTLIBRARIES += apple_sensors.la apple_sensors_la_SOURCES = apple_sensors.c -apple_sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) -apple_sensors_la_LDFLAGS += -framework IOKit +apple_sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) -framework IOKit endif if BUILD_PLUGIN_AQUAERO pkglib_LTLIBRARIES += aquaero.la aquaero_la_SOURCES = aquaero.c -aquaero_la_LDFLAGS = $(PLUGIN_LDFLAGS) aquaero_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBAQUAERO5_CFLAGS) -aquaero_la_LIBADD = $(BUILD_WITH_LIBAQUAERO5_LDFLAGS) -laquaero5 +aquaero_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBAQUAERO5_LDFLAGS) +aquaero_la_LIBADD = -laquaero5 endif if BUILD_PLUGIN_ASCENT @@ -165,7 +215,6 @@ if BUILD_PLUGIN_BATTERY pkglib_LTLIBRARIES += battery.la battery_la_SOURCES = battery.c battery_la_LDFLAGS = $(PLUGIN_LDFLAGS) -battery_la_LIBADD = if BUILD_WITH_LIBIOKIT battery_la_LDFLAGS += -framework IOKit endif @@ -196,6 +245,12 @@ cgroups_la_LDFLAGS = $(PLUGIN_LDFLAGS) cgroups_la_LIBADD = libmount.la endif +if BUILD_PLUGIN_CHRONY +pkglib_LTLIBRARIES += chrony.la +chrony_la_SOURCES = chrony.c +chrony_la_LDFLAGS = $(PLUGIN_LDFLAGS) +endif + if BUILD_PLUGIN_CONNTRACK pkglib_LTLIBRARIES += conntrack.la conntrack_la_SOURCES = conntrack.c @@ -239,6 +294,12 @@ cpufreq_la_SOURCES = cpufreq.c cpufreq_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif +if BUILD_PLUGIN_CPUSLEEP +pkglib_LTLIBRARIES += cpusleep.la +cpusleep_la_SOURCES = cpusleep.c +cpusleep_la_LDFLAGS = $(PLUGIN_LDFLAGS) +endif + if BUILD_PLUGIN_CSV pkglib_LTLIBRARIES += csv.la csv_la_SOURCES = csv.c @@ -247,32 +308,27 @@ endif if BUILD_PLUGIN_CURL pkglib_LTLIBRARIES += curl.la -curl_la_SOURCES = curl.c +curl_la_SOURCES = curl.c \ + utils_curl_stats.c utils_curl_stats.h curl_la_LDFLAGS = $(PLUGIN_LDFLAGS) -curl_la_CFLAGS = $(AM_CFLAGS) -curl_la_LIBADD = -if BUILD_WITH_LIBCURL -curl_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS) -curl_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS) -endif +curl_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) +curl_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) endif if BUILD_PLUGIN_CURL_JSON pkglib_LTLIBRARIES += curl_json.la -curl_json_la_SOURCES = curl_json.c -curl_json_la_CFLAGS = $(AM_CFLAGS) -curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) +curl_json_la_SOURCES = curl_json.c \ + utils_curl_stats.c utils_curl_stats.h +curl_json_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) curl_json_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) -curl_json_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS) -if BUILD_WITH_LIBCURL -curl_json_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS) -curl_json_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS) -endif +curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) +curl_json_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) endif if BUILD_PLUGIN_CURL_XML pkglib_LTLIBRARIES += curl_xml.la -curl_xml_la_SOURCES = curl_xml.c +curl_xml_la_SOURCES = curl_xml.c \ + utils_curl_stats.c utils_curl_stats.h curl_xml_la_LDFLAGS = $(PLUGIN_LDFLAGS) curl_xml_la_CFLAGS = $(AM_CFLAGS) \ $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS) @@ -319,6 +375,9 @@ disk_la_CFLAGS += $(BUILD_WITH_LIBUDEV_CFLAGS) disk_la_LDFLAGS += $(BUILD_WITH_LIBUDEV_LDFLAGS) disk_la_LIBADD += $(BUILD_WITH_LIBUDEV_LIBS) endif +if BUILD_FREEBSD +disk_la_LIBADD += -ldevstat -lgeom +endif if BUILD_WITH_PERFSTAT disk_la_LIBADD += -lperfstat endif @@ -328,21 +387,19 @@ if BUILD_PLUGIN_DNS pkglib_LTLIBRARIES += dns.la dns_la_SOURCES = dns.c utils_dns.c utils_dns.h dns_la_LDFLAGS = $(PLUGIN_LDFLAGS) -dns_la_LIBADD = -lpcap -lpthread +dns_la_LIBADD = -lpcap endif if BUILD_PLUGIN_DRBD pkglib_LTLIBRARIES += drbd.la drbd_la_SOURCES = drbd.c drbd_la_LDFLAGS = $(PLUGIN_LDFLAGS) -drbd_la_LIBADD = -lpthread endif if BUILD_PLUGIN_EMAIL pkglib_LTLIBRARIES += email.la email_la_SOURCES = email.c email_la_LDFLAGS = $(PLUGIN_LDFLAGS) -email_la_LIBADD = -lpthread endif if BUILD_PLUGIN_ENTROPY @@ -358,7 +415,6 @@ exec_la_SOURCES = exec.c \ utils_cmd_putval.c utils_cmd_putval.h \ utils_parse_option.h utils_parse_option.c exec_la_LDFLAGS = $(PLUGIN_LDFLAGS) -exec_la_LIBADD = -lpthread endif if BUILD_PLUGIN_ETHSTAT @@ -387,6 +443,23 @@ gmond_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(GANGLIA_LDFLAGS) gmond_la_LIBADD = $(GANGLIA_LIBS) endif +if BUILD_PLUGIN_GPS +pkglib_LTLIBRARIES += gps.la +gps_la_SOURCES = gps.c +gps_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBGPS_CFLAGS) +gps_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBGPS_LDFLAGS) +gps_la_LIBADD = -lpthread $(BUILD_WITH_LIBGPS_LIBS) +endif + +if BUILD_PLUGIN_GRPC +pkglib_LTLIBRARIES += grpc.la +grpc_la_SOURCES = grpc.cc +nodist_grpc_la_SOURCES = collectd.grpc.pb.cc collectd.pb.cc types.pb.cc +grpc_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBGRPCPP_CPPFLAGS) $(BUILD_WITH_LIBPROTOBUF_CPPFLAGS) +grpc_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBGRPCPP_LDFLAGS) $(BUILD_WITH_LIBPROTOBUF_LDFLAGS) +grpc_la_LIBADD = $(BUILD_WITH_LIBGRPCPP_LIBS) $(BUILD_WITH_LIBPROTOBUF_LIBS) +endif + if BUILD_PLUGIN_HDDTEMP pkglib_LTLIBRARIES += hddtemp.la hddtemp_la_SOURCES = hddtemp.c @@ -422,7 +495,6 @@ endif # BUILD_PLUGIN_INTERFACE if BUILD_PLUGIN_IPC pkglib_LTLIBRARIES += ipc.la ipc_la_SOURCES = ipc.c -ipc_la_CFLAGS = $(AM_CFLAGS) ipc_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif @@ -445,8 +517,9 @@ endif if BUILD_PLUGIN_IPVS pkglib_LTLIBRARIES += ipvs.la ipvs_la_SOURCES = ipvs.c +ipvs_la_CFLAGS = $(AM_CFLAGS) if IP_VS_H_NEEDS_KERNEL_CFLAGS -ipvs_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) +ipvs_la_CFLAGS += $(KERNEL_CFLAGS) endif ipvs_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif @@ -490,7 +563,6 @@ endif if BUILD_PLUGIN_LOG_LOGSTASH pkglib_LTLIBRARIES += log_logstash.la log_logstash_la_SOURCES = log_logstash.c -log_logstash_la_CFLAGS = $(AM_CFLAGS) log_logstash_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) log_logstash_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) log_logstash_la_LIBADD = $(BUILD_WITH_LIBYAJL_LIBS) @@ -503,10 +575,20 @@ lpar_la_LDFLAGS = $(PLUGIN_LDFLAGS) lpar_la_LIBADD = -lperfstat endif +if BUILD_PLUGIN_LUA +pkglib_LTLIBRARIES += lua.la +lua_la_SOURCES = lua.c \ + utils_lua.c utils_lua.h +lua_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBLUA_CFLAGS) +lua_la_LDFLAGS = $(PLUGIN_LDFLAGS) +lua_la_LIBADD = $(BUILD_WITH_LIBLUA_LIBS) +endif + if BUILD_PLUGIN_LVM pkglib_LTLIBRARIES += lvm.la lvm_la_SOURCES = lvm.c -lvm_la_LDFLAGS = $(PLUGIN_LDFLAGS) +lvm_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBLVM2APP_CPPFLAGS) +lvm_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBLVM2APP_LDFLAGS) lvm_la_LIBADD = $(BUILD_WITH_LIBLVM2APP_LIBS) endif @@ -617,6 +699,14 @@ modbus_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBMODBUS_CFLAGS) modbus_la_LIBADD = $(BUILD_WITH_LIBMODBUS_LIBS) endif +if BUILD_PLUGIN_MQTT +pkglib_LTLIBRARIES += mqtt.la +mqtt_la_SOURCES = mqtt.c +mqtt_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBMOSQUITTO_CPPFLAGS) +mqtt_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBMOSQUITTO_LDFLAGS) +mqtt_la_LIBADD = $(BUILD_WITH_LIBMOSQUITTO_LIBS) +endif + if BUILD_PLUGIN_MULTIMETER pkglib_LTLIBRARIES += multimeter.la multimeter_la_SOURCES = multimeter.c @@ -626,13 +716,9 @@ endif if BUILD_PLUGIN_MYSQL pkglib_LTLIBRARIES += mysql.la mysql_la_SOURCES = mysql.c +mysql_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBMYSQL_CFLAGS) mysql_la_LDFLAGS = $(PLUGIN_LDFLAGS) -mysql_la_CFLAGS = $(AM_CFLAGS) -mysql_la_LIBADD = -if BUILD_WITH_LIBMYSQL -mysql_la_CFLAGS += $(BUILD_WITH_LIBMYSQL_CFLAGS) -mysql_la_LIBADD += $(BUILD_WITH_LIBMYSQL_LIBS) -endif +mysql_la_LIBADD = $(BUILD_WITH_LIBMYSQL_LIBS) endif if BUILD_PLUGIN_NETAPP @@ -657,7 +743,7 @@ network_la_SOURCES = network.c network.h \ utils_fbhash.c utils_fbhash.h network_la_CPPFLAGS = $(AM_CPPFLAGS) network_la_LDFLAGS = $(PLUGIN_LDFLAGS) -network_la_LIBADD = -lpthread +network_la_LIBADD = if BUILD_WITH_LIBSOCKET network_la_LIBADD += -lsocket endif @@ -683,13 +769,9 @@ endif if BUILD_PLUGIN_NGINX pkglib_LTLIBRARIES += nginx.la nginx_la_SOURCES = nginx.c -nginx_la_CFLAGS = $(AM_CFLAGS) -nginx_la_LIBADD = +nginx_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) nginx_la_LDFLAGS = $(PLUGIN_LDFLAGS) -if BUILD_WITH_LIBCURL -nginx_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS) -nginx_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS) -endif +nginx_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) endif if BUILD_PLUGIN_NOTIFY_DESKTOP @@ -704,7 +786,13 @@ if BUILD_PLUGIN_NOTIFY_EMAIL pkglib_LTLIBRARIES += notify_email.la notify_email_la_SOURCES = notify_email.c notify_email_la_LDFLAGS = $(PLUGIN_LDFLAGS) -notify_email_la_LIBADD = -lesmtp -lssl -lcrypto -lpthread +notify_email_la_LIBADD = -lesmtp -lssl -lcrypto +endif + +if BUILD_PLUGIN_NOTIFY_NAGIOS +pkglib_LTLIBRARIES += notify_nagios.la +notify_nagios_la_SOURCES = notify_nagios.c +notify_nagios_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif if BUILD_PLUGIN_NTPD @@ -728,7 +816,7 @@ pkglib_LTLIBRARIES += nut.la nut_la_SOURCES = nut.c nut_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBUPSCLIENT_CFLAGS) nut_la_LDFLAGS = $(PLUGIN_LDFLAGS) -nut_la_LIBADD = -lpthread $(BUILD_WITH_LIBUPSCLIENT_LIBS) +nut_la_LIBADD = $(BUILD_WITH_LIBUPSCLIENT_LIBS) endif if BUILD_PLUGIN_OLSRD @@ -744,24 +832,22 @@ endif if BUILD_PLUGIN_ONEWIRE pkglib_LTLIBRARIES += onewire.la onewire_la_SOURCES = onewire.c -onewire_la_CFLAGS = $(AM_CFLAGS) onewire_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBOWCAPI_CPPFLAGS) onewire_la_LIBADD = $(BUILD_WITH_LIBOWCAPI_LIBS) -onewire_la_LDFLAGS = $(PLUGIN_LDFLAGS) +onewire_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBOWCAPI_LDFLAGS) endif if BUILD_PLUGIN_OPENLDAP pkglib_LTLIBRARIES += openldap.la openldap_la_SOURCES = openldap.c -openldap_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBLDAP_LDFLAGS) -openldap_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBLDAP_CPPFLAGS) +openldap_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBLDAP_CPPFLAGS) +openldap_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBLDAP_LDFLAGS) openldap_la_LIBADD = -lldap endif if BUILD_PLUGIN_OPENVPN pkglib_LTLIBRARIES += openvpn.la openvpn_la_SOURCES = openvpn.c -openvpn_la_CFLAGS = $(AM_CFLAGS) openvpn_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif @@ -769,8 +855,7 @@ if BUILD_PLUGIN_ORACLE pkglib_LTLIBRARIES += oracle.la oracle_la_SOURCES = oracle.c \ utils_db_query.c utils_db_query.h -oracle_la_CFLAGS = $(AM_CFLAGS) -oracle_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_ORACLE_CFLAGS) +oracle_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_ORACLE_CPPFLAGS) oracle_la_LIBADD = $(BUILD_WITH_ORACLE_LIBS) oracle_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif @@ -781,6 +866,10 @@ perl_la_SOURCES = perl.c # Despite C99 providing the "bool" type thru stdbool.h, Perl defines its own # version of that type if HAS_BOOL is not defined... *sigh* perl_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAS_BOOL=1 +# Despite off_t being 64 bit wide on 64 bit platforms, Perl insist on using +# off64_t which is only exposed when _LARGEFILE64_SOURCE is defined... *sigh* +# On older platforms we also need _REENTRANT. _GNU_SOURCE sets both of these. +perl_la_CPPFLAGS += -D_GNU_SOURCE perl_la_CFLAGS = $(AM_CFLAGS) \ $(PERL_CFLAGS) \ -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\" @@ -804,8 +893,9 @@ if BUILD_PLUGIN_PINBA pkglib_LTLIBRARIES += pinba.la pinba_la_SOURCES = pinba.c nodist_pinba_la_SOURCES = pinba.pb-c.c pinba.pb-c.h -pinba_la_LDFLAGS = $(PLUGIN_LDFLAGS) -pinba_la_LIBADD = -lprotobuf-c +pinba_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPROTOBUF_C_CPPFLAGS) +pinba_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBPROTOBUF_C_LDFLAGS) +pinba_la_LIBADD = $(BUILD_WITH_LIBPROTOBUF_C_LIBS) endif if BUILD_PLUGIN_PING @@ -835,13 +925,11 @@ endif if BUILD_PLUGIN_PYTHON pkglib_LTLIBRARIES += python.la python_la_SOURCES = python.c pyconfig.c pyvalues.c cpython.h -python_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_PYTHON_CPPFLAGS) -python_la_CFLAGS = $(AM_CFLAGS) +python_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBPYTHON_CPPFLAGS) if COMPILER_IS_GCC -python_la_CFLAGS += -fno-strict-aliasing -Wno-strict-aliasing +python_la_CPPFLAGS += -fno-strict-aliasing -Wno-strict-aliasing endif -python_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_PYTHON_LDFLAGS) -python_la_LIBADD = $(BUILD_WITH_PYTHON_LIBS) +python_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBPYTHON_LDFLAGS) endif if BUILD_PLUGIN_PROCESSES @@ -909,9 +997,9 @@ endif if BUILD_PLUGIN_SIGROK pkglib_LTLIBRARIES += sigrok.la sigrok_la_SOURCES = sigrok.c -sigrok_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSIGROK_CFLAGS) -sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSIGROK_LDFLAGS) -sigrok_la_LIBADD = -lsigrok +sigrok_la_CFLAGS = $(AM_CFLAGS) $(LIBSIGROK_CFLAGS) +sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS) +sigrok_la_LIBADD = $(LIBSIGROK_LIBS) endif if BUILD_PLUGIN_SMART @@ -927,24 +1015,16 @@ endif if BUILD_PLUGIN_SNMP pkglib_LTLIBRARIES += snmp.la snmp_la_SOURCES = snmp.c -snmp_la_LDFLAGS = $(PLUGIN_LDFLAGS) -snmp_la_CFLAGS = $(AM_CFLAGS) -snmp_la_LIBADD = -if BUILD_WITH_LIBNETSNMP -snmp_la_CFLAGS += $(BUILD_WITH_LIBSNMP_CFLAGS) -snmp_la_LIBADD += $(BUILD_WITH_LIBSNMP_LIBS) -endif -if BUILD_WITH_LIBPTHREAD -snmp_la_LIBADD += -lpthread -endif +snmp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBNETSNMP_CPPFLAGS) +snmp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBNETSNMP_LDFLAGS) +snmp_la_LIBADD = $(BUILD_WITH_LIBNETSNMP_LIBS) endif if BUILD_PLUGIN_STATSD pkglib_LTLIBRARIES += statsd.la -statsd_la_SOURCES = statsd.c \ - utils_latency.h utils_latency.c +statsd_la_SOURCES = statsd.c statsd_la_LDFLAGS = $(PLUGIN_LDFLAGS) -statsd_la_LIBADD = -lpthread -lm +statsd_la_LIBADD = liblatency.la -lm endif if BUILD_PLUGIN_SWAP @@ -1095,7 +1175,6 @@ unixsock_la_SOURCES = unixsock.c \ utils_cmd_putnotif.h utils_cmd_putnotif.c \ utils_parse_option.h utils_parse_option.c unixsock_la_LDFLAGS = $(PLUGIN_LDFLAGS) -unixsock_la_LIBADD = -lpthread endif if BUILD_PLUGIN_UPTIME @@ -1170,34 +1249,29 @@ endif if BUILD_PLUGIN_WRITE_GRAPHITE pkglib_LTLIBRARIES += write_graphite.la write_graphite_la_SOURCES = write_graphite.c \ - utils_format_graphite.c utils_format_graphite.h \ - utils_format_json.c utils_format_json.h + utils_format_graphite.c utils_format_graphite.h write_graphite_la_LDFLAGS = $(PLUGIN_LDFLAGS) +write_graphite_la_LIBADD = libformat_json.la endif if BUILD_PLUGIN_WRITE_HTTP pkglib_LTLIBRARIES += write_http.la write_http_la_SOURCES = write_http.c \ - utils_format_json.c utils_format_json.h + utils_format_kairosdb.c utils_format_kairosdb.h write_http_la_LDFLAGS = $(PLUGIN_LDFLAGS) -write_http_la_CFLAGS = $(AM_CFLAGS) -write_http_la_LIBADD = -if BUILD_WITH_LIBCURL -write_http_la_CFLAGS += $(BUILD_WITH_LIBCURL_CFLAGS) -write_http_la_LIBADD += $(BUILD_WITH_LIBCURL_LIBS) -endif +write_http_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) +write_http_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) libformat_json.la endif if BUILD_PLUGIN_WRITE_KAFKA pkglib_LTLIBRARIES += write_kafka.la write_kafka_la_SOURCES = write_kafka.c \ utils_format_graphite.c utils_format_graphite.h \ - utils_format_json.c utils_format_json.h \ utils_cmd_putval.c utils_cmd_putval.h \ utils_crc32.c utils_crc32.h write_kafka_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRDKAFKA_CPPFLAGS) write_kafka_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRDKAFKA_LDFLAGS) -write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS) +write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS) libformat_json.la endif if BUILD_PLUGIN_WRITE_LOG @@ -1219,16 +1293,15 @@ if BUILD_PLUGIN_WRITE_REDIS pkglib_LTLIBRARIES += write_redis.la write_redis_la_SOURCES = write_redis.c write_redis_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBHIREDIS_LDFLAGS) -write_redis_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBHIREDIS_CPPFLAGS) +write_redis_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBHIREDIS_CPPFLAGS) write_redis_la_LIBADD = -lhiredis endif if BUILD_PLUGIN_WRITE_RIEMANN pkglib_LTLIBRARIES += write_riemann.la write_riemann_la_SOURCES = write_riemann.c write_riemann_threshold.c write_riemann_threshold.h -nodist_write_riemann_la_SOURCES = riemann.pb-c.c riemann.pb-c.h -write_riemann_la_LDFLAGS = $(PLUGIN_LDFLAGS) -write_riemann_la_LIBADD = -lprotobuf-c +write_riemann_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBRIEMANN_CLIENT_LIBS) +write_riemann_la_CFLAGS = $(AM_CFLAGS) $(LIBRIEMANN_CLIENT_CFLAGS) endif if BUILD_PLUGIN_WRITE_SENSU @@ -1243,6 +1316,14 @@ write_tsdb_la_SOURCES = write_tsdb.c write_tsdb_la_LDFLAGS = $(PLUGIN_LDFLAGS) endif +if BUILD_PLUGIN_XENCPU +pkglib_LTLIBRARIES += xencpu.la +xencpu_la_SOURCES = xencpu.c +xencpu_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBXENCTL_CPPFLAGS) +xencpu_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBXENCTL_LDFLAGS) +xencpu_la_LIBADD = -lxenctrl +endif + if BUILD_PLUGIN_XMMS pkglib_LTLIBRARIES += xmms.la xmms_la_SOURCES = xmms.c @@ -1254,17 +1335,12 @@ endif if BUILD_PLUGIN_ZFS_ARC pkglib_LTLIBRARIES += zfs_arc.la zfs_arc_la_SOURCES = zfs_arc.c -zfs_arc_la_CFLAGS = $(AM_CFLAGS) zfs_arc_la_LDFLAGS = $(PLUGIN_LDFLAGS) if BUILD_FREEBSD zfs_arc_la_LIBADD = -lm -else -if BUILD_LINUX -# zfs_arc requires no library on linux -else -# solaris -zfs_arc_la_LIBADD = -lkstat endif +if BUILD_SOLARIS +zfs_arc_la_LIBADD = -lkstat endif endif @@ -1276,12 +1352,19 @@ endif BUILT_SOURCES += $(dist_man_MANS) +if BUILD_PLUGIN_ZONE +pkglib_LTLIBRARIES += zone.la +zone_la_SOURCES = zone.c +zone_la_LDFLAGS = $(PLUGIN_LDFLAGS) +endif + dist_man_MANS = collectd.1 \ collectd.conf.5 \ collectd-email.5 \ collectd-exec.5 \ collectdctl.1 \ collectd-java.5 \ + collectd-lua.5 \ collectdmon.1 \ collectd-nagios.1 \ collectd-perl.5 \ @@ -1292,15 +1375,12 @@ dist_man_MANS = collectd.1 \ collectd-unixsock.5 \ types.db.5 -#collectd_1_SOURCES = collectd.pod - -EXTRA_DIST = types.db - -EXTRA_DIST += collectd.conf.pod \ +EXTRA_DIST = collectd.conf.pod \ collectd-email.pod \ collectd-exec.pod \ collectdctl.pod \ collectd-java.pod \ + collectd-lua.pod \ collectdmon.pod \ collectd-nagios.pod \ collectd-perl.pod \ @@ -1311,10 +1391,17 @@ EXTRA_DIST += collectd.conf.pod \ collectd-threshold.pod \ collectd-unixsock.pod \ postgresql_default.conf \ - types.db.pod + types.db \ + types.db.pod \ + valgrind.FreeBSD.suppress + +AM_V_POD2MAN_C = $(am__v_POD2MAN_C_@AM_V@) +am__v_POD2MAN_C_ = $(am__v_POD2MAN_C_@AM_DEFAULT_V@) +am__v_POD2MAN_C_0 = @echo " POD2MAN " $@; +am__v_POD2MAN_C_1 = .pod.1: - pod2man --release=$(VERSION) --center=$(PACKAGE) $< \ + $(AM_V_POD2MAN_C)pod2man --release=$(VERSION) --center=$(PACKAGE) $< \ >.pod2man.tmp.$$$$ 2>/dev/null && mv -f .pod2man.tmp.$$$$ $@ || true @if grep '\' $@ >/dev/null 2>&1; \ then \ @@ -1322,7 +1409,7 @@ EXTRA_DIST += collectd.conf.pod \ fi .pod.5: - pod2man --section=5 --release=$(VERSION) --center=$(PACKAGE) $< \ + $(AM_V_POD2MAN_C)pod2man --section=5 --release=$(VERSION) --center=$(PACKAGE) $< \ >.pod2man.tmp.$$$$ 2>/dev/null && mv -f .pod2man.tmp.$$$$ $@ || true @if grep '\' $@ >/dev/null 2>&1; \ then \ @@ -1331,7 +1418,7 @@ EXTRA_DIST += collectd.conf.pod \ AM_V_PROTOC_C = $(am__v_PROTOC_C_@AM_V@) am__v_PROTOC_C_ = $(am__v_PROTOC_C_@AM_DEFAULT_V@) -am__v_PROTOC_C_0 = @echo " PROTOC-C " $@; +am__v_PROTOC_C_0 = @echo " PROTOC-C" $@; am__v_PROTOC_C_1 = # Protocol buffer for the "pinba" plugin. @@ -1341,18 +1428,7 @@ CLEANFILES += pinba.pb-c.c pinba.pb-c.h BUILT_SOURCES += pinba.pb-c.c pinba.pb-c.h pinba.pb-c.c pinba.pb-c.h: pinba.proto - $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto -endif - -# Protocol buffer for the "write_riemann" plugin. -EXTRA_DIST += riemann.proto -if BUILD_PLUGIN_WRITE_RIEMANN -CLEANFILES += riemann.pb-c.c riemann.pb-c.h - -BUILT_SOURCES += riemann.pb-c.c riemann.pb-c.h - -riemann.pb-c.c riemann.pb-c.h: riemann.proto - $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto + $(AM_V_PROTOC_C)$(PROTOC_C) -I$(srcdir) --c_out . $(srcdir)/pinba.proto endif install-exec-hook: @@ -1373,27 +1449,11 @@ uninstall-hook: rm -f $(DESTDIR)$(sysconfdir)/collectd.conf rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf; -check_PROGRAMS = test_utils_mount test_utils_vl_lookup - -test_utils_mount_SOURCES = utils_mount_test.c testing.h -test_utils_mount_LDADD = libmount.la daemon/libplugin_mock.la -if BUILD_WITH_LIBKSTAT -test_utils_mount_LDADD += -lkstat -endif - -test_utils_vl_lookup_SOURCES = utils_vl_lookup_test.c testing.h -test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la -if BUILD_WITH_LIBKSTAT -test_utils_vl_lookup_LDADD += -lkstat -endif - -TESTS = test_utils_mount test_utils_vl_lookup - if BUILD_PLUGIN_CEPH test_plugin_ceph_SOURCES = ceph_test.c test_plugin_ceph_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) test_plugin_ceph_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) -test_plugin_ceph_LDADD = daemon/libcommon.la daemon/libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS) +test_plugin_ceph_LDADD = daemon/libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS) check_PROGRAMS += test_plugin_ceph TESTS += test_plugin_ceph endif diff --git a/src/aggregation.c b/src/aggregation.c index 56e4955c..2744c89e 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -26,11 +26,8 @@ #include "collectd.h" -#include - #include "plugin.h" #include "common.h" -#include "configfile.h" #include "meta_data.h" #include "utils_cache.h" /* for uc_get_rate() */ #include "utils_subst.h" @@ -240,13 +237,12 @@ static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */ DEBUG ("aggregation plugin: Creating new instance."); - inst = malloc (sizeof (*inst)); + inst = calloc (1, sizeof (*inst)); if (inst == NULL) { - ERROR ("aggregation plugin: malloc() failed."); + ERROR ("aggregation plugin: calloc() failed."); return (NULL); } - memset (inst, 0, sizeof (*inst)); pthread_mutex_init (&inst->lock, /* attr = */ NULL); inst->ds_type = ds->ds[0].type; @@ -259,14 +255,13 @@ static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */ #define INIT_STATE(field) do { \ inst->state_ ## field = NULL; \ if (agg->calc_ ## field) { \ - inst->state_ ## field = malloc (sizeof (*inst->state_ ## field)); \ + inst->state_ ## field = calloc (1, sizeof (*inst->state_ ## field)); \ if (inst->state_ ## field == NULL) { \ agg_instance_destroy (inst); \ free (inst); \ - ERROR ("aggregation plugin: malloc() failed."); \ + ERROR ("aggregation plugin: calloc() failed."); \ return (NULL); \ } \ - memset (inst->state_ ## field, 0, sizeof (*inst->state_ ## field)); \ } \ } while (0) @@ -350,7 +345,6 @@ static int agg_instance_read_func (agg_instance_t *inst, /* {{{ */ else sstrncpy (vl->plugin_instance, func, sizeof (vl->plugin_instance)); - memset (&v, 0, sizeof (v)); status = rate_to_value (&v, rate, state, inst->ds_type, t); if (status != 0) { @@ -488,9 +482,7 @@ static void agg_lookup_free_obj_callback (void *user_obj) /* {{{ */ static int agg_config_handle_group_by (oconfig_item_t const *ci, /* {{{ */ aggregation_t *agg) { - int i; - - for (i = 0; i < ci->values_num; i++) + for (int i = 0; i < ci->values_num; i++) { char const *value; @@ -526,15 +518,13 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ aggregation_t *agg; _Bool is_valid; int status; - int i; - agg = malloc (sizeof (*agg)); + agg = calloc (1, sizeof (*agg)); if (agg == NULL) { - ERROR ("aggregation plugin: malloc failed."); + ERROR ("aggregation plugin: calloc failed."); return (-1); } - memset (agg, 0, sizeof (*agg)); sstrncpy (agg->ident.host, "/.*/", sizeof (agg->ident.host)); sstrncpy (agg->ident.plugin, "/.*/", sizeof (agg->ident.plugin)); @@ -544,7 +534,7 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ sstrncpy (agg->ident.type_instance, "/.*/", sizeof (agg->ident.type_instance)); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -682,8 +672,6 @@ static int agg_config_aggregation (oconfig_item_t *ci) /* {{{ */ static int agg_config (oconfig_item_t *ci) /* {{{ */ { - int i; - pthread_mutex_lock (&agg_instance_list_lock); if (lookup == NULL) @@ -700,7 +688,7 @@ static int agg_config (oconfig_item_t *ci) /* {{{ */ } } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -718,7 +706,6 @@ static int agg_config (oconfig_item_t *ci) /* {{{ */ static int agg_read (void) /* {{{ */ { - agg_instance_t *this; cdtime_t t; int success; @@ -739,7 +726,7 @@ static int agg_read (void) /* {{{ */ return (0); } - for (this = agg_instance_list_head; this != NULL; this = this->next) + for (agg_instance_t *this = agg_instance_list_head; this != NULL; this = this->next) { int status; diff --git a/src/amqp.c b/src/amqp.c index 4206bdc1..89f051e8 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -27,14 +27,13 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_cmd_putval.h" #include "utils_format_json.h" #include "utils_format_graphite.h" -#include - #include #include @@ -529,13 +528,11 @@ static int camqp_connect (camqp_config_t *conf) /* {{{ */ static int camqp_shutdown (void) /* {{{ */ { - size_t i; - DEBUG ("amqp plugin: Shutting down %zu subscriber threads.", subscriber_threads_num); subscriber_threads_running = 0; - for (i = 0; i < subscriber_threads_num; i++) + for (size_t i = 0; i < subscriber_threads_num; i++) { /* FIXME: Sending a signal is not very elegant here. Maybe find out how * to use a timeout in the thread and check for the variable in regular @@ -736,7 +733,7 @@ static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ if (tmp == NULL) { ERROR ("amqp plugin: realloc failed."); - camqp_config_free (conf); + sfree (subscriber_threads); return (ENOMEM); } subscriber_threads = tmp; @@ -750,7 +747,6 @@ static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ char errbuf[1024]; ERROR ("amqp plugin: pthread_create failed: %s", sstrerror (status, errbuf, sizeof (errbuf))); - camqp_config_free (conf); return (status); } @@ -766,17 +762,20 @@ static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ static int camqp_write_locked (camqp_config_t *conf, /* {{{ */ const char *buffer, const char *routing_key) { - amqp_basic_properties_t props; int status; status = camqp_connect (conf); if (status != 0) return (status); - memset (&props, 0, sizeof (props)); - props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG - | AMQP_BASIC_DELIVERY_MODE_FLAG - | AMQP_BASIC_APP_ID_FLAG; + amqp_basic_properties_t props = { + ._flags = AMQP_BASIC_CONTENT_TYPE_FLAG + | AMQP_BASIC_DELIVERY_MODE_FLAG + | AMQP_BASIC_APP_ID_FLAG, + .delivery_mode = conf->delivery_mode, + .app_id = amqp_cstring_bytes("collectd") + }; + if (conf->format == CAMQP_FORMAT_COMMAND) props.content_type = amqp_cstring_bytes("text/collectd"); else if (conf->format == CAMQP_FORMAT_JSON) @@ -785,8 +784,6 @@ static int camqp_write_locked (camqp_config_t *conf, /* {{{ */ props.content_type = amqp_cstring_bytes("text/graphite"); else assert (23 == 42); - props.delivery_mode = conf->delivery_mode; - props.app_id = amqp_cstring_bytes("collectd"); status = amqp_basic_publish(conf->connection, /* channel = */ 1, @@ -817,15 +814,12 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ if ((ds == NULL) || (vl == NULL) || (conf == NULL)) return (EINVAL); - memset (buffer, 0, sizeof (buffer)); - if (conf->routing_key != NULL) { sstrncpy (routing_key, conf->routing_key, sizeof (routing_key)); } else { - size_t i; ssnprintf (routing_key, sizeof (routing_key), "collectd/%s/%s/%s/%s/%s", vl->host, vl->plugin, vl->plugin_instance, @@ -833,7 +827,7 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ /* Switch slashes (the only character forbidden by collectd) and dots * (the separation character used by AMQP). */ - for (i = 0; routing_key[i] != 0; i++) + for (size_t i = 0; routing_key[i] != 0; i++) { if (routing_key[i] == '.') routing_key[i] = '/'; @@ -923,17 +917,15 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ { camqp_config_t *conf; int status; - int i; - conf = malloc (sizeof (*conf)); + conf = calloc (1, sizeof (*conf)); if (conf == NULL) { - ERROR ("amqp plugin: malloc failed."); + ERROR ("amqp plugin: calloc failed."); return (ENOMEM); } /* Initialize "conf" {{{ */ - memset (conf, 0, sizeof (*conf)); conf->publish = publish; conf->name = NULL; conf->format = CAMQP_FORMAT_COMMAND; @@ -971,7 +963,7 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ return (status); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1104,9 +1096,7 @@ static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ static int camqp_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/apache.c b/src/apache.c index c515e3c5..e10a15d4 100644 --- a/src/apache.c +++ b/src/apache.c @@ -25,9 +25,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include @@ -63,8 +63,10 @@ typedef struct apache_s apache_t; /* TODO: Remove this prototype */ static int apache_read_host (user_data_t *user_data); -static void apache_free (apache_t *st) +static void apache_free (void *arg) { + apache_t *st = arg; + if (st == NULL) return; @@ -98,14 +100,14 @@ static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, return (0); } - if (len <= 0) + if (len == 0) return (len); if ((st->apache_buffer_fill + len) >= st->apache_buffer_size) { char *temp; - temp = (char *) realloc (st->apache_buffer, + temp = realloc (st->apache_buffer, st->apache_buffer_fill + len + 1); if (temp == NULL) { @@ -137,7 +139,7 @@ static size_t apache_header_callback (void *buf, size_t size, size_t nmemb, return (0); } - if (len <= 0) + if (len == 0) return (len); /* look for the Server header */ @@ -172,16 +174,14 @@ static size_t apache_header_callback (void *buf, size_t size, size_t nmemb, static int config_add (oconfig_item_t *ci) { apache_t *st; - int i; int status; - st = malloc (sizeof (*st)); + st = calloc (1, sizeof (*st)); if (st == NULL) { - ERROR ("apache plugin: malloc failed."); + ERROR ("apache plugin: calloc failed."); return (-1); } - memset (st, 0, sizeof (*st)); st->timeout = -1; @@ -193,7 +193,7 @@ static int config_add (oconfig_item_t *ci) } assert (st->name != NULL); - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -239,14 +239,13 @@ static int config_add (oconfig_item_t *ci) if (status == 0) { - user_data_t ud; - char callback_name[3*DATA_MAX_NAME_LEN]; + user_data_t ud = { + .data = st, + .free_func = apache_free + }; - memset (&ud, 0, sizeof (ud)); - ud.data = st; - ud.free_func = (void *) apache_free; + char callback_name[3*DATA_MAX_NAME_LEN]; - memset (callback_name, 0, sizeof (callback_name)); ssnprintf (callback_name, sizeof (callback_name), "apache/%s/%s", (st->host != NULL) ? st->host : hostname_g, @@ -255,7 +254,7 @@ static int config_add (oconfig_item_t *ci) status = plugin_register_complex_read (/* group = */ NULL, /* name = */ callback_name, /* callback = */ apache_read_host, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); } @@ -271,9 +270,8 @@ static int config_add (oconfig_item_t *ci) static int config (oconfig_item_t *ci) { int status = 0; - int i; - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -383,8 +381,7 @@ static int init_host (apache_t *st) /* {{{ */ if (st->timeout >= 0) curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, (long) st->timeout); else - curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, - CDTIME_T_TO_MS(plugin_get_interval())); + curl_easy_setopt (st->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval())); #endif return (0); @@ -465,8 +462,7 @@ static void submit_scoreboard (char *buf, apache_t *st) long long response_start = 0LL; long long response_end = 0LL; - int i; - for (i = 0; buf[i] != '\0'; i++) + for (int i = 0; buf[i] != '\0'; i++) { if (buf[i] == '.') open++; else if (buf[i] == '_') waiting++; diff --git a/src/apcups.c b/src/apcups.c index 281bf980..af5f24c7 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -1,6 +1,6 @@ /* * collectd - src/apcups.c - * Copyright (C) 2006-2012 Florian octo Forster + * Copyright (C) 2006-2015 Florian octo Forster * Copyright (C) 2006 Anthony Gialluca * Copyright (C) 2000-2004 Kern Sibbald * Copyright (C) 1996-1999 Andre M. Hedrick @@ -25,16 +25,13 @@ **/ #include "collectd.h" + #include "common.h" /* rrd_update_file */ #include "plugin.h" /* plugin_register, plugin_submit */ -#include "configfile.h" /* cf_register */ #if HAVE_SYS_TYPES_H # include #endif -#if HAVE_SYS_SOCKET_H -# include -#endif #if HAVE_NETDB_H # include #endif @@ -43,11 +40,17 @@ # include #endif -#define NISPORT 3551 -#define MAXSTRING 256 -#define MODULE_NAME "apcups" +#ifndef APCUPS_SERVER_TIMEOUT +# define APCUPS_SERVER_TIMEOUT 15.0 +#endif -#define APCUPS_DEFAULT_HOST "localhost" +#ifndef APCUPS_DEFAULT_NODE +# define APCUPS_DEFAULT_NODE "localhost" +#endif + +#ifndef APCUPS_DEFAULT_SERVICE +# define APCUPS_DEFAULT_SERVICE "3551" +#endif /* * Private data types @@ -68,24 +71,16 @@ struct apc_detail_s * Private variables */ /* Default values for contacting daemon */ -static char *conf_host = NULL; -static int conf_port = NISPORT; +static char *conf_node = NULL; +static char *conf_service = NULL; /* Defaults to false for backwards compatibility. */ static _Bool conf_report_seconds = 0; +static _Bool conf_persistent_conn = 1; static int global_sockfd = -1; static int count_retries = 0; static int count_iterations = 0; -static _Bool close_socket = 0; - -static const char *config_keys[] = -{ - "Host", - "Port", - "ReportSeconds" -}; -static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static int net_shutdown (int *fd) { @@ -94,7 +89,7 @@ static int net_shutdown (int *fd) if ((fd == NULL) || (*fd < 0)) return (EINVAL); - swrite (*fd, (void *) &packet_size, sizeof (packet_size)); + (void)swrite (*fd, (void *) &packet_size, sizeof (packet_size)); close (*fd); *fd = -1; @@ -116,26 +111,20 @@ static int apcups_shutdown (void) * Returns -1 on error * Returns socket file descriptor otherwise */ -static int net_open (char *host, int port) +static int net_open (char const *node, char const *service) { int sd; int status; - char port_str[8]; - struct addrinfo ai_hints; struct addrinfo *ai_return; struct addrinfo *ai_list; - assert ((port > 0x00000000) && (port <= 0x0000FFFF)); - - /* Convert the port to a string */ - ssnprintf (port_str, sizeof (port_str), "%i", port); + /* TODO: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */ + struct addrinfo ai_hints = { + .ai_family = AF_INET, + .ai_socktype = SOCK_STREAM + }; - /* Resolve name */ - memset ((void *) &ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_family = AF_INET; /* XXX: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */ - ai_hints.ai_socktype = SOCK_STREAM; - - status = getaddrinfo (host, port_str, &ai_hints, &ai_return); + status = getaddrinfo (node, service, &ai_hints, &ai_return); if (status != 0) { char errbuf[1024]; @@ -179,7 +168,7 @@ static int net_open (char *host, int port) DEBUG ("apcups plugin: Done opening a socket %i", sd); return (sd); -} /* int net_open (char *host, char *service, int port) */ +} /* int net_open */ /* * Receive a message from the other end. Each message consists of @@ -234,7 +223,7 @@ static int net_recv (int *sockfd, char *buf, int buflen) * Returns zero on success * Returns non-zero on error */ -static int net_send (int *sockfd, char *buff, int len) +static int net_send (int *sockfd, const char *buff, int len) { uint16_t packet_size; @@ -263,7 +252,7 @@ static int net_send (int *sockfd, char *buff, int len) } /* Get and print status from apcupsd NIS server */ -static int apc_query_server (char *host, int port, +static int apc_query_server (char const *node, char const *service, struct apc_detail_s *apcups_detail) { int n; @@ -285,7 +274,7 @@ static int apc_query_server (char *host, int port, { if (global_sockfd < 0) { - global_sockfd = net_open (host, port); + global_sockfd = net_open (node, service); if (global_sockfd < 0) { ERROR ("apcups plugin: Connecting to the " @@ -325,13 +314,13 @@ static int apc_query_server (char *host, int port, "first %i iterations. Will close the socket " "in future iterations.", count_retries, count_iterations); - close_socket = 1; + conf_persistent_conn = 0; } while ((n = net_recv (&global_sockfd, recvline, sizeof (recvline) - 1)) > 0) { - assert ((unsigned int)n < sizeof (recvline)); - recvline[n] = '\0'; + assert ((size_t)n < sizeof (recvline)); + recvline[n] = 0; #if APCMAIN printf ("net_recv = `%s';\n", recvline); #endif /* if APCMAIN */ @@ -375,7 +364,7 @@ static int apc_query_server (char *host, int port, } status = errno; /* save errno, net_shutdown() may re-set it. */ - if (close_socket) + if (!conf_persistent_conn) net_shutdown (&global_sockfd); if (n < 0) @@ -389,43 +378,43 @@ static int apc_query_server (char *host, int port, return (0); } -static int apcups_config (const char *key, const char *value) +static int apcups_config (oconfig_item_t *ci) { - if (strcasecmp (key, "host") == 0) - { - if (conf_host != NULL) - { - free (conf_host); - conf_host = NULL; - } - if ((conf_host = strdup (value)) == NULL) - return (1); - } - else if (strcasecmp (key, "Port") == 0) + _Bool persistent_conn_set = 0; + + for (int i = 0; i < ci->children_num; i++) { - int port_tmp = atoi (value); - if (port_tmp < 1 || port_tmp > 65535) - { - WARNING ("apcups plugin: Invalid port: %i", port_tmp); - return (1); + oconfig_item_t *child = ci->children + i; + + if (strcasecmp (child->key, "Host") == 0) + cf_util_get_string (child, &conf_node); + else if (strcasecmp (child->key, "Port") == 0) + cf_util_get_service (child, &conf_service); + else if (strcasecmp (child->key, "ReportSeconds") == 0) + cf_util_get_boolean (child, &conf_report_seconds); + else if (strcasecmp (child->key, "PersistentConnection") == 0) { + cf_util_get_boolean (child, &conf_persistent_conn); + persistent_conn_set = 1; } - conf_port = port_tmp; - } - else if (strcasecmp (key, "ReportSeconds") == 0) - { - if (IS_TRUE (value)) - conf_report_seconds = 1; else - conf_report_seconds = 0; + ERROR ("apcups plugin: Unknown config option \"%s\".", child->key); } - else - { - return (-1); + + if (!persistent_conn_set) { + double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval()); + if (interval > APCUPS_SERVER_TIMEOUT) { + NOTICE ("apcups plugin: Plugin poll interval set to %.3f seconds. " + "Apcupsd NIS socket timeout is %.3f seconds, " + "PersistentConnection disabled by default.", + interval, APCUPS_SERVER_TIMEOUT); + conf_persistent_conn = 0; + } } + return (0); -} +} /* int apcups_config */ -static void apc_submit_generic (char *type, char *type_inst, double value) +static void apc_submit_generic (const char *type, const char *type_inst, double value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -469,10 +458,9 @@ static int apcups_read (void) apcups_detail.itemp = -300.0; apcups_detail.linefreq = -1.0; - status = apc_query_server (conf_host == NULL - ? APCUPS_DEFAULT_HOST - : conf_host, - conf_port, &apcups_detail); + status = apc_query_server ((conf_node == NULL) ? APCUPS_DEFAULT_NODE : conf_node, + (conf_service == NULL) ? APCUPS_DEFAULT_SERVICE : conf_service, + &apcups_detail); /* * if we did not connect then do not bother submitting @@ -480,11 +468,10 @@ static int apcups_read (void) */ if (status != 0) { - DEBUG ("apcups plugin: apc_query_server (%s, %i) = %i", - conf_host == NULL - ? APCUPS_DEFAULT_HOST - : conf_host, - conf_port, status); + DEBUG ("apcups plugin: apc_query_server (%s, %s) = %i", + (conf_node == NULL) ? APCUPS_DEFAULT_NODE : conf_node, + (conf_service == NULL) ? APCUPS_DEFAULT_SERVICE : conf_service, + status); return (-1); } @@ -495,8 +482,7 @@ static int apcups_read (void) void module_register (void) { - plugin_register_config ("apcups", apcups_config, config_keys, - config_keys_num); + plugin_register_complex_config ("apcups", apcups_config); plugin_register_read ("apcups", apcups_read); plugin_register_shutdown ("apcups", apcups_shutdown); } /* void module_register */ diff --git a/src/apple_sensors.c b/src/apple_sensors.c index 19d5a49f..48fbcb91 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -59,7 +60,7 @@ static mach_port_t io_master_port = MACH_PORT_NULL; static int as_init (void) { kern_return_t status; - + if (io_master_port != MACH_PORT_NULL) { mach_port_deallocate (mach_task_self (), @@ -113,8 +114,6 @@ static int as_read (void) char inst[128]; int value_int; double value_double; - int i; - if (!io_master_port || (io_master_port == MACH_PORT_NULL)) return (-1); @@ -169,7 +168,7 @@ static int as_read (void) kCFStringEncodingASCII)) continue; inst[sizeof (inst) - 1] = '\0'; - for (i = 0; i < 128; i++) + for (int i = 0; i < 128; i++) { if (inst[i] == '\0') break; diff --git a/src/aquaero.c b/src/aquaero.c index 5db988e6..81a4efd4 100644 --- a/src/aquaero.c +++ b/src/aquaero.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -33,9 +34,7 @@ static char *conf_device = NULL; static int aquaero_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -87,9 +86,8 @@ static void aquaero_submit_array (const char *type, const char *type_instance_prefix, double *value_array, int len) { char type_instance[DATA_MAX_NAME_LEN]; - int i; - for (i = 0; i < len; i++) + for (int i = 0; i < len; i++) { if (value_array[i] == AQ5_FLOAT_UNDEF) continue; @@ -106,7 +104,6 @@ static int aquaero_read (void) aq5_settings_t aq_sett; char *err_msg = NULL; char type_instance[DATA_MAX_NAME_LEN]; - int i; if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0) { @@ -147,7 +144,7 @@ static int aquaero_read (void) AQ5_NUM_OTHER_SENSORS); /* Fans */ - for (i = 0; i < AQ5_NUM_FAN; i++) + for (int i = 0; i < AQ5_NUM_FAN; i++) { if ((aq_sett.fan_data_source[i] == NONE) || (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF)) diff --git a/src/ascent.c b/src/ascent.c index 11175af5..11bb97f0 100644 --- a/src/ascent.c +++ b/src/ascent.c @@ -25,14 +25,14 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include #include -static char *races_list[] = /* {{{ */ +static const char *races_list[] = /* {{{ */ { NULL, "Human", /* 1 */ @@ -49,7 +49,7 @@ static char *races_list[] = /* {{{ */ }; /* }}} */ #define RACES_LIST_LENGTH STATIC_ARRAY_SIZE (races_list) -static char *classes_list[] = /* {{{ */ +static const char *classes_list[] = /* {{{ */ { NULL, "Warrior", /* 1 */ @@ -66,7 +66,7 @@ static char *classes_list[] = /* {{{ */ }; /* }}} */ #define CLASSES_LIST_LENGTH STATIC_ARRAY_SIZE (classes_list) -static char *genders_list[] = /* {{{ */ +static const char *genders_list[] = /* {{{ */ { "Male", "Female" @@ -154,14 +154,14 @@ static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{ { size_t len = size * nmemb; - if (len <= 0) + if (len == 0) return (len); if ((ascent_buffer_fill + len) >= ascent_buffer_size) { char *temp; - temp = (char *) realloc (ascent_buffer, + temp = realloc (ascent_buffer, ascent_buffer_fill + len + 1); if (temp == NULL) { @@ -181,20 +181,19 @@ static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{ static int ascent_submit_players (player_stats_t *ps) /* {{{ */ { - size_t i; gauge_t value; - for (i = 0; i < RACES_LIST_LENGTH; i++) + for (size_t i = 0; i < RACES_LIST_LENGTH; i++) if (races_list[i] != NULL) ascent_submit_gauge ("by-race", "players", races_list[i], (gauge_t) ps->races[i]); - for (i = 0; i < CLASSES_LIST_LENGTH; i++) + for (size_t i = 0; i < CLASSES_LIST_LENGTH; i++) if (classes_list[i] != NULL) ascent_submit_gauge ("by-class", "players", classes_list[i], (gauge_t) ps->classes[i]); - for (i = 0; i < GENDERS_LIST_LENGTH; i++) + for (size_t i = 0; i < GENDERS_LIST_LENGTH; i++) if (genders_list[i] != NULL) ascent_submit_gauge ("by-gender", "players", genders_list[i], (gauge_t) ps->genders[i]); @@ -328,9 +327,7 @@ static int ascent_xml_read_int (xmlDoc *doc, xmlNode *node, /* {{{ */ static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */ player_info_t *pi) { - xmlNode *child; - - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -364,12 +361,11 @@ static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */ static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */ { - xmlNode *child; - player_stats_t ps; + player_stats_t ps = { + .level_sum = 0 + }; - memset (&ps, 0, sizeof (ps)); - - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -396,9 +392,7 @@ static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */ static int ascent_xml_status (xmlDoc *doc, xmlNode *node) /* {{{ */ { - xmlNode *child; - - for (child = node->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -438,7 +432,6 @@ static int ascent_xml (const char *data) /* {{{ */ { xmlDoc *doc; xmlNode *cur; - xmlNode *child; #if 0 doc = xmlParseMemory (data, strlen (data), @@ -469,7 +462,7 @@ static int ascent_xml (const char *data) /* {{{ */ return (-1); } - for (child = cur->xmlChildrenNode; child != NULL; child = child->next) + for (xmlNode *child = cur->xmlChildrenNode; child != NULL; child = child->next) { if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0) || (xmlStrcmp ((const xmlChar *) "text", child->name) == 0)) @@ -594,8 +587,7 @@ static int ascent_init (void) /* {{{ */ if (timeout != NULL) curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, atol(timeout)); else - curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, - CDTIME_T_TO_MS(plugin_get_interval())); + curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval())); #endif return (0); diff --git a/src/barometer.c b/src/barometer.c index aaedd70a..998932da 100644 --- a/src/barometer.c +++ b/src/barometer.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "utils_cache.h" #include "plugin.h" @@ -29,6 +30,7 @@ #include #include #include +#include /* ------------ MPL115 defines ------------ */ /* I2C address of the MPL115 sensor */ @@ -343,9 +345,9 @@ static temperature_list_t * temp_list = NULL; */ static int temp_list_add(temperature_list_t * list, const char * sensor) { - temperature_list_t * new_temp; + temperature_list_t *new_temp; - new_temp = (temperature_list_t *) malloc(sizeof(*new_temp)); + new_temp = malloc(sizeof (*new_temp)); if(new_temp == NULL) return -1; @@ -407,7 +409,6 @@ static int get_reference_temperature(double * result) gauge_t * values = NULL; /**< rate values */ size_t values_num = 0; /**< number of rate values */ - int i; gauge_t values_history[REF_TEMP_AVG_NUM]; @@ -445,11 +446,10 @@ static int get_reference_temperature(double * result) list->initialized = 1; list->num_values = values_num; - for(i=0; inum_values; ++i) + for(size_t i=0; inum_values; ++i) { - DEBUG ("barometer: get_reference_temperature - history %d: %lf", - i, - values_history[i]); + DEBUG ("barometer: get_reference_temperature - history %zu: %lf", + i, values_history[i]); if(!isnan(values_history[i])) { avg_sum += values_history[i]; @@ -501,11 +500,10 @@ static int get_reference_temperature(double * result) continue; } - for(i=0; i #endif @@ -143,7 +142,7 @@ static void submit_capacity (char const *plugin_instance, /* {{{ */ } /* }}} void submit_capacity */ #if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H -static double dict_get_double (CFDictionaryRef dict, char *key_string) /* {{{ */ +static double dict_get_double (CFDictionaryRef dict, const char *key_string) /* {{{ */ { double val_double; long long val_int; @@ -203,7 +202,6 @@ static void get_via_io_power_sources (double *ret_charge, /* {{{ */ CFTypeRef ps_obj; double temp_double; - int i; ps_raw = IOPSCopyPowerSourcesInfo (); ps_array = IOPSCopyPowerSourcesList (ps_raw); @@ -211,7 +209,7 @@ static void get_via_io_power_sources (double *ret_charge, /* {{{ */ DEBUG ("ps_array_len == %i", ps_array_len); - for (i = 0; i < ps_array_len; i++) + for (int i = 0; i < ps_array_len; i++) { ps_obj = CFArrayGetValueAtIndex (ps_array, i); ps_dict = IOPSGetPowerSourceDescription (ps_raw, ps_obj); @@ -276,7 +274,6 @@ static void get_via_generic_iokit (double *ret_capacity_full, /* {{{ */ CFDictionaryRef bat_root_dict; CFArrayRef bat_info_arry; CFIndex bat_info_arry_len; - CFIndex bat_info_arry_pos; CFDictionaryRef bat_info_dict; double temp_double; @@ -311,7 +308,7 @@ static void get_via_generic_iokit (double *ret_capacity_full, /* {{{ */ } bat_info_arry_len = CFArrayGetCount (bat_info_arry); - for (bat_info_arry_pos = 0; + for (CFIndex bat_info_arry_pos = 0; bat_info_arry_pos < bat_info_arry_len; bat_info_arry_pos++) { @@ -341,7 +338,7 @@ static void get_via_generic_iokit (double *ret_capacity_full, /* {{{ */ *ret_voltage = temp_double / 1000.0; } } - + CFRelease (bat_root_dict); } @@ -358,7 +355,7 @@ static int battery_read (void) /* {{{ */ * IOPowerSources. IOKit, on the other hand, only reports the full * capacity. We use the two to calculate the current charged capacity. */ gauge_t charge_rel = NAN; /* Current charge in percent */ - gauge_t capacity_charged = NAN; /* Charged capacity */ + gauge_t capacity_charged; /* Charged capacity */ gauge_t capacity_full = NAN; /* Total capacity */ gauge_t capacity_design = NAN; /* Full design capacity */ @@ -715,11 +712,10 @@ static int read_acpi (void) /* {{{ */ static int read_pmu (void) /* {{{ */ { - int i; - + int i = 0; /* The upper limit here is just a safeguard. If there is a system with * more than 100 batteries, this can easily be increased. */ - for (i = 0; i < 100; i++) + for (; i < 100; i++) { FILE *fh; @@ -804,9 +800,7 @@ static int battery_read (void) /* {{{ */ static int battery_config (oconfig_item_t *ci) { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; diff --git a/src/bind.c b/src/bind.c index 6eac159c..9b6b32e3 100644 --- a/src/bind.c +++ b/src/bind.c @@ -36,9 +36,9 @@ #endif /* STRPTIME_NEEDS_STANDARDS */ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" /* Some versions of libcurl don't include this themselves and then don't have * fd_set available. */ @@ -54,7 +54,7 @@ # define BIND_DEFAULT_URL "http://localhost:8053/" #endif -/* +/* * Some types used for the callback functions. `translation_table_ptr_t' and * `list_info_ptr_t' are passed to the callbacks in the `void *user_data' * pointer. @@ -277,14 +277,14 @@ static size_t bind_curl_callback (void *buf, size_t size, /* {{{ */ { size_t len = size * nmemb; - if (len <= 0) + if (len == 0) return (len); if ((bind_buffer_fill + len) >= bind_buffer_size) { char *temp; - temp = realloc(bind_buffer, bind_buffer_fill + len + 1); + temp = realloc (bind_buffer, bind_buffer_fill + len + 1); if (temp == NULL) { ERROR ("bind plugin: realloc failed."); @@ -309,12 +309,11 @@ static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */ time_t current_time, void *user_data) { translation_table_ptr_t *table = (translation_table_ptr_t *) user_data; - size_t i; if (table == NULL) return (-1); - for (i = 0; i < table->table_length; i++) + for (size_t i = 0; i < table->table_length; i++) { if (strcmp (table->table[i].xml_name, name) != 0) continue; @@ -417,7 +416,7 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */ xmlNode *node; char *str_ptr; char *tmp; - struct tm tm; + struct tm tm = { 0 }; xpathObj = xmlXPathEvalExpression (BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -458,7 +457,6 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */ return (-1); } - memset (&tm, 0, sizeof(tm)); tmp = strptime (str_ptr, "%Y-%m-%dT%T", &tm); xmlFree(str_ptr); if (tmp == NULL) @@ -474,7 +472,7 @@ static int bind_xml_read_timestamp (const char *xpath_expression, /* {{{ */ return (0); } /* }}} int bind_xml_read_timestamp */ -/* +/* * bind_parse_generic_name_value * * Reads statistics in the form: @@ -491,7 +489,6 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -503,19 +500,18 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { xmlNode *name_node = NULL; xmlNode *counter = NULL; xmlNode *parent; - xmlNode *child; parent = xpathObj->nodesetval->nodeTab[i]; DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;", (char *) parent->name); /* Iterate over all child nodes. */ - for (child = parent->xmlChildrenNode; + for (xmlNode *child = parent->xmlChildrenNode; child != NULL; child = child->next) { @@ -559,7 +555,7 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ * return (0); } /* }}} int bind_parse_generic_name_value */ -/* +/* * bind_parse_generic_value_list * * Reads statistics in the form: @@ -578,7 +574,6 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ * { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -590,12 +585,10 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ * num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { - xmlNode *child; - /* Iterate over all child nodes. */ - for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; + for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; child != NULL; child = child->next) { @@ -649,7 +642,6 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression { xmlXPathObject *xpathObj = NULL; int num_entries; - int i; xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) @@ -661,12 +653,10 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression num_entries = 0; /* Iterate over all matching nodes. */ - for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) + for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { - xmlNode *child; - /* Iterate over all child nodes. */ - for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; + for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; child != NULL; child = child->next) { @@ -714,7 +704,6 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *path_obj; char *zone_name = NULL; - int i; size_t j; if (version >= 3) @@ -738,7 +727,7 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) + for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) { zone_name = (char *) xmlNodeListGetString (doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1); @@ -774,7 +763,7 @@ static int bind_xml_stats_handle_zone (int version, xmlDoc *doc, /* {{{ */ { /* Parse the tag {{{ */ char plugin_instance[DATA_MAX_NAME_LEN]; translation_table_ptr_t table_ptr = - { + { nsstats_translation_table, nsstats_translation_table_length, plugin_instance @@ -817,7 +806,6 @@ static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *zone_nodes = NULL; xmlXPathContext *zone_path_context; - int i; zone_path_context = xmlXPathNewContext (doc); if (zone_path_context == NULL) @@ -834,7 +822,7 @@ static int bind_xml_stats_search_zones (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++) + for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) { node = zone_nodes->nodesetval->nodeTab[i]; assert (node != NULL); @@ -855,7 +843,6 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */ { char *view_name = NULL; cb_view_t *view; - int i; size_t j; if (version == 3) @@ -887,7 +874,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) + for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++) { view_name = (char *) xmlNodeListGetString (doc, path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1); @@ -955,7 +942,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */ { char plugin_instance[DATA_MAX_NAME_LEN]; translation_table_ptr_t table_ptr = - { + { resstats_translation_table, resstats_translation_table_length, plugin_instance @@ -1010,7 +997,6 @@ static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */ { xmlXPathObject *view_nodes = NULL; xmlXPathContext *view_path_context; - int i; view_path_context = xmlXPathNewContext (doc); if (view_path_context == NULL) @@ -1027,7 +1013,7 @@ static int bind_xml_stats_search_views (int version, xmlDoc *doc, /* {{{ */ return (-1); } - for (i = 0; i < view_nodes->nodesetval->nodeNr; i++) + for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) { xmlNode *node; @@ -1441,7 +1427,6 @@ static int bind_xml (const char *data) /* {{{ */ xmlXPathContext *xpathCtx = NULL; xmlXPathObject *xpathObj = NULL; int ret = -1; - int i; doc = xmlParseMemory (data, strlen (data)); if (doc == NULL) @@ -1471,7 +1456,7 @@ static int bind_xml (const char *data) /* {{{ */ } else { - for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) + for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlNode *node; char *attr_version; @@ -1533,7 +1518,7 @@ static int bind_xml (const char *data) /* {{{ */ return (-1); } - for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) + for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) { xmlNode *node; char *attr_version; @@ -1613,7 +1598,7 @@ static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */ return (-1); } - tmp = (char **) realloc (view->zones, + tmp = realloc (view->zones, sizeof (char *) * (view->zones_num + 1)); if (tmp == NULL) { @@ -1636,7 +1621,6 @@ static int bind_config_add_view_zone (cb_view_t *view, /* {{{ */ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ { cb_view_t *tmp; - int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -1644,7 +1628,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ return (-1); } - tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1)); + tmp = realloc (views, sizeof (*views) * (views_num + 1)); if (tmp == NULL) { ERROR ("bind plugin: realloc failed."); @@ -1668,7 +1652,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ return (-1); } - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1693,9 +1677,7 @@ static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */ static int bind_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -1758,7 +1740,7 @@ static int bind_init (void) /* {{{ */ curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L); #ifdef HAVE_CURLOPT_TIMEOUT_MS curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ? - (long) timeout : CDTIME_T_TO_MS(plugin_get_interval())); + (long) timeout : (long) CDTIME_T_TO_MS(plugin_get_interval())); #endif diff --git a/src/ceph.c b/src/ceph.c index 9c53a3e7..e6d3767b 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -27,6 +27,7 @@ #define _BSD_SOURCE #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -37,6 +38,9 @@ #if HAVE_YAJL_YAJL_VERSION_H #include #endif +#ifdef HAVE_SYS_CAPABILITY_H +# include +#endif #include #include @@ -45,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -97,7 +100,7 @@ enum ceph_dset_type_d }; /** Valid types for ceph defined in types.db */ -const char * ceph_dset_types [CEPH_DSET_TYPES_NUM] = +static const char * const ceph_dset_types [CEPH_DSET_TYPES_NUM] = {"ceph_latency", "ceph_bytes", "ceph_rate"}; /******* ceph_daemon *******/ @@ -164,7 +167,7 @@ static int convert_special_metrics = 1; static struct ceph_daemon **g_daemons = NULL; /** Number of elements in g_daemons */ -static int g_num_daemons = 0; +static size_t g_num_daemons = 0; /** * A set of data that we build up in memory while parsing the JSON. @@ -259,7 +262,10 @@ static int ceph_cb_boolean(void *ctx, int bool_val) #define BUFFER_ADD(dest, src) do { \ size_t dest_size = sizeof (dest); \ - strncat ((dest), (src), dest_size - strlen (dest)); \ + size_t dest_len = strlen (dest); \ + if (dest_size > dest_len) { \ + sstrncpy ((dest) + dest_len, (src), dest_size - dest_len); \ + } \ (dest)[dest_size - 1] = 0; \ } while (0) @@ -268,16 +274,14 @@ ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len) { yajl_struct *state = (yajl_struct*) ctx; char buffer[number_len+1]; - char key[2 * DATA_MAX_NAME_LEN]; + char key[2 * DATA_MAX_NAME_LEN] = { 0 }; _Bool latency_type = 0; - size_t i; int status; memcpy(buffer, number_val, number_len); - buffer[sizeof(buffer) - 1] = 0; + buffer[sizeof(buffer) - 1] = '\0'; - memset (key, 0, sizeof (key)); - for (i = 0; i < state->depth; i++) + for (size_t i = 0; i < state->depth; i++) { if (state->stack[i] == NULL) continue; @@ -293,6 +297,11 @@ ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len) { latency_type = 1; + /* depth >= 2 => (stack[-1] != NULL && stack[-2] != NULL) */ + assert ((state->depth < 2) + || ((state->stack[state->depth - 1] != NULL) + && (state->stack[state->depth - 2] != NULL))); + /* Super-special case for filestore.journal_wr_bytes.avgcount: For * some reason, Ceph schema encodes this as a count/sum pair while all * other "Bytes" data (excluding used/capacity bytes for OSD space) uses @@ -423,8 +432,7 @@ static void ceph_daemon_print(const struct ceph_daemon *d) static void ceph_daemons_print(void) { - int i; - for(i = 0; i < g_num_daemons; ++i) + for(size_t i = 0; i < g_num_daemons; ++i) { ceph_daemon_print(g_daemons[i]); } @@ -432,15 +440,15 @@ static void ceph_daemons_print(void) static void ceph_daemon_free(struct ceph_daemon *d) { - int i = 0; - for(; i < d->last_idx; i++) + for(int i = 0; i < d->last_idx; i++) { sfree(d->last_poll_data[i]); } sfree(d->last_poll_data); d->last_poll_data = NULL; d->last_idx = 0; - for(i = 0; i < d->ds_num; i++) + + for(int i = 0; i < d->ds_num; i++) { sfree(d->ds_names[i]); } @@ -549,10 +557,9 @@ static _Bool has_suffix (char const *str, char const *suffix) /* count_parts returns the number of elements a "foo.bar.baz" style key has. */ static size_t count_parts (char const *key) { - char const *ptr; size_t parts_num = 0; - for (ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.')) + for (const char *ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.')) parts_num++; return parts_num; @@ -594,7 +601,6 @@ static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name, { uint32_t type; char ds_name[DATA_MAX_NAME_LEN]; - memset(ds_name, 0, sizeof(ds_name)); if(convert_special_metrics) { @@ -624,7 +630,7 @@ static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name, return -ENOMEM; } - d->ds_names[d->ds_num] = malloc(sizeof(char) * DATA_MAX_NAME_LEN); + d->ds_names[d->ds_num] = malloc(DATA_MAX_NAME_LEN); if(!d->ds_names[d->ds_num]) { return -ENOMEM; @@ -685,10 +691,9 @@ static int cc_handle_bool(struct oconfig_item_s *item, int *dest) static int cc_add_daemon_config(oconfig_item_t *ci) { - int ret, i; - struct ceph_daemon *nd, cd; + int ret; + struct ceph_daemon *nd, cd = { 0 }; struct ceph_daemon **tmp; - memset(&cd, 0, sizeof(struct ceph_daemon)); if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -703,7 +708,7 @@ static int cc_add_daemon_config(oconfig_item_t *ci) return ret; } - for(i=0; i < ci->children_num; i++) + for(int i=0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -748,21 +753,22 @@ static int cc_add_daemon_config(oconfig_item_t *ci) } g_daemons = tmp; - nd = malloc(sizeof(*nd)); + nd = malloc(sizeof (*nd)); if(!nd) { return ENOMEM; } memcpy(nd, &cd, sizeof(*nd)); - g_daemons[g_num_daemons++] = nd; + g_daemons[g_num_daemons] = nd; + g_num_daemons++; return 0; } static int ceph_config(oconfig_item_t *ci) { - int ret, i; + int ret; - for(i = 0; i < ci->children_num; ++i) + for(int i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; if(strcasecmp("Daemon", child->key) == 0) @@ -846,7 +852,7 @@ node_handler_define_schema(void *arg, const char *val, const char *key) static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum, uint64_t cur_count) { - d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data)); + d->last_poll_data[d->last_idx] = malloc(sizeof (*d->last_poll_data[d->last_idx])); if(!d->last_poll_data[d->last_idx]) { return -ENOMEM; @@ -874,7 +880,7 @@ static int update_last(struct ceph_daemon *d, const char *ds_n, int index, if(!d->last_poll_data) { - d->last_poll_data = malloc(1 * sizeof(struct last_data *)); + d->last_poll_data = malloc(sizeof (*d->last_poll_data)); if(!d->last_poll_data) { return -ENOMEM; @@ -899,8 +905,7 @@ static int update_last(struct ceph_daemon *d, const char *ds_n, int index, */ static int backup_search_for_last_avg(struct ceph_daemon *d, const char *ds_n) { - int i = 0; - for(; i < d->last_idx; i++) + for(int i = 0; i < d->last_idx; i++) { if(strcmp(d->last_poll_data[i]->ds_name, ds_n) == 0) { @@ -960,12 +965,11 @@ static double get_last_avg(struct ceph_daemon *d, const char *ds_n, int index, */ static uint32_t backup_search_for_type(struct ceph_daemon *d, char *ds_name) { - int idx = 0; - for(; idx < d->ds_num; idx++) + for(int i = 0; i < d->ds_num; i++) { - if(strcmp(d->ds_names[idx], ds_name) == 0) + if(strcmp(d->ds_names[i], ds_name) == 0) { - return d->ds_types[idx]; + return d->ds_types[i]; } } return DSET_TYPE_UNFOUND; @@ -984,7 +988,6 @@ static int node_handler_fetch_data(void *arg, const char *val, const char *key) int index = vtmp->index; char ds_name[DATA_MAX_NAME_LEN]; - memset(ds_name, 0, sizeof(ds_name)); if (parse_keys (ds_name, sizeof (ds_name), key)) { @@ -1087,7 +1090,7 @@ static int node_handler_fetch_data(void *arg, const char *val, const char *key) static int cconn_connect(struct cconn *io) { - struct sockaddr_un address; + struct sockaddr_un address = { 0 }; int flags, fd, err; if(io->state != CSTATE_UNCONNECTED) { @@ -1102,7 +1105,6 @@ static int cconn_connect(struct cconn *io) "failed: error %d", err); return err; } - memset(&address, 0, sizeof(struct sockaddr_un)); address.sun_family = AF_UNIX; snprintf(address.sun_path, sizeof(address.sun_path), "%s", io->d->asok_path); @@ -1462,7 +1464,7 @@ static int milli_diff(const struct timeval *t1, const struct timeval *t2) */ static int cconn_main_loop(uint32_t request_type) { - int i, ret, some_unreachable = 0; + int ret, some_unreachable = 0; struct timeval end_tv; struct cconn io_array[g_num_daemons]; @@ -1470,7 +1472,7 @@ static int cconn_main_loop(uint32_t request_type) /* create cconn array */ memset(io_array, 0, sizeof(io_array)); - for(i = 0; i < g_num_daemons; ++i) + for(size_t i = 0; i < g_num_daemons; ++i) { io_array[i].d = g_daemons[i]; io_array[i].request_type = request_type; @@ -1489,13 +1491,13 @@ static int cconn_main_loop(uint32_t request_type) struct pollfd fds[g_num_daemons]; memset(fds, 0, sizeof(fds)); nfds = 0; - for(i = 0; i < g_num_daemons; ++i) + for(size_t i = 0; i < g_num_daemons; ++i) { struct cconn *io = io_array + i; ret = cconn_prepare(io, fds + nfds); if(ret < 0) { - WARNING("ceph plugin: cconn_prepare(name=%s,i=%d,st=%d)=%d", + WARNING("ceph plugin: cconn_prepare(name=%s,i=%zu,st=%d)=%d", io->d->name, i, io->state, ret); cconn_close(io); io->request_type = ASOK_REQ_NONE; @@ -1527,13 +1529,14 @@ static int cconn_main_loop(uint32_t request_type) ERROR("ceph plugin: poll(2) error: %d", ret); goto done; } - for(i = 0; i < nfds; ++i) + for(int i = 0; i < nfds; ++i) { struct cconn *io = polled_io_array[i]; int revents = fds[i].revents; if(revents == 0) { /* do nothing */ + continue; } else if(cconn_validate_revents(io, revents)) { @@ -1558,7 +1561,7 @@ static int cconn_main_loop(uint32_t request_type) } } } - done: for(i = 0; i < g_num_daemons; ++i) + done: for(size_t i = 0; i < g_num_daemons; ++i) { cconn_close(io_array + i); } @@ -1581,18 +1584,35 @@ static int ceph_read(void) /******* lifecycle *******/ static int ceph_init(void) { - int ret; +#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_DAC_OVERRIDE) + if (check_capability (CAP_DAC_OVERRIDE) != 0) + { + if (getuid () == 0) + WARNING ("ceph plugin: Running collectd as root, but the " + "CAP_DAC_OVERRIDE capability is missing. The plugin's read " + "function will probably fail. Is your init system dropping " + "capabilities?"); + else + WARNING ("ceph plugin: collectd doesn't have the CAP_DAC_OVERRIDE " + "capability. If you don't want to run collectd as root, try running " + "\"setcap cap_dac_override=ep\" on the collectd binary."); + } +#endif + ceph_daemons_print(); - ret = cconn_main_loop(ASOK_REQ_VERSION); + if (g_num_daemons < 1) + { + ERROR ("ceph plugin: No daemons configured. See the \"Daemon\" config option."); + return ENOENT; + } - return (ret) ? ret : 0; + return cconn_main_loop(ASOK_REQ_VERSION); } static int ceph_shutdown(void) { - int i; - for(i = 0; i < g_num_daemons; ++i) + for(size_t i = 0; i < g_num_daemons; ++i) { ceph_daemon_free(g_daemons[i]); } diff --git a/src/ceph_test.c b/src/ceph_test.c index ae67125f..91f084f7 100644 --- a/src/ceph_test.c +++ b/src/ceph_test.c @@ -24,8 +24,8 @@ struct case_s { - char *key; - char *value; + const char *key; + const char *value; }; typedef struct case_s case_t; @@ -136,22 +136,23 @@ DEF_TEST(traverse_json) yajl_handle hndl; #if HAVE_YAJL_V2 hndl = yajl_alloc (&callbacks, NULL, &ctx); - CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl)); + CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl)); CHECK_ZERO (yajl_complete_parse (hndl)); #else hndl = yajl_alloc (&callbacks, NULL, NULL, &ctx); - CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl)); + CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl)); CHECK_ZERO (yajl_parse_complete (hndl)); #endif + yajl_free (hndl); return 0; } DEF_TEST(parse_keys) { struct { - char *str; - char *want; + const char *str; + const char *want; } cases[] = { {"WBThrottle.bytes_dirtied.description.bytes_wb.description.ios_dirtied.description.ios_wb.type", "WBThrottle.bytesDirtied.description.bytesWb.description.iosDirt"}, {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, @@ -168,13 +169,10 @@ DEF_TEST(parse_keys) for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) { - char got[DATA_MAX_NAME_LEN]; - - memset (got, 0, sizeof (got)); + char got[64]; CHECK_ZERO (parse_keys (got, sizeof (got), cases[i].str)); - - CHECK_ZERO (strcmp (got, cases[i].want)); + EXPECT_EQ_STR (cases[i].want, got); } return 0; diff --git a/src/cgroups.c b/src/cgroups.c index 6d419722..f7c7e0d6 100644 --- a/src/cgroups.c +++ b/src/cgroups.c @@ -22,9 +22,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_mount.h" #include "utils_ignorelist.h" @@ -206,18 +206,16 @@ static int cgroups_config (const char *key, const char *value) static int cgroups_read (void) { - cu_mount_t *mnt_list; - cu_mount_t *mnt_ptr; + cu_mount_t *mnt_list = NULL; _Bool cgroup_found = 0; - mnt_list = NULL; if (cu_mount_getlist (&mnt_list) == NULL) { ERROR ("cgroups plugin: cu_mount_getlist failed."); return (-1); } - for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) + for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) { /* Find the cgroup mountpoint which contains the cpuacct * controller. */ diff --git a/src/chrony.c b/src/chrony.c new file mode 100644 index 00000000..f6294e49 --- /dev/null +++ b/src/chrony.c @@ -0,0 +1,1123 @@ +/* chrony plugin for collectd (monitoring of chrony time server daemon) + ********************************************************************** + * Copyright (C) Claudius M Zingerli, ZSeng, 2015-2016 + * + * Internals roughly based on the ntpd plugin + * Some functions copied from chronyd/web (as marked) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * TODO: + * - More robust udp parsing (using offsets instead of structs?) + * -> Currently chrony parses its data the same way as we do (using structs) + * - Plausibility checks on values received + * -> Done at higher levels + */ + +#include "collectd.h" + +#include "common.h" /* auxiliary functions */ +#include "plugin.h" /* plugin_register_*, plugin_dispatch_values */ + +#if HAVE_NETDB_H +# include /* struct addrinfo */ +#endif +#if HAVE_ARPA_INET_H +# include /* ntohs/ntohl */ +#endif + + +#define CONFIG_KEY_HOST "Host" +#define CONFIG_KEY_PORT "Port" +#define CONFIG_KEY_TIMEOUT "Timeout" + +#define URAND_DEVICE_PATH "/dev/urandom" /* Used to initialize seq nr generator */ +#define RAND_DEVICE_PATH "/dev/random" /* Used to initialize seq nr generator (fall back) */ + +static const char *g_config_keys[] = { + CONFIG_KEY_HOST, + CONFIG_KEY_PORT, + CONFIG_KEY_TIMEOUT +}; + +static int g_config_keys_num = STATIC_ARRAY_SIZE(g_config_keys); +static int g_chrony_is_connected; +static int g_chrony_socket = -1; +static time_t g_chrony_timeout = -1; +static char *g_chrony_plugin_instance; +static char *g_chrony_host; +static char *g_chrony_port; +static uint32_t g_chrony_rand = 1; +static uint32_t g_chrony_seq_is_initialized; + +#define PLUGIN_NAME_SHORT "chrony" +#define PLUGIN_NAME PLUGIN_NAME_SHORT " plugin" +#define DAEMON_NAME PLUGIN_NAME_SHORT +#define CHRONY_DEFAULT_HOST "localhost" +#define CHRONY_DEFAULT_PORT "323" +#define CHRONY_DEFAULT_TIMEOUT 2 + +/* Return codes (collectd expects non-zero on errors) */ +#define CHRONY_RC_OK 0 +#define CHRONY_RC_FAIL 1 + +/* Chronyd command packet variables adapted from chrony/candm.h (GPL2) */ +#define PROTO_VERSION_NUMBER 6 +#define IPADDR_UNSPEC 0 +#define IPADDR_INET4 1 +#define IPADDR_INET6 2 +#define IPV6_STR_MAX_SIZE (8*4+7+1) + +typedef enum +{ + PKT_TYPE_CMD_REQUEST = 1, + PKT_TYPE_CMD_REPLY = 2 +} ePacketType; + +typedef enum +{ + REQ_N_SOURCES = 14, + REQ_SOURCE_DATA = 15, + REQ_TRACKING = 33, + REQ_SOURCE_STATS = 34 +} eDaemonRequests; + + +typedef enum +{ + RPY_NULL = 1, + RPY_N_SOURCES = 2, + RPY_SOURCE_DATA = 3, + RPY_MANUAL_TIMESTAMP = 4, + RPY_TRACKING = 5, + RPY_SOURCE_STATS = 6, + RPY_RTC = 7 +} eDaemonReplies; + + +#if defined(__GNUC__) || defined (__SUNPRO_C) || defined(lint) +# /* extension to enforce struct packing. */ +# define ATTRIB_PACKED __attribute__((packed)) +#else +# error Not defining packed attribute (unknown compiler) +# define ATTRIB_PACKED +#endif + +typedef struct ATTRIB_PACKED +{ + int32_t value; +} tFloat; + +typedef struct ATTRIB_PACKED +{ + uint32_t tv_sec_high; + uint32_t tv_sec_low; + uint32_t tv_nsec; +} tTimeval; + +typedef enum +{ + STT_SUCCESS = 0, + STT_FAILED = 1, + STT_UNAUTH = 2, + STT_INVALID = 3, + STT_NOSUCHSOURCE = 4, + STT_INVALIDTS = 5, + STT_NOTENABLED = 6, + STT_BADSUBNET = 7, + STT_ACCESSALLOWED = 8, + STT_ACCESSDENIED = 9, + STT_NOHOSTACCESS = 10, + STT_SOURCEALREADYKNOWN = 11, + STT_TOOMANYSOURCES = 12, + STT_NORTC = 13, + STT_BADRTCFILE = 14, + STT_INACTIVE = 15, + STT_BADSAMPLE = 16, + STT_INVALIDAF = 17, + STT_BADPKTVERSION = 18, + STT_BADPKTLENGTH = 19 +} eChrony_Status; + +/* Chrony client request packets */ +typedef struct ATTRIB_PACKED +{ + uint8_t f_dummy0[80]; /* Chrony expects 80bytes dummy data (Avoiding UDP Amplification) */ +} tChrony_Req_Tracking; + +typedef struct ATTRIB_PACKED +{ + uint32_t f_n_sources; +} tChrony_Req_N_Sources; + +typedef struct ATTRIB_PACKED +{ + int32_t f_index; + uint8_t f_dummy0[44]; +} tChrony_Req_Source_data; + +typedef struct ATTRIB_PACKED +{ + int32_t f_index; + uint8_t f_dummy0[56]; +} tChrony_Req_Source_stats; + +typedef struct ATTRIB_PACKED +{ + struct + { + uint8_t f_version; + uint8_t f_type; + uint8_t f_dummy0; + uint8_t f_dummy1; + uint16_t f_cmd; + uint16_t f_cmd_try; + uint32_t f_seq; + + uint32_t f_dummy2; + uint32_t f_dummy3; + } header; /* Packed: 20Bytes */ + union + { + tChrony_Req_N_Sources n_sources; + tChrony_Req_Source_data source_data; + tChrony_Req_Source_stats source_stats; + tChrony_Req_Tracking tracking; + } body; + uint8_t padding[4 + 16]; /* Padding to match minimal response size */ +} tChrony_Request; + +/* Chrony daemon response packets */ +typedef struct ATTRIB_PACKED +{ + uint32_t f_n_sources; +} tChrony_Resp_N_Sources; + +typedef struct ATTRIB_PACKED +{ + union + { + uint32_t ip4; + uint8_t ip6[16]; + } addr; + uint16_t f_family; +} tChrony_IPAddr; + +typedef struct ATTRIB_PACKED +{ + tChrony_IPAddr addr; + uint16_t dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on x86_64 */ + int16_t f_poll; /* 2^f_poll = Time between polls (s) */ + uint16_t f_stratum; /* Remote clock stratum */ + uint16_t f_state; /* 0 = RPY_SD_ST_SYNC, 1 = RPY_SD_ST_UNREACH, 2 = RPY_SD_ST_FALSETICKER */ + /* 3 = RPY_SD_ST_JITTERY, 4 = RPY_SD_ST_CANDIDATE, 5 = RPY_SD_ST_OUTLIER */ + uint16_t f_mode; /* 0 = RPY_SD_MD_CLIENT, 1 = RPY_SD_MD_PEER, 2 = RPY_SD_MD_REF */ + uint16_t f_flags; /* unused */ + uint16_t f_reachability; /* Bit mask of successfull tries to reach the source */ + + uint32_t f_since_sample; /* Time since last sample (s) */ + tFloat f_origin_latest_meas; /* */ + tFloat f_latest_meas; /* */ + tFloat f_latest_meas_err; /* */ +} tChrony_Resp_Source_data; + +typedef struct ATTRIB_PACKED +{ + uint32_t f_ref_id; + tChrony_IPAddr addr; + uint16_t dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on x86_64 */ + uint32_t f_n_samples; /* Number of measurements done */ + uint32_t f_n_runs; /* How many measurements to come */ + uint32_t f_span_seconds; /* For how long we're measuring */ + tFloat f_rtc_seconds_fast; /* ??? */ + tFloat f_rtc_gain_rate_ppm; /* Estimated relative frequency error */ + tFloat f_skew_ppm; /* Clock skew (ppm) (worst case freq est error (skew: peak2peak)) */ + tFloat f_est_offset; /* Estimated offset of source */ + tFloat f_est_offset_err; /* Error of estimation */ +} tChrony_Resp_Source_stats; + +typedef struct ATTRIB_PACKED +{ + uint32_t f_ref_id; + tChrony_IPAddr addr; + uint16_t dummy; /* FIXME: Strange dummy space. Needed on gcc 4.8.3/clang 3.4.1 on x86_64 */ + uint16_t f_stratum; + uint16_t f_leap_status; + tTimeval f_ref_time; + tFloat f_current_correction; + tFloat f_last_offset; + tFloat f_rms_offset; + tFloat f_freq_ppm; + tFloat f_resid_freq_ppm; + tFloat f_skew_ppm; + tFloat f_root_delay; + tFloat f_root_dispersion; + tFloat f_last_update_interval; +} tChrony_Resp_Tracking; + +typedef struct ATTRIB_PACKED +{ + struct + { + uint8_t f_version; + uint8_t f_type; + uint8_t f_dummy0; + uint8_t f_dummy1; + uint16_t f_cmd; + uint16_t f_reply; + uint16_t f_status; + uint16_t f_dummy2; + uint16_t f_dummy3; + uint16_t f_dummy4; + uint32_t f_seq; + uint32_t f_dummy5; + uint32_t f_dummy6; + } header; /* Packed: 28 Bytes */ + + union + { + tChrony_Resp_N_Sources n_sources; + tChrony_Resp_Source_data source_data; + tChrony_Resp_Source_stats source_stats; + tChrony_Resp_Tracking tracking; + } body; + + uint8_t padding[1024]; +} tChrony_Response; + + +/*****************************************************************************/ +/* Internal functions */ +/*****************************************************************************/ + +/* connect_client code adapted from: http://long.ccaba.upc.edu/long/045Guidelines/eva/ipv6.html#daytimeClient6 */ +/* License granted by Eva M Castro via e-mail on 2016-02-18 under the terms of GPLv3 */ +static int +connect_client(const char *p_hostname, + const char *p_service, int p_family, int p_socktype) +{ + struct addrinfo *res, *ressave; + int n, sockfd; + + struct addrinfo ai_hints = { + .ai_family = p_family, + .ai_socktype = p_socktype + }; + + n = getaddrinfo(p_hostname, p_service, &ai_hints, &res); + + if (n < 0) + { + ERROR(PLUGIN_NAME ": getaddrinfo error:: [%s]", gai_strerror(n)); + return -1; + } + + ressave = res; + + sockfd = -1; + while (res) + { + sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + + if (!(sockfd < 0)) + { + if (connect(sockfd, res->ai_addr, res->ai_addrlen) == 0) + { + /* Success */ + break; + } + + close(sockfd); + sockfd = -1; + } + res = res->ai_next; + } + + freeaddrinfo(ressave); + return sockfd; +} + + +/* niptoha code originally from: git://git.tuxfamily.org/gitroot/chrony/chrony.git:util.c */ +/* Original code licensed as GPLv2, by Richard P. Purnow, Miroslav Lichvar */ +/* Original name: char * UTI_IPToString(IPAddr *addr)*/ +static char * +niptoha(const tChrony_IPAddr * addr, char *p_buf, size_t p_buf_size) +{ + int rc = 1; + unsigned long a, b, c, d, ip; + + switch (ntohs(addr->f_family)) + { + case IPADDR_UNSPEC: + rc = snprintf(p_buf, p_buf_size, "[UNSPEC]"); + break; + case IPADDR_INET4: + ip = ntohl(addr->addr.ip4); + a = (ip >> 24) & 0xff; + b = (ip >> 16) & 0xff; + c = (ip >> 8) & 0xff; + d = (ip >> 0) & 0xff; + rc = snprintf(p_buf, p_buf_size, "%ld.%ld.%ld.%ld", a, b, c, d); + break; + case IPADDR_INET6: + { + const char *rp = inet_ntop(AF_INET6, addr->addr.ip6, p_buf, p_buf_size); + if (rp == NULL) + { + ERROR(PLUGIN_NAME ": Error converting ipv6 address to string. Errno = %d", errno); + rc = snprintf(p_buf, p_buf_size, "[UNKNOWN]"); + } + break; + } + default: + rc = snprintf(p_buf, p_buf_size, "[UNKNOWN]"); + } + assert(rc > 0); + return p_buf; +} + + +static int +chrony_set_timeout(void) +{ + /* Set the socket's timeout to g_chrony_timeout; a value of 0 signals infinite timeout */ + /* Returns 0 on success, !0 on error (check errno) */ + + struct timeval tv; + tv.tv_sec = g_chrony_timeout; + tv.tv_usec = 0; + + assert(g_chrony_socket >= 0); + if (setsockopt(g_chrony_socket, SOL_SOCKET, + SO_RCVTIMEO, (char *) &tv, sizeof(struct timeval)) < 0) + { + return CHRONY_RC_FAIL; + } + return CHRONY_RC_OK; +} + + +static int +chrony_connect(void) +{ + /* Connects to the chrony daemon */ + /* Returns 0 on success, !0 on error (check errno) */ + int socket; + + if (g_chrony_host == NULL) + { + g_chrony_host = strdup(CHRONY_DEFAULT_HOST); + if (g_chrony_host == NULL) + { + ERROR(PLUGIN_NAME ": Error duplicating chrony host name"); + return CHRONY_RC_FAIL; + } + } + if (g_chrony_port == NULL) + { + g_chrony_port = strdup(CHRONY_DEFAULT_PORT); + if (g_chrony_port == NULL) + { + ERROR(PLUGIN_NAME ": Error duplicating chrony port string"); + return CHRONY_RC_FAIL; + } + } + if (g_chrony_timeout < 0) + { + g_chrony_timeout = CHRONY_DEFAULT_TIMEOUT; + assert(g_chrony_timeout >= 0); + } + + DEBUG(PLUGIN_NAME ": Connecting to %s:%s", g_chrony_host, g_chrony_port); + socket = connect_client(g_chrony_host, g_chrony_port, AF_UNSPEC, SOCK_DGRAM); + if (socket < 0) + { + ERROR(PLUGIN_NAME ": Error connecting to daemon. Errno = %d", errno); + return CHRONY_RC_FAIL; + } + DEBUG(PLUGIN_NAME ": Connected"); + g_chrony_socket = socket; + + if (chrony_set_timeout()) + { + ERROR(PLUGIN_NAME ": Error setting timeout to %llds. Errno = %d", + (long long)g_chrony_timeout, errno); + return CHRONY_RC_FAIL; + } + return CHRONY_RC_OK; +} + + +static int +chrony_send_request(const tChrony_Request * p_req, size_t p_req_size) +{ + if (send(g_chrony_socket, p_req, p_req_size, 0) < 0) + { + ERROR(PLUGIN_NAME ": Error sending packet. Errno = %d", errno); + return CHRONY_RC_FAIL; + } + return CHRONY_RC_OK; +} + + +static int +chrony_recv_response(tChrony_Response * p_resp, size_t p_resp_max_size, + size_t * p_resp_size) +{ + ssize_t rc = recv(g_chrony_socket, p_resp, p_resp_max_size, 0); + if (rc <= 0) + { + ERROR(PLUGIN_NAME ": Error receiving packet: %s (%d)", strerror(errno), + errno); + return CHRONY_RC_FAIL; + } + else + { + *p_resp_size = rc; + return CHRONY_RC_OK; + } +} + + +static int +chrony_query(const int p_command, tChrony_Request * p_req, + tChrony_Response * p_resp, size_t * p_resp_size) +{ + /* Check connection. We simply perform one try as collectd already handles retries */ + assert(p_req); + assert(p_resp); + assert(p_resp_size); + + if (g_chrony_is_connected == 0) + { + if (chrony_connect() == CHRONY_RC_OK) + { + g_chrony_is_connected = 1; + } + else + { + ERROR(PLUGIN_NAME ": Unable to connect. Errno = %d", errno); + return CHRONY_RC_FAIL; + } + } + + do + { + int valid_command = 0; + size_t req_size = sizeof(p_req->header) + sizeof(p_req->padding); + size_t resp_size = sizeof(p_resp->header); + uint16_t resp_code = RPY_NULL; + switch (p_command) + { + case REQ_TRACKING: + req_size += sizeof(p_req->body.tracking); + resp_size += sizeof(p_resp->body.tracking); + resp_code = RPY_TRACKING; + valid_command = 1; + break; + case REQ_N_SOURCES: + req_size += sizeof(p_req->body.n_sources); + resp_size += sizeof(p_resp->body.n_sources); + resp_code = RPY_N_SOURCES; + valid_command = 1; + break; + case REQ_SOURCE_DATA: + req_size += sizeof(p_req->body.source_data); + resp_size += sizeof(p_resp->body.source_data); + resp_code = RPY_SOURCE_DATA; + valid_command = 1; + break; + case REQ_SOURCE_STATS: + req_size += sizeof(p_req->body.source_stats); + resp_size += sizeof(p_resp->body.source_stats); + resp_code = RPY_SOURCE_STATS; + valid_command = 1; + break; + default: + ERROR(PLUGIN_NAME ": Unknown request command (Was: %d)", p_command); + break; + } + + if (valid_command == 0) + break; + + uint32_t seq_nr = rand_r(&g_chrony_rand); + p_req->header.f_cmd = htons(p_command); + p_req->header.f_cmd_try = 0; + p_req->header.f_seq = seq_nr; + + DEBUG(PLUGIN_NAME ": Sending request (.cmd = %d, .seq = %d)", p_command, + seq_nr); + if (chrony_send_request(p_req, req_size) != 0) + break; + + DEBUG(PLUGIN_NAME ": Waiting for response"); + if (chrony_recv_response(p_resp, resp_size, p_resp_size) != 0) + break; + + DEBUG(PLUGIN_NAME + ": Received response: .version = %u, .type = %u, .cmd = %u, .reply = %u, .status = %u, .seq = %u", + p_resp->header.f_version, p_resp->header.f_type, + ntohs(p_resp->header.f_cmd), ntohs(p_resp->header.f_reply), + ntohs(p_resp->header.f_status), p_resp->header.f_seq); + + if (p_resp->header.f_version != p_req->header.f_version) + { + ERROR(PLUGIN_NAME ": Wrong protocol version (Was: %d, expected: %d)", + p_resp->header.f_version, p_req->header.f_version); + return CHRONY_RC_FAIL; + } + if (p_resp->header.f_type != PKT_TYPE_CMD_REPLY) + { + ERROR(PLUGIN_NAME ": Wrong packet type (Was: %d, expected: %d)", + p_resp->header.f_type, PKT_TYPE_CMD_REPLY); + return CHRONY_RC_FAIL; + } + if (p_resp->header.f_seq != seq_nr) + { + /* FIXME: Implement sequence number handling */ + ERROR(PLUGIN_NAME + ": Unexpected sequence number (Was: %d, expected: %d)", + p_resp->header.f_seq, p_req->header.f_seq); + return CHRONY_RC_FAIL; + } + if (p_resp->header.f_cmd != p_req->header.f_cmd) + { + ERROR(PLUGIN_NAME ": Wrong reply command (Was: %d, expected: %d)", + p_resp->header.f_cmd, p_req->header.f_cmd); + return CHRONY_RC_FAIL; + } + + if (ntohs(p_resp->header.f_reply) != resp_code) + { + ERROR(PLUGIN_NAME ": Wrong reply code (Was: %d, expected: %d)", + ntohs(p_resp->header.f_reply), resp_code); + return CHRONY_RC_FAIL; + } + + switch (p_resp->header.f_status) + { + case STT_SUCCESS: + DEBUG(PLUGIN_NAME ": Reply packet status STT_SUCCESS"); + break; + default: + ERROR(PLUGIN_NAME + ": Reply packet contains error status: %d (expected: %d)", + p_resp->header.f_status, STT_SUCCESS); + return CHRONY_RC_FAIL; + } + + /* Good result */ + return CHRONY_RC_OK; + } + while (0); + + /* Some error occured */ + return CHRONY_RC_FAIL; +} + + +static void +chrony_init_req(tChrony_Request * p_req) +{ + memset(p_req, 0, sizeof(*p_req)); + p_req->header.f_version = PROTO_VERSION_NUMBER; + p_req->header.f_type = PKT_TYPE_CMD_REQUEST; + p_req->header.f_dummy0 = 0; + p_req->header.f_dummy1 = 0; + p_req->header.f_dummy2 = 0; + p_req->header.f_dummy3 = 0; +} + + +/* ntohf code originally from: git://git.tuxfamily.org/gitroot/chrony/chrony.git:util.c */ +/* Original code licensed as GPLv2, by Richard P. Purnow, Miroslav Lichvar */ +/* Original name: double UTI_tFloatNetworkToHost(tFloat f) */ +static double +ntohf(tFloat p_float) +{ + /* Convert tFloat in Network-bit-order to double in host-bit-order */ + +#define FLOAT_EXP_BITS 7 +#define FLOAT_EXP_MIN (-(1 << (FLOAT_EXP_BITS - 1))) +#define FLOAT_EXP_MAX (-FLOAT_EXP_MIN - 1) +#define FLOAT_COEF_BITS ((int)sizeof (int32_t) * 8 - FLOAT_EXP_BITS) +#define FLOAT_COEF_MIN (-(1 << (FLOAT_COEF_BITS - 1))) +#define FLOAT_COEF_MAX (-FLOAT_COEF_MIN - 1) + + int32_t exp, coef; + uint32_t uval; + + uval = ntohl(p_float.value); + exp = (uval >> FLOAT_COEF_BITS) - FLOAT_COEF_BITS; + if (exp >= 1 << (FLOAT_EXP_BITS - 1)) + exp -= 1 << FLOAT_EXP_BITS; + + /* coef = (x << FLOAT_EXP_BITS) >> FLOAT_EXP_BITS; */ + coef = uval % (1U << FLOAT_COEF_BITS); + if (coef >= 1 << (FLOAT_COEF_BITS - 1)) + coef -= 1 << FLOAT_COEF_BITS; + + return coef * pow(2.0, exp); +} + + +static void +chrony_push_data(const char *p_type, const char *p_type_inst, double p_value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = p_value; /* TODO: Check type??? (counter, gauge, derive, absolute) */ + + vl.values = values; + vl.values_len = 1; + + /* XXX: Shall g_chrony_host/g_chrony_port be reflected in the plugin's output? */ + /* hostname_g is set in daemon/collectd.c (from config, via gethostname or by resolving localhost) */ + /* defined as: char hostname_g[DATA_MAX_NAME_LEN]; (never NULL) */ + sstrncpy(vl.host, hostname_g, sizeof(vl.host)); + sstrncpy(vl.plugin, PLUGIN_NAME_SHORT, sizeof(vl.plugin)); + if (g_chrony_plugin_instance != NULL) + { + sstrncpy(vl.plugin_instance, g_chrony_plugin_instance, + sizeof(vl.plugin_instance)); + } + if (p_type != NULL) + sstrncpy(vl.type, p_type, sizeof(vl.type)); + + if (p_type_inst != NULL) + sstrncpy(vl.type_instance, p_type_inst, sizeof(vl.type_instance)); + + plugin_dispatch_values(&vl); +} + + +static void +chrony_push_data_valid(const char *p_type, const char *p_type_inst, const int p_is_valid, + double p_value) +{ + /* Push real value if p_is_valid is true, push NAN if p_is_valid is not true (idea from ntp plugin) */ + if (p_is_valid == 0) + p_value = NAN; + + chrony_push_data(p_type, p_type_inst, p_value); +} + + +static int +chrony_init_seq(void) +{ + /* Initialize the sequence number generator from /dev/urandom */ + /* Fallbacks: /dev/random and time(NULL) */ + + int fh; + + /* Try urandom */ + fh = open(URAND_DEVICE_PATH, O_RDONLY); + if (fh >= 0) + { + ssize_t rc = read(fh, &g_chrony_rand, sizeof(g_chrony_rand)); + if (rc != sizeof(g_chrony_rand)) + { + ERROR(PLUGIN_NAME ": Reading from random source \'%s\'failed: %s (%d)", + URAND_DEVICE_PATH, strerror(errno), errno); + close(fh); + return CHRONY_RC_FAIL; + } + close(fh); + DEBUG(PLUGIN_NAME ": Seeding RNG from " URAND_DEVICE_PATH); + } + else + { + if (errno == ENOENT) + { + /* URAND_DEVICE_PATH device not found. Try RAND_DEVICE_PATH as fall-back */ + fh = open(RAND_DEVICE_PATH, O_RDONLY); + if (fh >= 0) + { + ssize_t rc = read(fh, &g_chrony_rand, sizeof(g_chrony_rand)); + if (rc != sizeof(g_chrony_rand)) + { + ERROR(PLUGIN_NAME + ": Reading from random source \'%s\'failed: %s (%d)", + RAND_DEVICE_PATH, strerror(errno), errno); + close(fh); + return CHRONY_RC_FAIL; + } + close(fh); + DEBUG(PLUGIN_NAME ": Seeding RNG from " RAND_DEVICE_PATH); + } + else + { + /* Error opening RAND_DEVICE_PATH. Try time(NULL) as fall-back */ + DEBUG(PLUGIN_NAME ": Seeding RNG from time(NULL)"); + g_chrony_rand = time(NULL) ^ getpid(); + } + } + else + { + ERROR(PLUGIN_NAME ": Opening random source \'%s\' failed: %s (%d)", + URAND_DEVICE_PATH, strerror(errno), errno); + return CHRONY_RC_FAIL; + } + } + + return CHRONY_RC_OK; +} + + +/*****************************************************************************/ +/* Exported functions */ +/*****************************************************************************/ +static int +chrony_config(const char *p_key, const char *p_value) +{ + assert(p_key); + assert(p_value); + + /* Parse config variables */ + if (strcasecmp(p_key, CONFIG_KEY_HOST) == 0) + { + if (g_chrony_host != NULL) + free(g_chrony_host); + + if ((g_chrony_host = strdup(p_value)) == NULL) + { + ERROR(PLUGIN_NAME ": Error duplicating host name"); + return CHRONY_RC_FAIL; + } + } + else + { + if (strcasecmp(p_key, CONFIG_KEY_PORT) == 0) + { + if (g_chrony_port != NULL) + free(g_chrony_port); + + if ((g_chrony_port = strdup(p_value)) == NULL) + { + ERROR(PLUGIN_NAME ": Error duplicating port name"); + return CHRONY_RC_FAIL; + } + } + else + { + if (strcasecmp(p_key, CONFIG_KEY_TIMEOUT) == 0) + { + time_t tosec = strtol(p_value, NULL, 0); + g_chrony_timeout = tosec; + } + else + { + WARNING(PLUGIN_NAME ": Unknown configuration variable: %s %s", p_key, p_value); + return CHRONY_RC_FAIL; + } + } + } + /* XXX: We could set g_chrony_plugin_instance here to "g_chrony_host-g_chrony_port", but as multiple instances aren't yet supported, we skip this for now */ + + return CHRONY_RC_OK; +} + + +static int +chrony_request_daemon_stats(void) +{ + /* Perform Tracking request */ + int rc; + size_t chrony_resp_size; + tChrony_Request chrony_req; + tChrony_Response chrony_resp; + + chrony_init_req(&chrony_req); + rc = + chrony_query(REQ_TRACKING, &chrony_req, &chrony_resp, &chrony_resp_size); + if (rc != 0) + { + ERROR(PLUGIN_NAME ": chrony_query (REQ_TRACKING) failed with status %i", + rc); + return rc; + } +#if COLLECT_DEBUG + { + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; + niptoha(&chrony_resp.body.tracking.addr, src_addr, sizeof(src_addr)); + DEBUG(PLUGIN_NAME ": Daemon stat: .addr = %s, .ref_id= %u, .stratum = %u, .leap_status = %u, .ref_time = %u:%u:%u, .current_correction = %f, .last_offset = %f, .rms_offset = %f, .freq_ppm = %f, .skew_ppm = %f, .root_delay = %f, .root_dispersion = %f, .last_update_interval = %f", src_addr, ntohs(chrony_resp.body.tracking.f_ref_id), + ntohs(chrony_resp.body.tracking.f_stratum), + ntohs(chrony_resp.body.tracking.f_leap_status), + ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_high), + ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_low), + ntohl(chrony_resp.body.tracking.f_ref_time.tv_nsec), + ntohf(chrony_resp.body.tracking.f_current_correction), + ntohf(chrony_resp.body.tracking.f_last_offset), + ntohf(chrony_resp.body.tracking.f_rms_offset), + ntohf(chrony_resp.body.tracking.f_freq_ppm), + ntohf(chrony_resp.body.tracking.f_skew_ppm), + ntohf(chrony_resp.body.tracking.f_root_delay), + ntohf(chrony_resp.body.tracking.f_root_dispersion), + ntohf(chrony_resp.body.tracking.f_last_update_interval)); + } +#endif + + double time_ref = ntohl(chrony_resp.body.tracking.f_ref_time.tv_nsec); + time_ref /= 1000000000.0; + time_ref += ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_low); + if (chrony_resp.body.tracking.f_ref_time.tv_sec_high) + { + double secs_high = + ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_high); + secs_high *= 4294967296.0; + time_ref += secs_high; + } + + /* Forward results to collectd-daemon */ + /* Type_instance is always 'chrony' to tag daemon-wide data */ + /* Type Type_instan Value */ + chrony_push_data("clock_stratum", DAEMON_NAME, ntohs(chrony_resp.body.tracking.f_stratum)); + chrony_push_data("time_ref", DAEMON_NAME, time_ref); /* unit: s */ + chrony_push_data("time_offset_ntp", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_current_correction)); /* Offset between system time and NTP, unit: s */ + chrony_push_data("time_offset", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_last_offset)); /* Estimated Offset of the NTP time, unit: s */ + chrony_push_data("time_offset_rms", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_rms_offset)); /* averaged value of the above, unit: s */ + chrony_push_data("frequency_error", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_freq_ppm)); /* Frequency error of the local osc, unit: ppm */ + chrony_push_data("clock_skew_ppm", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_skew_ppm)); + chrony_push_data("root_delay", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_root_delay)); /* Network latency between local daemon and the current source */ + chrony_push_data("root_dispersion", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_root_dispersion)); + chrony_push_data("clock_last_update", DAEMON_NAME, ntohf(chrony_resp.body.tracking.f_last_update_interval)); + + return CHRONY_RC_OK; +} + + +static int +chrony_request_sources_count(unsigned int *p_count) +{ + /* Requests the number of time sources from the chrony daemon */ + int rc; + size_t chrony_resp_size; + tChrony_Request chrony_req; + tChrony_Response chrony_resp; + + DEBUG(PLUGIN_NAME ": Requesting data"); + chrony_init_req(&chrony_req); + rc = + chrony_query(REQ_N_SOURCES, &chrony_req, &chrony_resp, &chrony_resp_size); + if (rc != 0) + { + ERROR(PLUGIN_NAME ": chrony_query (REQ_N_SOURCES) failed with status %i", + rc); + return rc; + } + + *p_count = ntohl(chrony_resp.body.n_sources.f_n_sources); + DEBUG(PLUGIN_NAME ": Getting data of %d clock sources", *p_count); + + return CHRONY_RC_OK; +} + + +static int +chrony_request_source_data(int p_src_idx, int *p_is_reachable) +{ + /* Perform Source data request for source #p_src_idx */ + int rc; + size_t chrony_resp_size; + tChrony_Request chrony_req; + tChrony_Response chrony_resp; + + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; + + chrony_init_req(&chrony_req); + chrony_req.body.source_data.f_index = htonl(p_src_idx); + rc = + chrony_query(REQ_SOURCE_DATA, &chrony_req, &chrony_resp, + &chrony_resp_size); + if (rc != 0) + { + ERROR(PLUGIN_NAME + ": chrony_query (REQ_SOURCE_DATA) failed with status %i", rc); + return rc; + } + + niptoha(&chrony_resp.body.source_data.addr, src_addr, sizeof(src_addr)); + DEBUG(PLUGIN_NAME + ": Source[%d] data: .addr = %s, .poll = %u, .stratum = %u, .state = %u, .mode = %u, .flags = %u, .reach = %u, .latest_meas_ago = %u, .orig_latest_meas = %f, .latest_meas = %f, .latest_meas_err = %f", + p_src_idx, src_addr, ntohs(chrony_resp.body.source_data.f_poll), + ntohs(chrony_resp.body.source_data.f_stratum), + ntohs(chrony_resp.body.source_data.f_state), + ntohs(chrony_resp.body.source_data.f_mode), + ntohs(chrony_resp.body.source_data.f_flags), + ntohs(chrony_resp.body.source_data.f_reachability), + ntohl(chrony_resp.body.source_data.f_since_sample), + ntohf(chrony_resp.body.source_data.f_origin_latest_meas), + ntohf(chrony_resp.body.source_data.f_latest_meas), + ntohf(chrony_resp.body.source_data.f_latest_meas_err)); + + /* Push NaN if source is currently not reachable */ + int is_reachable = + ntohs(chrony_resp.body.source_data.f_reachability) & 0x01; + *p_is_reachable = is_reachable; + + /* Forward results to collectd-daemon */ + chrony_push_data_valid("clock_stratum", src_addr, is_reachable, + ntohs(chrony_resp.body.source_data.f_stratum)); + chrony_push_data_valid("clock_state", src_addr, is_reachable, + ntohs(chrony_resp.body.source_data.f_state)); + chrony_push_data_valid("clock_mode", src_addr, is_reachable, + ntohs(chrony_resp.body.source_data.f_mode)); + chrony_push_data_valid("clock_reachability", src_addr, is_reachable, + ntohs(chrony_resp.body.source_data.f_reachability)); + chrony_push_data_valid("clock_last_meas", src_addr, is_reachable, + ntohs(chrony_resp.body.source_data.f_since_sample)); + + return CHRONY_RC_OK; +} + + +static int +chrony_request_source_stats(int p_src_idx, const int *p_is_reachable) +{ + /* Perform Source stats request for source #p_src_idx */ + int rc; + size_t chrony_resp_size; + tChrony_Request chrony_req; + tChrony_Response chrony_resp; + double skew_ppm, frequency_error, time_offset; + + char src_addr[IPV6_STR_MAX_SIZE] = { 0 }; + + if (*p_is_reachable == 0) + { + skew_ppm = 0; + frequency_error = 0; + time_offset = 0; + } + else + { + chrony_init_req(&chrony_req); + chrony_req.body.source_stats.f_index = htonl(p_src_idx); + rc = + chrony_query(REQ_SOURCE_STATS, &chrony_req, &chrony_resp, + &chrony_resp_size); + if (rc != 0) + { + ERROR(PLUGIN_NAME + ": chrony_query (REQ_SOURCE_STATS) failed with status %i", rc); + return rc; + } + + skew_ppm = ntohf(chrony_resp.body.source_stats.f_skew_ppm); + frequency_error = + ntohf(chrony_resp.body.source_stats.f_rtc_gain_rate_ppm); + time_offset = ntohf(chrony_resp.body.source_stats.f_est_offset); + + niptoha(&chrony_resp.body.source_stats.addr, src_addr, sizeof(src_addr)); + DEBUG(PLUGIN_NAME + ": Source[%d] stat: .addr = %s, .ref_id= %u, .n_samples = %u, " + ".n_runs = %u, .span_seconds = %u, .rtc_seconds_fast = %f, " + ".rtc_gain_rate_ppm = %f, .skew_ppm= %f, .est_offset = %f, .est_offset_err = %f", + p_src_idx, src_addr, + ntohl(chrony_resp.body.source_stats.f_ref_id), + ntohl(chrony_resp.body.source_stats.f_n_samples), + ntohl(chrony_resp.body.source_stats.f_n_runs), + ntohl(chrony_resp.body.source_stats.f_span_seconds), + ntohf(chrony_resp.body.source_stats.f_rtc_seconds_fast), + frequency_error, skew_ppm, time_offset, + ntohf(chrony_resp.body.source_stats.f_est_offset_err)); + + } /* if (*is_reachable) */ + + /* Forward results to collectd-daemon */ + chrony_push_data_valid("clock_skew_ppm", src_addr, *p_is_reachable, skew_ppm); + chrony_push_data_valid("frequency_error", src_addr, *p_is_reachable, frequency_error); /* unit: ppm */ + chrony_push_data_valid("time_offset", src_addr, *p_is_reachable, time_offset); /* unit: s */ + + return CHRONY_RC_OK; +} + + +static int +chrony_read(void) +{ + /* collectd read callback: Perform data acquisition */ + int rc; + unsigned int n_sources; + + if (g_chrony_seq_is_initialized == 0) + { + /* Seed RNG for sequence number generation */ + rc = chrony_init_seq(); + if (rc != CHRONY_RC_OK) + return rc; + + g_chrony_seq_is_initialized = 1; + } + + /* Get daemon stats */ + rc = chrony_request_daemon_stats(); + if (rc != CHRONY_RC_OK) + return rc; + + /* Get number of time sources, then check every source for status */ + rc = chrony_request_sources_count(&n_sources); + if (rc != CHRONY_RC_OK) + return rc; + + for (unsigned int now_src = 0; now_src < n_sources; ++now_src) + { + int is_reachable; + rc = chrony_request_source_data(now_src, &is_reachable); + if (rc != CHRONY_RC_OK) + return rc; + + rc = chrony_request_source_stats(now_src, &is_reachable); + if (rc != CHRONY_RC_OK) + return rc; + + } + return CHRONY_RC_OK; +} + + +static int +chrony_shutdown(void) +{ + /* Collectd shutdown callback: Free mem */ + if (g_chrony_is_connected != 0) + { + close(g_chrony_socket); + g_chrony_is_connected = 0; + } + if (g_chrony_host != NULL) + sfree(g_chrony_host); + + if (g_chrony_port != NULL) + sfree(g_chrony_port); + + if (g_chrony_plugin_instance != NULL) + sfree(g_chrony_plugin_instance); + + return CHRONY_RC_OK; +} + + +void +module_register(void) +{ + plugin_register_config(PLUGIN_NAME_SHORT, chrony_config, g_config_keys, + g_config_keys_num); + plugin_register_read(PLUGIN_NAME_SHORT, chrony_read); + plugin_register_shutdown(PLUGIN_NAME_SHORT, chrony_shutdown); +} diff --git a/src/collectd-java.pod b/src/collectd-java.pod index aade08a4..afa7e48a 100644 --- a/src/collectd-java.pod +++ b/src/collectd-java.pod @@ -620,6 +620,11 @@ sets the type instance instead. I<(optional)> Works like the option of the same name directly beneath the I block, but sets the type instance instead. I<(optional)> +=item B I + +When set, overrides the default setting for the I field +(C). + =item B B|B Set this to true if the returned attribute is a I. If set to diff --git a/src/collectd-lua.pod b/src/collectd-lua.pod new file mode 100644 index 00000000..7a256550 --- /dev/null +++ b/src/collectd-lua.pod @@ -0,0 +1,163 @@ +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +=encoding UTF-8 + +=head1 NAME + +collectd-lua - Documentation of collectd's C + +=head1 SYNOPSIS + + LoadPlugin lua + # ... + + BasePath "/path/to/your/lua/scripts" + Script "script1.lua" + Script "script2.lua" + + +=head1 DESCRIPTION + +The C embeds a Lua interpreter into collectd and provides an +interface to collectd's plugin system. This makes it possible to write plugins +for collectd in Lua. This is a lot more efficient than executing a +Lua script every time you want to read a value with the C (see +L) and provides a lot more functionality, too. + +The minimum required Lua version is I<5.1>. + +=head1 CONFIGURATION + +=over 4 + +=item B I + +Loads the Lua plugin. + +=item B I + +The directory the C looks in to find script B