<br>Please ignore the one awaiting moderation in the filter. I joined the list.<br><br>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.<br>
<br>Thanks,<br><br>Paul<br><br><div class="gmail_quote">On Thu, Jun 18, 2009 at 2:55 PM, Paul Sadauskas <span dir="ltr"><<a href="mailto:psadauskas@gmail.com">psadauskas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">This plugin monitors the record count and file size of the configured<br>
tokyocabinet server.<br>
<br>
TokyoTyrant: <a href="http://tokyocabinet.sourceforge.net/tyrantdoc/" target="_blank">http://tokyocabinet.sourceforge.net/tyrantdoc/</a><br>
<br>
Signed-off-by: Paul Sadauskas <<a href="mailto:psadauskas@gmail.com">psadauskas@gmail.com</a>><br>
---<br>
<a href="http://configure.in" target="_blank">configure.in</a> | 30 ++++++++++++++<br>
src/Makefile.am | 9 ++++<br>
src/<a href="http://collectd.conf.in" target="_blank">collectd.conf.in</a> | 5 ++<br>
src/tokyotyrant.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++<br>
src/types.db | 2 +<br>
5 files changed, 154 insertions(+), 0 deletions(-)<br>
create mode 100644 src/tokyotyrant.c<br>
<br>
diff --git a/<a href="http://configure.in" target="_blank">configure.in</a> b/<a href="http://configure.in" target="_blank">configure.in</a><br>
index 51e3803..a663449 100644<br>
--- a/<a href="http://configure.in" target="_blank">configure.in</a><br>
+++ b/<a href="http://configure.in" target="_blank">configure.in</a><br>
@@ -1095,6 +1095,34 @@ then<br>
fi<br>
AM_CONDITIONAL(BUILD_WITH_LIBKVM_OPENFILES, test "x$with_kvm_openfiles" = "xyes")<br>
<br>
+# --with-libtokyotyrant {{{<br>
+with_libtokyotyrant_libs=""<br>
+AC_ARG_WITH(libtokyotyrant, [AS_HELP_STRING([--with-libtokyotyrant@<:@=PREFIX@:>@], [Path to libtokyotyrant.])],<br>
+[<br>
+ if test "x$withval" = "xno"<br>
+ then<br>
+ with_libtokyotyrant="no"<br>
+ else if test "x$withval" = "xyes"<br>
+ then<br>
+ with_libtokyotyrant="yes"<br>
+ fi; fi<br>
+],<br>
+[<br>
+ with_libtokyotyrant="yes"<br>
+])<br>
+<br>
+if test "x$with_libtokyotyrant" = "xyes"<br>
+then<br>
+ #with_libtokyotyrant_libs="-ltokyotyrant"<br>
+ with_libtokyotyrant_libs="-ltokyotyrant -ltokyocabinet"<br>
+<br>
+<br>
+ BUILD_WITH_LIBTOKYOTYRANT_LIBS="$with_libtokyotyrant_libs"<br>
+ AC_SUBST(BUILD_WITH_LIBTOKYOTYRANT_LIBS)<br>
+fi<br>
+AM_CONDITIONAL(BUILD_WITH_LIBTOKYOTYRANT, test "x$with_libtokyotyrant" = "xyes")<br>
+# }}}<br>
+<br>
# --with-libcurl {{{<br>
with_curl_config="curl-config"<br>
with_curl_cflags=""<br>
@@ -3689,6 +3717,7 @@ AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics])<br>
AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics])<br>
AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values])<br>
AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics])<br>
+AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics])<br>
AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin])<br>
AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics])<br>
AC_PLUGIN([users], [$plugin_users], [User statistics])<br>
@@ -3891,6 +3920,7 @@ Configuration:<br>
librrd . . . . . . . $with_librrd<br>
libsensors . . . . . $with_libsensors<br>
libstatgrab . . . . . $with_libstatgrab<br>
+ libtokyotyrant . . . $with_libtokyotyrant<br>
libupsclient . . . . $with_libupsclient<br>
libvirt . . . . . . . $with_libvirt<br>
libxml2 . . . . . . . $with_libxml2<br>
diff --git a/src/Makefile.am b/src/Makefile.am<br>
index 129cdd0..b49704d 100644<br>
--- a/src/Makefile.am<br>
+++ b/src/Makefile.am<br>
@@ -952,6 +952,15 @@ collectd_LDADD += "-dlopen" <a href="http://thermal.la" target="_blank">thermal.la</a><br>
collectd_DEPENDENCIES += <a href="http://thermal.la" target="_blank">thermal.la</a><br>
endif<br>
<br>
+if BUILD_PLUGIN_TOKYOTYRANT<br>
+pkglib_LTLIBRARIES += <a href="http://tokyotyrant.la" target="_blank">tokyotyrant.la</a><br>
+tokyotyrant_la_SOURCES = tokyotyrant.c<br>
+tokyotyrant_la_LDFLAGS = -module -avoid-version<br>
+tokyotyrant_la_LIBADD = $(BUILD_WITH_LIBTOKYOTYRANT_LIBS)<br>
+collectd_LDADD += "-dlopen" <a href="http://tokyotyrant.la" target="_blank">tokyotyrant.la</a><br>
+collectd_DEPENDENCIES += <a href="http://tokyotyrant.la" target="_blank">tokyotyrant.la</a><br>
+endif<br>
+<br>
if BUILD_PLUGIN_UNIXSOCK<br>
pkglib_LTLIBRARIES += <a href="http://unixsock.la" target="_blank">unixsock.la</a><br>
unixsock_la_SOURCES = unixsock.c \<br>
diff --git a/src/<a href="http://collectd.conf.in" target="_blank">collectd.conf.in</a> b/src/<a href="http://collectd.conf.in" target="_blank">collectd.conf.in</a><br>
index 84a71fa..8b6d1ba 100644<br>
--- a/src/<a href="http://collectd.conf.in" target="_blank">collectd.conf.in</a><br>
+++ b/src/<a href="http://collectd.conf.in" target="_blank">collectd.conf.in</a><br>
@@ -118,6 +118,7 @@ FQDNLookup true<br>
#@BUILD_PLUGIN_TEAMSPEAK2_TRUE@LoadPlugin teamspeak2<br>
#@BUILD_PLUGIN_TED_TRUE@LoadPlugin ted<br>
#@BUILD_PLUGIN_THERMAL_TRUE@LoadPlugin thermal<br>
+#@BUILD_PLUGIN_TOKYOTYRANT_TRUE@LoadPlugin tokyotyrant<br>
#@BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock<br>
#@BUILD_PLUGIN_UPTIME_TRUE@LoadPlugin uptime<br>
#@BUILD_PLUGIN_USERS_TRUE@LoadPlugin users<br>
@@ -676,6 +677,10 @@ FQDNLookup true<br>
# IgnoreSelected false<br>
#</Plugin><br>
<br>
+#<Plugin tokyotyrant><br>
+# Host "localhost:1978"<br>
+#</Plugin><br>
+<br>
#<Plugin unixsock><br>
# SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"<br>
# SocketGroup "collectd"<br>
diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c<br>
new file mode 100644<br>
index 0000000..3ac0f97<br>
--- /dev/null<br>
+++ b/src/tokyotyrant.c<br>
@@ -0,0 +1,108 @@<br>
+/**<br>
+ * collectd - src/tokyotyrant.c<br>
+ * Copyright (C) 2009 Paul Sadauskas<br>
+ *<br>
+ * This program is free software; you can redistribute it and/or modify it<br>
+ * under the terms of the GNU General Public License as published by the<br>
+ * Free Software Foundation; only version 2 of the License is applicable.<br>
+ *<br>
+ * This program is distributed in the hope that it will be useful, but<br>
+ * WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
+ * General Public License for more details.<br>
+ *<br>
+ * You should have received a copy of the GNU General Public License along<br>
+ * with this program; if not, write to the Free Software Foundation, Inc.,<br>
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA<br>
+ *<br>
+ * Authors:<br>
+ * Paul Sadauskas <<a href="mailto:psadauskas@gmail.com">psadauskas@gmail.com</a>><br>
+ **/<br>
+<br>
+#include "collectd.h"<br>
+#include "plugin.h"<br>
+#include "common.h"<br>
+#include "utils_cache.h"<br>
+#include "utils_parse_option.h"<br>
+#include <tcrdb.h><br>
+<br>
+static const char *config_keys[] =<br>
+{<br>
+ "Host"<br>
+};<br>
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);<br>
+<br>
+static char *host = NULL;<br>
+<br>
+static int tt_config (const char *key, const char *value);<br>
+static int tt_read (void);<br>
+static void tt_submit(gauge_t rnum, const char *type);<br>
+<br>
+void module_register (void)<br>
+{<br>
+ plugin_register_config("tokyotyrant", tt_config, config_keys, config_keys_num);<br>
+ plugin_register_read("tokyotyrant", tt_read);<br>
+}<br>
+<br>
+static int tt_config (const char *key, const char *value)<br>
+{<br>
+<br>
+ if (strcasecmp ("Host", key) == 0)<br>
+ {<br>
+ if (host != NULL)<br>
+ free (host);<br>
+ host = strdup(value);<br>
+ }<br>
+ return (0);<br>
+}<br>
+<br>
+static void printerr(TCRDB *rdb)<br>
+{<br>
+ int ecode = tcrdbecode(rdb);<br>
+ ERROR ("tokyotyrant plugin: error: %d, %s", ecode, tcrdberrmsg(ecode));<br>
+}<br>
+<br>
+static int tt_read (void) {<br>
+ gauge_t rnum, size;<br>
+<br>
+ TCRDB *rdb = tcrdbnew();<br>
+<br>
+ if (!tcrdbopen2(rdb, host))<br>
+ {<br>
+ printerr (rdb);<br>
+ tcrdbdel (rdb);<br>
+ return (1);<br>
+ }<br>
+<br>
+ rnum = tcrdbrnum(rdb);<br>
+ size = tcrdbsize(rdb);<br>
+<br>
+ if (!tcrdbclose(rdb))<br>
+ {<br>
+ printerr (rdb);<br>
+ tcrdbdel (rdb);<br>
+ return (1);<br>
+ }<br>
+ tt_submit (rnum, "records");<br>
+ tt_submit (size, "file_size");<br>
+<br>
+ return (0);<br>
+}<br>
+<br>
+static void tt_submit (gauge_t val, const char* type)<br>
+{<br>
+ value_t values[1];<br>
+ value_list_t vl = VALUE_LIST_INIT;<br>
+<br>
+ values[0].gauge = val;<br>
+<br>
+ vl.values = values;<br>
+ vl.values_len = STATIC_ARRAY_SIZE (values);<br>
+<br>
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));<br>
+ sstrncpy (vl.plugin, "tokyotyrant", sizeof (vl.plugin));<br>
+ sstrncpy (vl.plugin_instance, host, sizeof (vl.plugin_instance));<br>
+ sstrncpy (vl.type, type, sizeof (vl.type));<br>
+<br>
+ plugin_dispatch_values (&vl);<br>
+}<br>
diff --git a/src/types.db b/src/types.db<br>
index 7028fe7..63ea23a 100644<br>
--- a/src/types.db<br>
+++ b/src/types.db<br>
@@ -41,6 +41,7 @@ email_count value:GAUGE:0:U<br>
email_size value:GAUGE:0:U<br>
entropy entropy:GAUGE:0:4294967295<br>
fanspeed value:GAUGE:0:U<br>
+file_size bytes:GAUGE:0:U<br>
files value:GAUGE:0:U<br>
frequency frequency:GAUGE:0:U<br>
frequency_offset ppm:GAUGE:-1000000:1000000<br>
@@ -106,6 +107,7 @@ ps_stacksize value:GAUGE:0:9223372036854775807<br>
ps_state value:GAUGE:0:65535<br>
ps_vm value:GAUGE:0:9223372036854775807<br>
queue_length value:GAUGE:0:U<br>
+records count:GAUGE:0:U<br>
route_etx value:GAUGE:0:U<br>
route_metric value:GAUGE:0:U<br>
routes value:GAUGE:0:U<br>
--<br>
1.6.3.2<br>
<br>
</div></div></blockquote></div><br>