stats_noreset feature for unbound-control

git-svn-id: https://unbound.nlnetlabs.nl/svn/trunk@1478 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
wouter 2009-02-12 11:41:51 +00:00
parent ce503cc9e8
commit ba6e303e45
9 changed files with 37 additions and 15 deletions

View 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);

View 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))

View 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.

View 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");

View 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
};

View 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

View File

@ -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).

View 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.

View 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");