r248 - trunk/varnish-cache/bin/varnishstat

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 28 13:29:36 CEST 2006


Author: phk
Date: 2006-06-28 13:29:36 +0200 (Wed, 28 Jun 2006)
New Revision: 248

Modified:
   trunk/varnish-cache/bin/varnishstat/Makefile.am
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
Log:
Give varnishstat a "-c" option to use curses to continously refresh


Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishstat/Makefile.am	2006-06-28 11:21:06 UTC (rev 247)
+++ trunk/varnish-cache/bin/varnishstat/Makefile.am	2006-06-28 11:29:36 UTC (rev 248)
@@ -4,6 +4,7 @@
 
 bin_PROGRAMS = varnishstat
 
-varnishlog_SOURCES = varnishstat.c
+varnishstat_SOURCES = varnishstat.c
 
+varnishstat_LDADD = -lcurses
 # varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la 

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-06-28 11:21:06 UTC (rev 247)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-06-28 11:29:36 UTC (rev 248)
@@ -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 @@
 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,14 +51,41 @@
 		    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);
 
 }




More information about the varnish-commit mailing list