Plugin for monitoring TokyoTyrant
authorPaul Sadauskas <psadauskas@gmail.com>
Thu, 18 Jun 2009 19:39:11 +0000 (13:39 -0600)
committerFlorian Forster <sifnfors@informatik.stud.uni-erlangen.de>
Mon, 6 Jul 2009 14:37:49 +0000 (16:37 +0200)
This plugin monitors the record count and file size of the configured
tokyocabinet server.

TokyoTyrant: http://tokyocabinet.sourceforge.net/tyrantdoc/

configure.in
src/Makefile.am
src/collectd.conf.in
src/tokyotyrant.c [new file with mode: 0644]
src/types.db

index 9c1910e..e9aca54 100644 (file)
@@ -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=""
@@ -3688,6 +3716,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
index 11c8ac6..30b0710 100644 (file)
@@ -938,6 +938,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 \
index 918a7c7..704918e 100644 (file)
@@ -118,6 +118,7 @@ FQDNLookup   true
 #@BUILD_PLUGIN_TEAMSPEAK2_TRUE@LoadPlugin teamspeak2
 #@BUILD_PLUGIN_TED_TRUE@LoadPlugin ted
 #@BUILD_PLUGIN_THERMAL_TRUE@LoadPlugin thermal
+#@BUILD_PLUGIN_TOKYOTYRANT_TRUE@LoadPlugin tokyotyrant
 #@BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock
 #@BUILD_PLUGIN_UPTIME_TRUE@LoadPlugin uptime
 #@BUILD_PLUGIN_USERS_TRUE@LoadPlugin users
@@ -685,6 +686,10 @@ FQDNLookup   true
 #      IgnoreSelected false
 #</Plugin>
 
+#<Plugin tokyotyrant>
+#      Host "localhost:1978"
+#</Plugin>
+
 #<Plugin unixsock>
 #      SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"
 #      SocketGroup "collectd"
diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c
new file mode 100644 (file)
index 0000000..5260619
--- /dev/null
@@ -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@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);
+}
index 83e7007..1acdaf6 100644 (file)
@@ -43,6 +43,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
@@ -108,6 +109,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