[collectd] [PATCH] Changes suggested by Sebastian Harl.
Paul Sadauskas
psadauskas at gmail.com
Sat Jun 20 22:57:09 CEST 2009
* Separate Host and Port in config, report Host as hostname, and Port as
plugin instance.
* Submit before closing connection.
* Else-case in config, in case of invalid config params.
* Flounder around at using pkg-config in configure.in
* Remove forward declarations.
* Include plugin in config summary.
Signed-off-by: Paul Sadauskas <psadauskas at gmail.com>
---
configure.in | 6 ++-
src/collectd.conf.in | 3 +-
src/tokyotyrant.c | 139 +++++++++++++++++++++++++++++--------------------
3 files changed, 88 insertions(+), 60 deletions(-)
diff --git a/configure.in b/configure.in
index a663449..a0ff550 100644
--- a/configure.in
+++ b/configure.in
@@ -1096,6 +1096,7 @@ fi
AM_CONDITIONAL(BUILD_WITH_LIBKVM_OPENFILES, test "x$with_kvm_openfiles" = "xyes")
# --with-libtokyotyrant {{{
+with_libtokyotyrant_cflags=""
with_libtokyotyrant_libs=""
AC_ARG_WITH(libtokyotyrant, [AS_HELP_STRING([--with-libtokyotyrant@<:@=PREFIX@:>@], [Path to libtokyotyrant.])],
[
@@ -1113,8 +1114,8 @@ AC_ARG_WITH(libtokyotyrant, [AS_HELP_STRING([--with-libtokyotyrant@<:@=PREFIX@:>
if test "x$with_libtokyotyrant" = "xyes"
then
- #with_libtokyotyrant_libs="-ltokyotyrant"
- with_libtokyotyrant_libs="-ltokyotyrant -ltokyocabinet"
+ with_libtokyotyrant_cflags="`$PKG_CONFIG --cflags tokyotyrant`"
+ with_libtokyotyrant_libs="`$PKG_CONFIG --libs tokyotyrant`"
BUILD_WITH_LIBTOKYOTYRANT_LIBS="$with_libtokyotyrant_libs"
@@ -4011,6 +4012,7 @@ Configuration:
tcpconns . . . . . . $enable_tcpconns
teamspeak2 . . . . . $enable_teamspeak2
ted . . . . . . . . . $enable_ted
+ tokyotyrant . . . . . $enable_tokyotyrant
thermal . . . . . . . $enable_thermal
unixsock . . . . . . $enable_unixsock
uptime . . . . . . . $enable_uptime
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 8b6d1ba..0296cc4 100644
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
@@ -678,7 +678,8 @@ FQDNLookup true
#</Plugin>
#<Plugin tokyotyrant>
-# Host "localhost:1978"
+# Host "localhost"
+# Port 1978
#</Plugin>
#<Plugin unixsock>
diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c
index 3ac0f97..d539889 100644
--- a/src/tokyotyrant.c
+++ b/src/tokyotyrant.c
@@ -28,81 +28,106 @@
static const char *config_keys[] =
{
- "Host"
+ "Host",
+ "Port"
};
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);
-}
+/* int is for opening connection, string is for plugin_instance */
+static char *port_str = NULL;
+static int port;
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);
+ if (strcasecmp ("Host", key) == 0)
+ {
+ if (host != NULL)
+ free (host);
+ host = strdup(value);
+ }
+ else if (strcasecmp ("Port", key) == 0)
+ {
+ if (port_str != NULL)
+ free (port_str);
+ port_str = strdup(value);
+
+ port = atoi(value);
+
+ if ((port < 0) || (port > 65535))
+ {
+ ERROR ("tokyotyrant plugin: error: Port %s out of range", value);
+ return (-1);
+ }
+ }
+ else
+ {
+ ERROR ("tokyotyrant plugin: error: unrecognized configuration key %s", key);
+ return (-1);
+ }
+
+ 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);
+ int ecode = tcrdbecode(rdb);
+ ERROR ("tokyotyrant plugin: error: %d, %s",
+ ecode, tcrdberrmsg(ecode));
}
static void tt_submit (gauge_t val, const char* type)
{
- value_t values[1];
- value_list_t vl = VALUE_LIST_INIT;
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
- values[0].gauge = val;
+ values[0].gauge = val;
- vl.values = values;
- vl.values_len = STATIC_ARRAY_SIZE (values);
+ 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));
+ sstrncpy (vl.host, host, sizeof (vl.host));
+ sstrncpy (vl.plugin, "tokyotyrant", sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, port_str,
+ sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (&vl);
+ plugin_dispatch_values (&vl);
}
+
+static int tt_read (void) {
+ gauge_t rnum, size;
+
+ TCRDB *rdb = tcrdbnew();
+
+ if (!tcrdbopen(rdb, host, port))
+ {
+ printerr (rdb);
+ tcrdbdel (rdb);
+ return (1);
+ }
+
+ rnum = tcrdbrnum(rdb);
+ size = tcrdbsize(rdb);
+ tt_submit (rnum, "records");
+ tt_submit (size, "file_size");
+
+ if (!tcrdbclose(rdb))
+ {
+ printerr (rdb);
+ tcrdbdel (rdb);
+ return (1);
+ }
+
+ return (0);
+}
+
+void module_register (void)
+{
+ plugin_register_config("tokyotyrant", tt_config,
+ config_keys, config_keys_num);
+ plugin_register_read("tokyotyrant", tt_read);
+}
+
+/* vim: set sw=8 ts=8 tw=78 : */
--
1.6.3.2
More information about the collectd
mailing list