X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Frrd_daemon.c;h=024738b7a30bc0b2d3c14ac1122763fd92c5ac27;hb=f2c7cb87dd7c98dafd9dc058a262253ed9db5281;hp=4b725c2189f9fb325319ee28e8fe7f06d9690a21;hpb=31f353175df83d273bd33340faa415269cd9341d;p=rrdtool.git diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 4b725c2..024738b 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -66,6 +66,8 @@ #include #include #include +#include +#include #include #include @@ -595,6 +597,67 @@ static int flush_file (const char *filename) /* {{{ */ 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) { @@ -798,6 +861,10 @@ static int handle_request (int fd) /* {{{ */ { 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);