From 3e930d0dcc14c3de5f778b68f38cee557b15e698 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 28 Jun 2006 11:21:06 +0000 Subject: [PATCH] Add varnishstat program git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@247 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/Makefile.am | 2 +- varnish-cache/bin/varnishstat/Makefile.am | 9 +++ varnish-cache/bin/varnishstat/varnishstat.c | 62 +++++++++++++++++++++ varnish-cache/configure.ac | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 varnish-cache/bin/varnishstat/Makefile.am create mode 100644 varnish-cache/bin/varnishstat/varnishstat.c diff --git a/varnish-cache/bin/Makefile.am b/varnish-cache/bin/Makefile.am index 267714fe..375fed56 100644 --- a/varnish-cache/bin/Makefile.am +++ b/varnish-cache/bin/Makefile.am @@ -1,3 +1,3 @@ # $Id$ -SUBDIRS = varnishd varnishlog +SUBDIRS = varnishd varnishlog varnishstat diff --git a/varnish-cache/bin/varnishstat/Makefile.am b/varnish-cache/bin/varnishstat/Makefile.am new file mode 100644 index 00000000..3aa7fe3f --- /dev/null +++ b/varnish-cache/bin/varnishstat/Makefile.am @@ -0,0 +1,9 @@ +# $Id: Makefile.am 133 2006-04-06 09:38:00Z phk $ + +INCLUDES = -I$(top_srcdir)/include + +bin_PROGRAMS = varnishstat + +varnishlog_SOURCES = varnishstat.c + +# varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la diff --git a/varnish-cache/bin/varnishstat/varnishstat.c b/varnish-cache/bin/varnishstat/varnishstat.c new file mode 100644 index 00000000..37b822cf --- /dev/null +++ b/varnish-cache/bin/varnishstat/varnishstat.c @@ -0,0 +1,62 @@ +/* + * $Id: varnishlog.c 153 2006-04-25 08:17:43Z phk $ + * + * Log tailer for Varnish + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +static struct shmloghead *loghead; + +int +main(int argc, char **argv) +{ + int fd; + int i; + struct shmloghead slh; + struct varnish_stats *VSL_stats; + + fd = open(SHMLOG_FILENAME, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Cannot open %s: %s\n", + SHMLOG_FILENAME, strerror(errno)); + exit (1); + } + i = read(fd, &slh, sizeof slh); + if (i != sizeof slh) { + fprintf(stderr, "Cannot read %s: %s\n", + SHMLOG_FILENAME, strerror(errno)); + exit (1); + } + if (slh.magic != SHMLOGHEAD_MAGIC) { + fprintf(stderr, "Wrong magic number in file %s\n", + SHMLOG_FILENAME); + exit (1); + } + + loghead = mmap(NULL, slh.size + sizeof slh, + PROT_READ, MAP_HASSEMAPHORE, fd, 0); + if (loghead == MAP_FAILED) { + fprintf(stderr, "Cannot mmap %s: %s\n", + SHMLOG_FILENAME, strerror(errno)); + exit (1); + } + + VSL_stats = &loghead->stats; + +#define MAC_STAT(n,t,f,d) \ + printf("%12ju " d "\n", (VSL_stats->n)); +#include "stat_field.h" +#undef MAC_STAT + + exit (0); + +} diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index bf4f81c8..1113ff4c 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -68,6 +68,7 @@ AC_CONFIG_FILES([ bin/Makefile bin/varnishd/Makefile bin/varnishlog/Makefile + bin/varnishstat/Makefile contrib/Makefile include/Makefile lib/Makefile -- 2.39.5