#include "plugin.h"
#include <netdb.h>
-#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
else
{
return -1;
- }
+ }
return 0;
}
static int zookeeper_connect (void)
{
- int sk;
+ int sk = -1;
int status;
struct addrinfo ai_hints;
struct addrinfo *ai;
struct addrinfo *ai_list;
- char *host;
- char *port;
+ const char *host;
+ const char *port;
memset ((void *) &ai_hints, '\0', sizeof (ai_hints));
ai_hints.ai_family = AF_UNSPEC;
ai_hints.ai_socktype = SOCK_STREAM;
-
+
host = (zk_host != NULL) ? zk_host : ZOOKEEPER_DEF_HOST;
port = (zk_port != NULL) ? zk_port : ZOOKEEPER_DEF_PORT;
status = getaddrinfo (host, port, &ai_hints, &ai_list);
for (ai = ai_list; ai != NULL; ai = ai->ai_next)
{
- sk = socket (ai->ai_family, SOCK_STREAM, 0);
+ sk = socket (ai->ai_family, SOCK_STREAM, 0);
if (sk < 0)
{
char errbuf[1024];
sk = -1;
WARNING ("zookeeper: connect(2) failed: %s",
sstrerror (errno, errbuf, sizeof(errbuf)));
- continue;
+ continue;
}
-
+
/* connected */
break;
}
freeaddrinfo(ai_list);
return (sk);
} /* int zookeeper_connect */
-
+
static int zookeeper_query (char *buffer, size_t buffer_size)
{
- int sk = -1;
- int status;
+ int sk, status;
size_t buffer_fill;
sk = zookeeper_connect();
ERROR ("zookeeper: Could not connect to daemon");
return (-1);
}
-
+
status = (int) swrite (sk, "mntr\r\n", strlen("mntr\r\n"));
if (status != 0)
{
close (sk);
return (-1);
}
-
+
buffer_fill += (size_t) status;
- if (status == 0)
- {
- /* done reading from the socket */
- break;
- }
} /* while (recv) */
status = 0;
} /* int zookeeper_query */
-static int zookeeper_read (void) {
+static int zookeeper_read (void) {
char buf[4096];
char *ptr;
char *save_ptr;
}
else if (FIELD_CHECK (fields[0], "zk_znode_count"))
{
- zookeeper_submit_gauge ("count", "znode", atol(fields[1]));
+ zookeeper_submit_gauge ("gauge", "znode", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_watch_count"))
{
- zookeeper_submit_gauge ("count", "watch", atol(fields[1]));
+ zookeeper_submit_gauge ("gauge", "watch", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
{
- zookeeper_submit_gauge ("count", "ephemerals", atol(fields[1]));
+ zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
{
- zookeeper_submit_gauge ("count", "ephemerals", atol(fields[1]));
+ zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_ephemerals_count"))
{
- zookeeper_submit_gauge ("count", "ephemerals", atol(fields[1]));
+ zookeeper_submit_gauge ("gauge", "ephemerals", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_approximate_data_size"))
{
- zookeeper_submit_gauge ("zk_approximate_data_size", NULL, atol(fields[1]));
+ zookeeper_submit_gauge ("bytes", "approximate_data_size", atol(fields[1]));
}
else if (FIELD_CHECK (fields[0], "zk_followers"))
{
DEBUG("Uncollected zookeeper MNTR field %s", fields[0]);
}
}
-
+
return (0);
} /* zookeeper_read */