diff options
Diffstat (limited to 'usr.sbin/relayctl')
-rw-r--r-- | usr.sbin/relayctl/parser.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayctl/parser.h | 3 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.8 | 10 | ||||
-rw-r--r-- | usr.sbin/relayctl/relayctl.c | 75 |
4 files changed, 57 insertions, 34 deletions
diff --git a/usr.sbin/relayctl/parser.c b/usr.sbin/relayctl/parser.c index f3316f2569e..303713537f9 100644 --- a/usr.sbin/relayctl/parser.c +++ b/usr.sbin/relayctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.19 2007/12/08 20:36:36 pyr Exp $ */ +/* $OpenBSD: parser.c,v 1.20 2007/12/20 20:15:43 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -80,6 +80,7 @@ static const struct token t_main[] = { static const struct token t_show[] = { {KEYWORD, "summary", SHOW_SUM, NULL}, {KEYWORD, "hosts", SHOW_HOSTS, NULL}, + {KEYWORD, "redirects", SHOW_RDRS, NULL}, {KEYWORD, "relays", SHOW_RELAYS, NULL}, {KEYWORD, "sessions", SHOW_SESSIONS, NULL}, {ENDTOKEN, "", NONE, NULL} diff --git a/usr.sbin/relayctl/parser.h b/usr.sbin/relayctl/parser.h index 32d9f79baeb..91e3e949671 100644 --- a/usr.sbin/relayctl/parser.h +++ b/usr.sbin/relayctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.8 2007/12/08 20:36:36 pyr Exp $ */ +/* $OpenBSD: parser.h,v 1.9 2007/12/20 20:15:43 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -20,6 +20,7 @@ enum actions { NONE, SHOW_SUM, SHOW_HOSTS, + SHOW_RDRS, SHOW_RELAYS, SHOW_SESSIONS, RDR_DISABLE, diff --git a/usr.sbin/relayctl/relayctl.8 b/usr.sbin/relayctl/relayctl.8 index ddf9fe81ad4..08cb980d92d 100644 --- a/usr.sbin/relayctl/relayctl.8 +++ b/usr.sbin/relayctl/relayctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: relayctl.8,v 1.19 2007/12/12 14:55:12 jmc Exp $ +.\" $OpenBSD: relayctl.8,v 1.20 2007/12/20 20:15:43 reyk Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 12 2007 $ +.Dd $Mdocdate: December 20 2007 $ .Dt RELAYCTL 8 .Os .Sh NAME @@ -59,7 +59,11 @@ the backup table as well. .It Cm reload Reload the configuration file. .It Cm show hosts -Show detailed status of hosts, tables, and redirections. +Show detailed status of hosts and tables. +.It Cm show redirects +Show detailed status of redirections including the current and average +access statistics. +The statistics will be updated every minute. .It Cm show relays Show detailed status of relays including the current and average access statistics. diff --git a/usr.sbin/relayctl/relayctl.c b/usr.sbin/relayctl/relayctl.c index 59a1fdd1c30..b0a8c5b1c6e 100644 --- a/usr.sbin/relayctl/relayctl.c +++ b/usr.sbin/relayctl/relayctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayctl.c,v 1.30 2007/12/08 20:36:36 pyr Exp $ */ +/* $OpenBSD: relayctl.c,v 1.31 2007/12/20 20:15:43 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -51,6 +51,7 @@ char *print_rdr_status(int); char *print_host_status(int, int); char *print_table_status(int, int); char *print_relay_status(int); +void print_statistics(struct ctl_stats[RELAY_MAXPROC + 1]); struct imsgname { int type; @@ -143,6 +144,7 @@ main(int argc, char *argv[]) /* not reached */ case SHOW_SUM: case SHOW_HOSTS: + case SHOW_RDRS: case SHOW_RELAYS: imsg_compose(ibuf, IMSG_CTL_SHOW_SUM, 0, 0, -1, NULL, 0); printf("%-4s\t%-8s\t%-24s\t%-7s\tStatus\n", @@ -207,6 +209,7 @@ main(int argc, char *argv[]) switch (res->action) { case SHOW_SUM: case SHOW_HOSTS: + case SHOW_RDRS: case SHOW_RELAYS: done = show_summary_msg(&imsg, res->action); break; @@ -310,12 +313,11 @@ show_summary_msg(struct imsg *imsg, int type) struct table *table; struct host *host; struct relay *rlay; - struct ctl_stats stats[RELAY_MAXPROC], crs; - int i; + struct ctl_stats stats[RELAY_MAXPROC]; switch (imsg->hdr.type) { case IMSG_CTL_RDR: - if (type == SHOW_RELAYS) + if (type == SHOW_HOSTS || type == SHOW_RELAYS) break; rdr = imsg->data; printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n", @@ -323,7 +325,7 @@ show_summary_msg(struct imsg *imsg, int type) print_rdr_status(rdr->conf.flags)); break; case IMSG_CTL_TABLE: - if (type == SHOW_RELAYS) + if (type == SHOW_RELAYS || type == SHOW_RDRS) break; table = imsg->data; printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n", @@ -331,7 +333,7 @@ show_summary_msg(struct imsg *imsg, int type) print_table_status(table->up, table->conf.flags)); break; case IMSG_CTL_HOST: - if (type == SHOW_RELAYS) + if (type == SHOW_RELAYS || type == SHOW_RDRS) break; host = imsg->data; printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n", @@ -347,38 +349,25 @@ show_summary_msg(struct imsg *imsg, int type) } break; case IMSG_CTL_RELAY: - if (type == SHOW_HOSTS) + if (type == SHOW_HOSTS || type == SHOW_RDRS) break; rlay = imsg->data; printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n", rlay->conf.id, "relay", rlay->conf.name, "", print_relay_status(rlay->conf.flags)); break; - case IMSG_CTL_STATISTICS: + case IMSG_CTL_RDR_STATS: + if (type != SHOW_RDRS) + break; + bcopy(imsg->data, &stats[0], sizeof(stats[0])); + stats[1].id = EMPTY_ID; + print_statistics(stats); + break; + case IMSG_CTL_RELAY_STATS: if (type != SHOW_RELAYS) break; bcopy(imsg->data, &stats, sizeof(stats)); - bzero(&crs, sizeof(crs)); - crs.interval = stats[0].interval; - for (i = 0; stats[i].id != EMPTY_ID; i++) { - crs.cnt += stats[i].cnt; - crs.last += stats[i].last; - crs.avg += stats[i].avg; - crs.last_hour += stats[i].last_hour; - crs.avg_hour += stats[i].avg_hour; - crs.last_day += stats[i].last_day; - crs.avg_day += stats[i].avg_day; - } - if (crs.cnt == 0) - break; - printf("\t%8s\ttotal: %lu sessions\n" - "\t%8s\tlast: %lu/%us %lu/h %lu/d sessions\n" - "\t%8s\taverage: %lu/%us %lu/h %lu/d sessions\n", - "", crs.cnt, - "", crs.last, crs.interval, - crs.last_hour, crs.last_day, - "", crs.avg, crs.interval, - crs.avg_hour, crs.avg_day); + print_statistics(stats); break; case IMSG_CTL_END: return (1); @@ -497,3 +486,31 @@ print_relay_status(int flags) return ("active"); } +void +print_statistics(struct ctl_stats stats[RELAY_MAXPROC + 1]) +{ + struct ctl_stats crs; + int i; + + bzero(&crs, sizeof(crs)); + crs.interval = stats[0].interval; + for (i = 0; stats[i].id != EMPTY_ID; i++) { + crs.cnt += stats[i].cnt; + crs.last += stats[i].last; + crs.avg += stats[i].avg; + crs.last_hour += stats[i].last_hour; + crs.avg_hour += stats[i].avg_hour; + crs.last_day += stats[i].last_day; + crs.avg_day += stats[i].avg_day; + } + if (crs.cnt == 0) + return; + printf("\t%8s\ttotal: %llu sessions\n" + "\t%8s\tlast: %u/%us %u/h %u/d sessions\n" + "\t%8s\taverage: %u/%us %u/h %u/d sessions\n", + "", crs.cnt, + "", crs.last, crs.interval, + crs.last_hour, crs.last_day, + "", crs.avg, crs.interval, + crs.avg_hour, crs.avg_day); +} |