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.])],
[
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"
tcpconns . . . . . . $enable_tcpconns
teamspeak2 . . . . . $enable_teamspeak2
ted . . . . . . . . . $enable_ted
+ tokyotyrant . . . . . $enable_tokyotyrant
thermal . . . . . . . $enable_thermal
unixsock . . . . . . $enable_unixsock
uptime . . . . . . . $enable_uptime
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 : */