[collectd] [PATCH] Plugin for monitoring TokyoTyrant

Paul Sadauskas psadauskas at gmail.com
Thu Jun 18 22:58:29 CEST 2009


Please ignore the one awaiting moderation in the filter. I joined the list.

I'm very rusty at my C, and I really don't understand how the build system
here works. Please feel free to modify this submission, or let me know what
I need to do to make it better.

Thanks,

Paul

On Thu, Jun 18, 2009 at 2:55 PM, Paul Sadauskas <psadauskas at gmail.com>wrote:

> This plugin monitors the record count and file size of the configured
> tokyocabinet server.
>
> TokyoTyrant: http://tokyocabinet.sourceforge.net/tyrantdoc/
>
> Signed-off-by: Paul Sadauskas <psadauskas at gmail.com>
> ---
>  configure.in         |   30 ++++++++++++++
>  src/Makefile.am      |    9 ++++
>  src/collectd.conf.in |    5 ++
>  src/tokyotyrant.c    |  108
> ++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/types.db         |    2 +
>  5 files changed, 154 insertions(+), 0 deletions(-)
>  create mode 100644 src/tokyotyrant.c
>
> diff --git a/configure.in b/configure.in
> index 51e3803..a663449 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -1095,6 +1095,34 @@ then
>  fi
>  AM_CONDITIONAL(BUILD_WITH_LIBKVM_OPENFILES, test "x$with_kvm_openfiles" =
> "xyes")
>
> +# --with-libtokyotyrant {{{
> +with_libtokyotyrant_libs=""
> +AC_ARG_WITH(libtokyotyrant, [AS_HELP_STRING([--with-libtokyotyrant@
> <:@=PREFIX@:>@], [Path to libtokyotyrant.])],
> +[
> +  if test "x$withval" = "xno"
> +  then
> +    with_libtokyotyrant="no"
> +  else if test "x$withval" = "xyes"
> +  then
> +    with_libtokyotyrant="yes"
> +  fi; fi
> +],
> +[
> +  with_libtokyotyrant="yes"
> +])
> +
> +if test "x$with_libtokyotyrant" = "xyes"
> +then
> +  #with_libtokyotyrant_libs="-ltokyotyrant"
> +  with_libtokyotyrant_libs="-ltokyotyrant -ltokyocabinet"
> +
> +
> +  BUILD_WITH_LIBTOKYOTYRANT_LIBS="$with_libtokyotyrant_libs"
> +  AC_SUBST(BUILD_WITH_LIBTOKYOTYRANT_LIBS)
> +fi
> +AM_CONDITIONAL(BUILD_WITH_LIBTOKYOTYRANT, test "x$with_libtokyotyrant" =
> "xyes")
> +# }}}
> +
>  # --with-libcurl {{{
>  with_curl_config="curl-config"
>  with_curl_cflags=""
> @@ -3689,6 +3717,7 @@ 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([tokyotyrant], [$with_libtokyotyrant],  [TokyoTyrant database
> statistics])
>  AC_PLUGIN([unixsock],    [yes],                [Unixsock communication
> plugin])
>  AC_PLUGIN([uptime],      [$plugin_uptime],     [Uptime statistics])
>  AC_PLUGIN([users],       [$plugin_users],      [User statistics])
> @@ -3891,6 +3920,7 @@ Configuration:
>     librrd  . . . . . . . $with_librrd
>     libsensors  . . . . . $with_libsensors
>     libstatgrab . . . . . $with_libstatgrab
> +    libtokyotyrant  . . . $with_libtokyotyrant
>     libupsclient  . . . . $with_libupsclient
>     libvirt . . . . . . . $with_libvirt
>     libxml2 . . . . . . . $with_libxml2
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 129cdd0..b49704d 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -952,6 +952,15 @@ collectd_LDADD += "-dlopen" thermal.la
>  collectd_DEPENDENCIES += thermal.la
>  endif
>
> +if BUILD_PLUGIN_TOKYOTYRANT
> +pkglib_LTLIBRARIES += tokyotyrant.la
> +tokyotyrant_la_SOURCES = tokyotyrant.c
> +tokyotyrant_la_LDFLAGS = -module -avoid-version
> +tokyotyrant_la_LIBADD  = $(BUILD_WITH_LIBTOKYOTYRANT_LIBS)
> +collectd_LDADD += "-dlopen" tokyotyrant.la
> +collectd_DEPENDENCIES += tokyotyrant.la
> +endif
> +
>  if BUILD_PLUGIN_UNIXSOCK
>  pkglib_LTLIBRARIES += unixsock.la
>  unixsock_la_SOURCES = unixsock.c \
> diff --git a/src/collectd.conf.in b/src/collectd.conf.in
> index 84a71fa..8b6d1ba 100644
> --- a/src/collectd.conf.in
> +++ b/src/collectd.conf.in
> @@ -118,6 +118,7 @@ FQDNLookup   true
>  #@BUILD_PLUGIN_TEAMSPEAK2_TRUE at LoadPlugin teamspeak2
>  #@BUILD_PLUGIN_TED_TRUE at LoadPlugin ted
>  #@BUILD_PLUGIN_THERMAL_TRUE at LoadPlugin thermal
> +#@BUILD_PLUGIN_TOKYOTYRANT_TRUE at LoadPlugin tokyotyrant
>  #@BUILD_PLUGIN_UNIXSOCK_TRUE at LoadPlugin unixsock
>  #@BUILD_PLUGIN_UPTIME_TRUE at LoadPlugin uptime
>  #@BUILD_PLUGIN_USERS_TRUE at LoadPlugin users
> @@ -676,6 +677,10 @@ FQDNLookup   true
>  #      IgnoreSelected false
>  #</Plugin>
>
> +#<Plugin tokyotyrant>
> +#      Host "localhost:1978"
> +#</Plugin>
> +
>  #<Plugin unixsock>
>  #      SocketFile "@prefix@/var/run/@PACKAGE_NAME at -unixsock"
>  #      SocketGroup "collectd"
> diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c
> new file mode 100644
> index 0000000..3ac0f97
> --- /dev/null
> +++ b/src/tokyotyrant.c
> @@ -0,0 +1,108 @@
> +/**
> + * collectd - src/tokyotyrant.c
> + * Copyright (C) 2009 Paul Sadauskas
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; only version 2 of the License is applicable.
> + *
> + * 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 St, Fifth Floor, Boston, MA  02110-1301 USA
> + *
> + * Authors:
> + *   Paul Sadauskas <psadauskas at gmail.com>
> + **/
> +
> +#include "collectd.h"
> +#include "plugin.h"
> +#include "common.h"
> +#include "utils_cache.h"
> +#include "utils_parse_option.h"
> +#include <tcrdb.h>
> +
> +static const char *config_keys[] =
> +{
> +  "Host"
> +};
> +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
> +
> +static char *host = NULL;
> +
> +static int tt_config (const char *key, const char *value);
> +static int tt_read (void);
> +static void tt_submit(gauge_t rnum, const char *type);
> +
> +void module_register (void)
> +{
> +  plugin_register_config("tokyotyrant", tt_config, config_keys,
> config_keys_num);
> +  plugin_register_read("tokyotyrant", tt_read);
> +}
> +
> +static int tt_config (const char *key, const char *value)
> +{
> +
> +  if (strcasecmp ("Host", key) == 0)
> +  {
> +    if (host != NULL)
> +      free (host);
> +    host = strdup(value);
> +  }
> +  return (0);
> +}
> +
> +static void printerr(TCRDB *rdb)
> +{
> +  int ecode = tcrdbecode(rdb);
> +  ERROR ("tokyotyrant plugin: error: %d, %s", ecode, tcrdberrmsg(ecode));
> +}
> +
> +static int tt_read (void) {
> +  gauge_t rnum, size;
> +
> +  TCRDB *rdb = tcrdbnew();
> +
> +  if (!tcrdbopen2(rdb, host))
> +  {
> +    printerr (rdb);
> +    tcrdbdel (rdb);
> +    return (1);
> +  }
> +
> +  rnum = tcrdbrnum(rdb);
> +  size = tcrdbsize(rdb);
> +
> +  if (!tcrdbclose(rdb))
> +  {
> +    printerr (rdb);
> +    tcrdbdel (rdb);
> +    return (1);
> +  }
> +  tt_submit (rnum, "records");
> +  tt_submit (size, "file_size");
> +
> +  return (0);
> +}
> +
> +static void tt_submit (gauge_t val, const char* type)
> +{
> +  value_t values[1];
> +  value_list_t vl = VALUE_LIST_INIT;
> +
> +  values[0].gauge = val;
> +
> +  vl.values = values;
> +  vl.values_len = STATIC_ARRAY_SIZE (values);
> +
> +  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
> +  sstrncpy (vl.plugin, "tokyotyrant", sizeof (vl.plugin));
> +  sstrncpy (vl.plugin_instance, host, sizeof (vl.plugin_instance));
> +  sstrncpy (vl.type, type, sizeof (vl.type));
> +
> +  plugin_dispatch_values (&vl);
> +}
> diff --git a/src/types.db b/src/types.db
> index 7028fe7..63ea23a 100644
> --- a/src/types.db
> +++ b/src/types.db
> @@ -41,6 +41,7 @@ email_count           value:GAUGE:0:U
>  email_size             value:GAUGE:0:U
>  entropy                        entropy:GAUGE:0:4294967295
>  fanspeed               value:GAUGE:0:U
> +file_size               bytes:GAUGE:0:U
>  files                  value:GAUGE:0:U
>  frequency              frequency:GAUGE:0:U
>  frequency_offset       ppm:GAUGE:-1000000:1000000
> @@ -106,6 +107,7 @@ ps_stacksize
>  value:GAUGE:0:9223372036854775807
>  ps_state               value:GAUGE:0:65535
>  ps_vm                  value:GAUGE:0:9223372036854775807
>  queue_length           value:GAUGE:0:U
> +records                 count:GAUGE:0:U
>  route_etx              value:GAUGE:0:U
>  route_metric           value:GAUGE:0:U
>  routes                 value:GAUGE:0:U
> --
> 1.6.3.2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.verplant.org/pipermail/collectd/attachments/20090618/3242e067/attachment-0001.htm 


More information about the collectd mailing list