Merge pull request #1885 from rubenk/lua-plugin
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sun, 14 Aug 2016 15:14:25 +0000 (17:14 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Aug 2016 15:14:25 +0000 (17:14 +0200)
Add a Lua plugin for Collectd

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

diff --combined README
--- 1/README
--- 2/README
+++ b/README
@@@ -168,6 -168,12 +168,12 @@@ Feature
        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).
        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.
@@@ -729,6 -739,10 +739,10 @@@ Prerequisite
      Used by the `openldap' plugin.
      <http://www.openldap.org/>
  
+   * liblua (optional)
+     Used by the `lua' plugin. Currently, Lua 5.1 and later are supported.
+     <https://www.lua.org/>
    * liblvm2 (optional)
      Used by the `lvm' plugin.
      <ftp://sources.redhat.com/pub/lvm2/>
      <http://code.google.com/p/protobuf-c/>
  
    * 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.
      <http://www.python.org/>
  
diff --combined configure.ac
@@@ -683,26 -683,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)
  AM_CONDITIONAL(BUILD_WITH_LIBLDAP, test "x$with_libldap" = "xyes")
  # }}}
  
+ # --with-liblua {{{
+ with_liblua_cppflags=""
+ with_liblua_ldflags=""
+ with_liblua_libs=""
+ with_liblua="yes"
+ AC_ARG_VAR([LIBLUA_PKG_CONFIG_NAME], [Name of liblua used by pkg-config])
+ if test "x$LIBLUA_PKG_CONFIG_NAME" = "x"
+ then
+        LIBLUA_PKG_CONFIG_NAME="lua"
+ fi
+ if test "x$with_liblua" = "xyes"
+ then
+       $PKG_CONFIG --exists $LIBLUA_PKG_CONFIG_NAME 2>/dev/null
+       lua_config_status=$?
+       if test 0 -ne $lua_config_status
+       then
+               with_liblua="no"
+       fi
+ fi
+ if test "x$with_liblua" = "xyes"
+ then
+       with_liblua_cppflags=`$PKG_CONFIG --cflags-only-I $LIBLUA_PKG_CONFIG_NAME` || with_liblua="no"
+       with_liblua_ldflags=`$PKG_CONFIG --libs-only-L $LIBLUA_PKG_CONFIG_NAME` || with_liblua="no"
+       with_liblua_libs=`$PKG_CONFIG --libs-only-l $LIBLUA_PKG_CONFIG_NAME` || with_liblua="no"
+ fi
+ if test "x$with_liblua" = "xyes"
+ then
+       SAVE_CPPFLAGS="$CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $with_liblua_cppflags"
+       AC_CHECK_HEADERS(lua.h lauxlib.h lualib.h, [], [with_liblua="no (header not found)"], [])
+       CPPFLAGS="$SAVE_CPPFLAGS"
+ fi
+ if test "x$with_liblua" = "xyes"
+ then
+       SAVE_LDFLAGS="$LDFLAGS"
+       SAVE_LIBS="$LIBS"
+       LDFLAGS="$SAVE_LDFLAGS $with_liblua_ldflags"
+       LIBS="$LIBS $with_liblua_libs"
+       AC_CHECK_FUNC(lua_settop, [with_liblua="yes"], [with_liblua="no (symbol 'lua_settop' not found)"])
+       LDFLAGS="$SAVE_LDFLAGS"
+       LIBS="$SAVE_LIBS"
+ fi
+ if test "x$with_liblua" = "xyes"
+ then
+     BUILD_WITH_LIBLUA_CPPFLAGS="$with_liblua_cppflags"
+     BUILD_WITH_LIBLUA_LDFLAGS="$with_liblua_ldflags"
+     BUILD_WITH_LIBLUA_LIBS="$with_liblua_libs"
+ fi
+ AC_SUBST(BUILD_WITH_LIBLUA_CPPFLAGS)
+ AC_SUBST(BUILD_WITH_LIBLUA_LDFLAGS)
+ AC_SUBST(BUILD_WITH_LIBLUA_LIBS)
+ # }}}
  # --with-liblvm2app {{{
  with_liblvm2app_cppflags=""
  with_liblvm2app_ldflags=""
@@@ -3348,6 -3393,9 +3409,6 @@@ AM_CONDITIONAL(BUILD_WITH_LIBNETAPP, te
  # }}}
  
  # --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"
        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 {{{
@@@ -3425,7 -3488,7 +3486,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"
@@@ -6094,6 -6157,7 +6155,7 @@@ AC_PLUGIN([load],                [$plug
  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])
@@@ -6312,18 -6376,6 +6374,18 @@@ AC_ARG_WITH(perl-bindings, [AS_HELP_STR
                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"
@@@ -6423,6 -6475,7 +6485,7 @@@ AC_MSG_RESULT([    libjvm  . . . . . . 
  AC_MSG_RESULT([    libkstat  . . . . . . $with_kstat])
  AC_MSG_RESULT([    libkvm  . . . . . . . $with_libkvm])
  AC_MSG_RESULT([    libldap . . . . . . . $with_libldap])
+ AC_MSG_RESULT([    liblua  . . . . . . . $with_liblua])
  AC_MSG_RESULT([    liblvm2app  . . . . . $with_liblvm2app])
  AC_MSG_RESULT([    libmemcached  . . . . $with_libmemcached])
  AC_MSG_RESULT([    libmnl  . . . . . . . $with_libmnl])
@@@ -6522,6 -6575,7 +6585,7 @@@ AC_MSG_RESULT([    load  . . . . . . . 
  AC_MSG_RESULT([    logfile . . . . . . . $enable_logfile])
  AC_MSG_RESULT([    log_logstash  . . . . $enable_log_logstash])
  AC_MSG_RESULT([    lpar  . . . . . . . . $enable_lpar])
+ AC_MSG_RESULT([    lua . . . . . . . . . $enable_lua])
  AC_MSG_RESULT([    lvm . . . . . . . . . $enable_lvm])
  AC_MSG_RESULT([    madwifi . . . . . . . $enable_madwifi])
  AC_MSG_RESULT([    match_empty_counter . $enable_match_empty_counter])
diff --combined src/Makefile.am
@@@ -170,6 -170,7 +170,7 @@@ apache_la_CFLAGS = $(AM_CFLAGS) $(BUILD
  apache_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS)
  endif
  
  if BUILD_PLUGIN_APCUPS
  pkglib_LTLIBRARIES += apcups.la
  apcups_la_SOURCES = apcups.c
@@@ -574,6 -575,15 +575,15 @@@ 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_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBLUA_CPPFLAGS)
+ lua_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBLUA_LDFLAGS)
+ lua_la_LIBADD = $(BUILD_WITH_LIBLUA_LIBS)
+ endif
  if BUILD_PLUGIN_LVM
  pkglib_LTLIBRARIES += lvm.la
  lvm_la_SOURCES = lvm.c
@@@ -1005,9 -1015,13 +1015,9 @@@ endi
  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
 +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
@@@ -1354,6 -1368,7 +1364,7 @@@ dist_man_MANS = collectd.1 
                collectd-exec.5 \
                collectdctl.1 \
                collectd-java.5 \
+               collectd-lua.5 \
                collectdmon.1 \
                collectd-nagios.1 \
                collectd-perl.5 \
@@@ -1369,6 -1384,7 +1380,7 @@@ EXTRA_DIST =    collectd.conf.pod 
                collectd-exec.pod \
                collectdctl.pod \
                collectd-java.pod \
+               collectd-lua.pod \
                collectdmon.pod \
                collectd-nagios.pod \
                collectd-perl.pod \
diff --combined src/collectd.conf.in
  #@BUILD_PLUGIN_JAVA_TRUE@LoadPlugin java
  @BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
  #@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar
+ #@BUILD_PLUGIN_LUA_TRUE@LoadPlugin lua
  #@BUILD_PLUGIN_LVM_TRUE@LoadPlugin lvm
  #@BUILD_PLUGIN_MADWIFI_TRUE@LoadPlugin madwifi
  #@BUILD_PLUGIN_MBMON_TRUE@LoadPlugin mbmon
  #</Plugin>
  
  #<Plugin grpc>
 +#     <Server "example.com" "50051">
 +#             EnableSSL true
 +#             SSLCACertificateFile "/path/to/root.pem"
 +#             SSLCertificateFile "/path/to/server.pem"
 +#             SSLCertificateKeyFile "/path/to/server.key"
 +#     </Server>
  #     <Listen "0.0.0.0" "50051">
  #             EnableSSL true
 -#             SSLRootCerts "/path/to/root.pem"
 -#             SSLServerCert "/path/to/server.pem"
 -#             SSLServerKey "/path/to/server.key"
 +#             SSLCACertificateFile "/path/to/root.pem"
 +#             SSLCertificateFile "/path/to/client.pem"
 +#             SSLCertificateKeyFile "/path/to/client.key"
  #     </Listen>
  #</Plugin>
  
  #     ReportBySerial false
  #</Plugin>
  
+ #<Plugin lua>
+ #     BasePath "@prefix@/share/@PACKAGE_NAME@/lua"
+ #     Script "script1.lua"
+ #     Script "script2.lua"
+ #</Plugin>
  #<Plugin madwifi>
  #     Interface "wlan0"
  #     IgnoreSelected false
diff --combined src/collectd.conf.pod
@@@ -1775,11 -1775,6 +1775,11 @@@ The following options are valid within 
  
  =over 4
  
 +=item B<Host> I<Name>
 +
 +Use I<Name> as the host name when submitting values. Defaults to the global
 +host name setting.
 +
  =item B<Instance> I<Instance>
  
  Sets the plugin instance to I<Instance>.
@@@ -2733,33 -2728,6 +2733,33 @@@ The B<gRPC> homepage can be found at L<
  
  =over 4
  
 +=item B<Server> I<Host> I<Port>
 +
 +The B<Server> statement sets the address of a server to which to send metrics
 +via the C<DispatchValues> function.
 +
 +The argument I<Host> may be a hostname, an IPv4 address, or an IPv6 address.
 +
 +Optionally, B<Server> may be specified as a configuration block which supports
 +the following options:
 +
 +=over 4
 +
 +=item B<EnableSSL> B<false>|B<true>
 +
 +Whether to require SSL for outgoing connections. Default: false.
 +
 +=item B<SSLCACertificateFile> I<Filename>
 +
 +=item B<SSLCertificateFile> I<Filename>
 +
 +=item B<SSLCertificateKeyFile> I<Filename>
 +
 +Filenames specifying SSL certificate and key material to be used with SSL
 +connections.
 +
 +=back
 +
  =item B<Listen> I<Host> I<Port>
  
  The B<Listen> statement sets the network address to bind to. When multiple
@@@ -2777,11 -2745,11 +2777,11 @@@ supports the following options
  
  Whether to enable SSL for incoming connections. Default: false.
  
 -=item B<SSLRootCerts> I<Filename>
 +=item B<SSLCACertificateFile> I<Filename>
  
 -=item B<SSLServerKey> I<Filename>
 +=item B<SSLCertificateFile> I<Filename>
  
 -=item B<SSLServerCert> I<Filename>
 +=item B<SSLCertificateKeyFile> I<Filename>
  
  Filenames specifying SSL certificate and key material to be used with SSL
  connections.
@@@ -3115,6 -3083,12 +3115,12 @@@ Defaults to false
  
  =back
  
+ =head2 Plugin C<lua>
+ This plugin embeds a Lua interpreter into collectd and provides an interface
+ to collectd's plugin system. See L<collectd-lua(5)> for its documentation.
  =head2 Plugin C<mbmon>
  
  The C<mbmon plugin> uses mbmon to retrieve temperature, voltage, etc.