]> err.no Git - varnish/commitdiff
Give varnishstat a "-c" option to use curses to continously refresh
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 11:29:36 +0000 (11:29 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 11:29:36 +0000 (11:29 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@248 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishstat/Makefile.am
varnish-cache/bin/varnishstat/varnishstat.c

index 3aa7fe3fe45aba6341ebfcdbde3101c7bfb3f0c9..c2302a7c039482a31e1a53d59bf85ab9337c2259 100644 (file)
@@ -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 
index 37b822cf2a10bb36cc78349f36cb1fe3b0456ed6..85bba07f90b6ca8da1788a1d2fe948cc09f66d24 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <curses.h>
 #include <sys/mman.h>
 
 #include <shmlog.h>
@@ -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);