From: phk Date: Wed, 28 Jun 2006 11:29:36 +0000 (+0000) Subject: Give varnishstat a "-c" option to use curses to continously refresh X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5079904ff4b4a30b731fecb213c14383ce4a258;p=varnish Give varnishstat a "-c" option to use curses to continously refresh git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@248 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishstat/Makefile.am b/varnish-cache/bin/varnishstat/Makefile.am index 3aa7fe3f..c2302a7c 100644 --- a/varnish-cache/bin/varnishstat/Makefile.am +++ b/varnish-cache/bin/varnishstat/Makefile.am @@ -4,6 +4,7 @@ INCLUDES = -I$(top_srcdir)/include bin_PROGRAMS = varnishstat -varnishlog_SOURCES = varnishstat.c +varnishstat_SOURCES = varnishstat.c +varnishstat_LDADD = -lcurses # varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la diff --git a/varnish-cache/bin/varnishstat/varnishstat.c b/varnish-cache/bin/varnishstat/varnishstat.c index 37b822cf..85bba07f 100644 --- a/varnish-cache/bin/varnishstat/varnishstat.c +++ b/varnish-cache/bin/varnishstat/varnishstat.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -20,9 +21,10 @@ int main(int argc, char **argv) { int fd; - int i; + int i, c; struct shmloghead slh; struct varnish_stats *VSL_stats; + int c_flag = 0; fd = open(SHMLOG_FILENAME, O_RDONLY); if (fd < 0) { @@ -49,13 +51,40 @@ main(int argc, char **argv) SHMLOG_FILENAME, strerror(errno)); exit (1); } - + VSL_stats = &loghead->stats; + while ((c = getopt(argc, argv, "c")) != -1) { + switch (c) { + case 'c': + c_flag = 1; + break; + default: + fprintf(stderr, "Usage: varnishstat [-c]\n"); + exit (2); + } + } + + if (c_flag) { + initscr(); + erase(); + + while (1) { + move(0,0); #define MAC_STAT(n,t,f,d) \ - printf("%12ju " d "\n", (VSL_stats->n)); + printw("%12ju " d "\n", (VSL_stats->n)); #include "stat_field.h" #undef MAC_STAT + refresh(); + sleep(1); + } + } else { + +#define MAC_STAT(n,t,f,d) \ + printf("%12ju " d "\n", (VSL_stats->n)); +#include "stat_field.h" +#undef MAC_STAT + } exit (0);