From e274d13b135ccbfe8d6abccf69c093313b38bc85 Mon Sep 17 00:00:00 2001 From: petter Date: Wed, 25 Feb 2009 07:46:42 +0000 Subject: [PATCH] Added -x option to get XML output. As with the -1 option, it prints it once and quits, and you can choose what fields to include with the -f option. Example XML output is client_req 2656016 Client requests received varnishstat.xsd contains the XML schema for the output. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3824 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishstat/varnishstat.c | 40 +++++++++++++++++-- varnish-cache/bin/varnishstat/varnishstat.xsd | 19 +++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 varnish-cache/bin/varnishstat/varnishstat.xsd diff --git a/varnish-cache/bin/varnishstat/varnishstat.c b/varnish-cache/bin/varnishstat/varnishstat.c index 333abb73..50b3cd64 100644 --- a/varnish-cache/bin/varnishstat/varnishstat.c +++ b/varnish-cache/bin/varnishstat/varnishstat.c @@ -211,6 +211,31 @@ do_curses(struct varnish_stats *VSL_stats, int delay, const char *fields) } } +static void +do_xml(struct varnish_stats *VSL_stats, const char* fields) +{ + char time_stamp[20]; + time_t now; + + printf("\n"); + now = time(NULL); + strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now)); + printf("\n", time_stamp); +#define MAC_STAT(n, t, l, f, d) \ + do { \ + if (fields != NULL && ! show_field( #n, fields )) break; \ + intmax_t ju = VSL_stats->n; \ + printf("\t\n"); \ + printf("\t\t%s\n", #n); \ + printf("\t\t%ju\n", ju); \ + printf("\t\t%s\n", d); \ + printf("\t\n"); \ + } while (0); +#include "stat_field.h" +#undef MAC_STAT + printf("\n"); +} + static void do_once(struct varnish_stats *VSL_stats, const char* fields) { @@ -259,6 +284,8 @@ usage(void) fprintf(stderr, FMT, "-V", "Display the version number and exit"); fprintf(stderr, FMT, "-w delay", "Wait delay seconds between updates. The default is 1."); + fprintf(stderr, FMT, "-x", + "Print statistics once as XML and exit."); #undef FMT exit(1); } @@ -330,11 +357,11 @@ main(int argc, char **argv) { int c; struct varnish_stats *VSL_stats; - int delay = 1, once = 0; + int delay = 1, once = 0, xml = 0; const char *n_arg = NULL; const char *fields = NULL; - while ((c = getopt(argc, argv, "1f:ln:Vw:")) != -1) { + while ((c = getopt(argc, argv, "1f:ln:Vw:x")) != -1) { switch (c) { case '1': once = 1; @@ -354,6 +381,9 @@ main(int argc, char **argv) case 'w': delay = atoi(optarg); break; + case 'x': + xml = 1; + break; default: usage(); } @@ -366,8 +396,10 @@ main(int argc, char **argv) usage(); exit(1); } - - if (once) + + if (xml) + do_xml(VSL_stats, fields); + else if (once) do_once(VSL_stats, fields); else do_curses(VSL_stats, delay, fields); diff --git a/varnish-cache/bin/varnishstat/varnishstat.xsd b/varnish-cache/bin/varnishstat/varnishstat.xsd new file mode 100644 index 00000000..84b0a6a0 --- /dev/null +++ b/varnish-cache/bin/varnishstat/varnishstat.xsd @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + -- 2.39.5