]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
stats_noreset feature for unbound-control
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 12 Feb 2009 11:41:51 +0000 (11:41 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 12 Feb 2009 11:41:51 +0000 (11:41 +0000)
git-svn-id: file:///svn/unbound/trunk@1478 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/remote.c
daemon/stats.c
daemon/stats.h
daemon/worker.c
daemon/worker.h
doc/Changelog
doc/TODO
doc/unbound-control.8.in
smallapp/unbound-control.c

index a54644c66d97b0318f3db18b46f02c8d633bfdd0..02558139b9e1e1a855bcd56ebd5b2a6000262720 100644 (file)
@@ -846,7 +846,7 @@ print_ext(SSL* ssl, struct stats_info* s)
 
 /** do the stats command */
 static void
-do_stats(SSL* ssl, struct daemon_remote* rc)
+do_stats(SSL* ssl, struct daemon_remote* rc, int reset)
 {
        struct daemon* daemon = rc->worker->daemon;
        struct stats_info total;
@@ -854,7 +854,7 @@ do_stats(SSL* ssl, struct daemon_remote* rc)
        int i;
        /* gather all thread statistics in one place */
        for(i=0; i<daemon->num; i++) {
-               server_stats_obtain(rc->worker, daemon->workers[i], &s);
+               server_stats_obtain(rc->worker, daemon->workers[i], &s, reset);
                if(!print_thread_stats(ssl, i, &s))
                        return;
                if(i == 0)
@@ -1387,8 +1387,11 @@ execute_cmd(struct daemon_remote* rc, SSL* ssl, char* cmd,
        } else if(strncmp(p, "reload", 6) == 0) {
                do_reload(ssl, rc);
                return;
+       } else if(strncmp(p, "stats_noreset", 13) == 0) {
+               do_stats(ssl, rc, 0);
+               return;
        } else if(strncmp(p, "stats", 5) == 0) {
-               do_stats(ssl, rc);
+               do_stats(ssl, rc, 1);
                return;
        } else if(strncmp(p, "status", 6) == 0) {
                do_status(ssl, worker);
index 465a57acfa101204efad48415c378e5220a911ec..8dfc08ac22e70afaca1186ccea7c530f2109e37e 100644 (file)
@@ -115,7 +115,7 @@ get_rrset_bogus(struct worker* worker)
 }
 
 void
-server_stats_compile(struct worker* worker, struct stats_info* s)
+server_stats_compile(struct worker* worker, struct stats_info* s, int reset)
 {
        int i;
 
@@ -143,24 +143,26 @@ server_stats_compile(struct worker* worker, struct stats_info* s)
        /* get and reset validator rrset bogus number */
        s->svr.rrset_bogus = get_rrset_bogus(worker);
 
-       if(!worker->env.cfg->stat_cumulative) {
+       if(reset && !worker->env.cfg->stat_cumulative) {
                worker_stats_clear(worker);
        }
 }
 
 void server_stats_obtain(struct worker* worker, struct worker* who,
-       struct stats_info* s)
+       struct stats_info* s, int reset)
 {
        uint8_t *reply = NULL;
        uint32_t len = 0;
        if(worker == who) {
                /* just fill it in */
-               server_stats_compile(worker, s);
+               server_stats_compile(worker, s, reset);
                return;
        }
        /* communicate over tube */
        verbose(VERB_ALGO, "write stats cmd");
-       worker_send_cmd(who, worker_cmd_stats);
+       if(reset)
+               worker_send_cmd(who, worker_cmd_stats);
+       else    worker_send_cmd(who, worker_cmd_stats_noreset);
        verbose(VERB_ALGO, "wait for stats reply");
        if(!tube_read_msg(worker->cmd, &reply, &len, 0))
                fatal_exit("failed to read stats over cmd channel");
@@ -171,10 +173,10 @@ void server_stats_obtain(struct worker* worker, struct worker* who,
        free(reply);
 }
 
-void server_stats_reply(struct worker* worker)
+void server_stats_reply(struct worker* worker, int reset)
 {
        struct stats_info s;
-       server_stats_compile(worker, &s);
+       server_stats_compile(worker, &s, reset);
        verbose(VERB_ALGO, "write stats replymsg");
        if(!tube_write_msg(worker->daemon->workers[0]->cmd, 
                (uint8_t*)&s, sizeof(s), 0))
index 0e339c3fd5e4492cab7bbe713eb8d959beb59357..1074e0b3281e1e1b26ea72fcf852abc71bf711c8 100644 (file)
@@ -175,23 +175,29 @@ void server_stats_log(struct server_stats* stats, struct worker* worker,
  * @param worker: the worker that is executing (the first worker).
  * @param who: on who to get the statistics info.
  * @param s: the stats block to fill in.
+ * @param reset: if stats can be reset.
  */
 void server_stats_obtain(struct worker* worker, struct worker* who,
-       struct stats_info* s);
+       struct stats_info* s, int reset);
 
 /**
  * Compile stats into structure for this thread worker.
  * Also clears the statistics counters (if that is set by config file).
  * @param worker: the worker to compile stats for, also the executing worker.
  * @param s: stats block.
+ * @param reset: if true, depending on config stats are reset.
+ *     if false, statistics are not reset.
  */
-void server_stats_compile(struct worker* worker, struct stats_info* s);
+void server_stats_compile(struct worker* worker, struct stats_info* s, 
+       int reset);
 
 /**
  * Send stats over comm tube in reply to query cmd
  * @param worker: this worker.
+ * @param reset: if true, depending on config stats are reset.
+ *     if false, statistics are not reset.
  */
-void server_stats_reply(struct worker* worker);
+void server_stats_reply(struct worker* worker, int reset);
 
 /**
  * Addup stat blocks.
index e87943f49652dd40fd2325055c1f4757d0054c56..e3ab440fde6fffe02dce0532ea5beb2cc6e75aed 100644 (file)
@@ -342,7 +342,11 @@ worker_handle_control_cmd(struct tube* ATTR_UNUSED(tube), uint8_t* msg,
                break;
        case worker_cmd_stats:
                verbose(VERB_ALGO, "got control cmd stats");
-               server_stats_reply(worker);
+               server_stats_reply(worker, 1);
+               break;
+       case worker_cmd_stats_noreset:
+               verbose(VERB_ALGO, "got control cmd stats_noreset");
+               server_stats_reply(worker, 0);
                break;
        case worker_cmd_remote:
                verbose(VERB_ALGO, "got control cmd remote");
index 14c2abcb7e71148aaaaf9ea39a874da346a648c0..47e349ed9487a3d926ed1676964da039c2c8676b 100644 (file)
@@ -67,6 +67,8 @@ enum worker_commands {
        worker_cmd_quit,
        /** obtain statistics */
        worker_cmd_stats,
+       /** obtain statistics without statsclear */
+       worker_cmd_stats_noreset,
        /** execute remote control command */
        worker_cmd_remote
 };
index 16dd3d0fe5163b4f66b314496f6109c415e9a028..714245b7c6ea10a8e40ba4eee54c2d1ac01f3d47 100644 (file)
@@ -2,6 +2,7 @@
        - call setusercontext if available (on BSD).
        - small refactor of stats clearing.
        - #227: flush_stats feature for unbound-control.
+       - stats_noreset feature for unbound-control.
 
 10 February 2009: Wouter
        - keys with rfc5011 REVOKE flag are skipped and not considered when
index adb4c722f1f339e80fa9d998388c9ac1b2e5cfc0..264d6adfa0012d8a4ddd908c2dc718b9bfc413c6 100644 (file)
--- a/doc/TODO
+++ b/doc/TODO
@@ -59,7 +59,6 @@ o local-zone directive with authority service, full authority server
 o remote control read ssl information while priviledged.
  
 o infra and lame cache: easier size config (in Mb), show usage in graphs.
-o unbound_control get_stats_noreset
 o unbound_control forward [addr {addr}] | [off]
 o config entry to denote that a zone is to be treated as unsigned (even if 
   a DS exists to higher trust anchor).
index 6c69a14f73e49881007b2345634a43d756a9d56d..7bc3a05dfc21c0c941ec46eb86af4ee2071b81b9 100644 (file)
@@ -61,6 +61,10 @@ Print statistics. Resets the internal counters to zero, this can be
 controlled using the \fBstatistics\-cumulative\fR config statement. 
 Statistics are printed with one [name]: [value] per line.
 .TP
+.B stats_noreset
+Peek at statistics. Prints them like the \fBstats\fR command does, but does not
+reset the internal counters to zero.
+.TP
 .B status
 Display server status. Exit code 3 if not running (the connection to the 
 port is refused), 1 on error, 0 if running.
index fe11743bcfbe8d12d0f2382a3d42ab922e8f4699..83afa89f141b37fc76d783a4db4faeebb34d4765 100644 (file)
@@ -62,6 +62,7 @@ usage()
        printf("  stop                          stops the server\n");
        printf("  reload                        reloads the server\n");
        printf("  stats                         print statistics\n");
+       printf("  stats_noreset                 peek at statistics\n");
        printf("  status                        display status of server\n");
        printf("  verbosity [number]            change logging detail\n");
        printf("  local_zone [name] [type]      add new local zone\n");