#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
return (0);
} /* }}} int flush_file */
+static int handle_request_stats (int fd, /* {{{ */
+ char *buffer __attribute__((unused)),
+ size_t buffer_size __attribute__((unused)))
+{
+ int status;
+ char outbuf[4096];
+
+ uint64_t copy_queue_length;
+ uint64_t copy_updates_total;
+ uint64_t copy_values_total;
+
+ uint64_t tree_nodes;
+ uint64_t tree_depth;
+
+ pthread_mutex_lock (&stats_lock);
+ copy_queue_length = stats_queue_length;
+ copy_updates_total = stats_updates_total;
+ copy_values_total = stats_values_total;
+ pthread_mutex_unlock (&stats_lock);
+
+ pthread_mutex_lock (&cache_lock);
+ tree_nodes = (uint64_t) g_tree_nnodes (cache_tree);
+ tree_depth = (uint64_t) g_tree_height (cache_tree);
+ pthread_mutex_unlock (&cache_lock);
+
+#define RRDD_STATS_SEND \
+ outbuf[sizeof (outbuf) - 1] = 0; \
+ status = write (fd, outbuf, strlen (outbuf)); \
+ if (status < 0) \
+ { \
+ status = errno; \
+ RRDD_LOG (LOG_INFO, "handle_request_stats: write(2) returned an error."); \
+ return (status); \
+ }
+
+ strncpy (outbuf, "5 Statistics follow\n", sizeof (outbuf));
+ RRDD_STATS_SEND;
+
+ snprintf (outbuf, sizeof (outbuf),
+ "QueueLength: %"PRIu64"\n", copy_queue_length);
+ RRDD_STATS_SEND;
+
+ snprintf (outbuf, sizeof (outbuf),
+ "UpdatesWritten: %"PRIu64"\n", copy_updates_total);
+ RRDD_STATS_SEND;
+
+ snprintf (outbuf, sizeof (outbuf),
+ "ValuesWritten: %"PRIu64"\n", copy_values_total);
+ RRDD_STATS_SEND;
+
+ snprintf (outbuf, sizeof (outbuf),
+ "TreeNodesNumber: %"PRIu64"\n", tree_nodes);
+ RRDD_STATS_SEND;
+
+ snprintf (outbuf, sizeof (outbuf),
+ "TreeDepth: %"PRIu64"\n", tree_depth);
+ RRDD_STATS_SEND;
+
+ return (0);
+} /* }}} int handle_request_stats */
+
static int handle_request_flush (int fd, /* {{{ */
char *buffer, size_t buffer_size)
{
{
return (handle_request_flush (fd, buffer_ptr, buffer_size));
}
+ else if (strcmp (command, "stats") == 0)
+ {
+ return (handle_request_stats (fd, buffer_ptr, buffer_size));
+ }
else
{
RRDD_LOG (LOG_INFO, "handle_request: unknown command: %s.", buffer);