From: Wouter Wijngaards Date: Thu, 12 Feb 2009 11:41:51 +0000 (+0000) Subject: stats_noreset feature for unbound-control X-Git-Tag: release-1.3.0~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca09b7014b2d3dd84350c814e993fddddf550b46;p=thirdparty%2Funbound.git stats_noreset feature for unbound-control git-svn-id: file:///svn/unbound/trunk@1478 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/remote.c b/daemon/remote.c index a54644c66..02558139b 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -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; inum; 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); diff --git a/daemon/stats.c b/daemon/stats.c index 465a57acf..8dfc08ac2 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -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)) diff --git a/daemon/stats.h b/daemon/stats.h index 0e339c3fd..1074e0b32 100644 --- a/daemon/stats.h +++ b/daemon/stats.h @@ -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. diff --git a/daemon/worker.c b/daemon/worker.c index e87943f49..e3ab440fd 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -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"); diff --git a/daemon/worker.h b/daemon/worker.h index 14c2abcb7..47e349ed9 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -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 }; diff --git a/doc/Changelog b/doc/Changelog index 16dd3d0fe..714245b7c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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 diff --git a/doc/TODO b/doc/TODO index adb4c722f..264d6adfa 100644 --- 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). diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 6c69a14f7..7bc3a05df 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -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. diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index fe11743bc..83afa89f1 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -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");