r3824 - trunk/varnish-cache/bin/varnishstat
petter at projects.linpro.no
petter at projects.linpro.no
Wed Feb 25 08:46:42 CET 2009
Author: petter
Date: 2009-02-25 08:46:42 +0100 (Wed, 25 Feb 2009)
New Revision: 3824
Added:
trunk/varnish-cache/bin/varnishstat/varnishstat.xsd
Modified:
trunk/varnish-cache/bin/varnishstat/varnishstat.c
Log:
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
<?xml version="1.0"?>
<varnishstat timestamp="2009-02-25T08:45:02">
<stat>
<name>client_req</name>
<value>2656016</value>
<description>Client requests received</description>
</stat>
</varnishstat>
varnishstat.xsd contains the XML schema for the output.
Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-24 12:00:05 UTC (rev 3823)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-25 07:46:42 UTC (rev 3824)
@@ -212,6 +212,31 @@
}
static void
+do_xml(struct varnish_stats *VSL_stats, const char* fields)
+{
+ char time_stamp[20];
+ time_t now;
+
+ printf("<?xml version=\"1.0\"?>\n");
+ now = time(NULL);
+ strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now));
+ printf("<varnishstat timestamp=\"%s\">\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<stat>\n"); \
+ printf("\t\t<name>%s</name>\n", #n); \
+ printf("\t\t<value>%ju</value>\n", ju); \
+ printf("\t\t<description>%s</description>\n", d); \
+ printf("\t</stat>\n"); \
+ } while (0);
+#include "stat_field.h"
+#undef MAC_STAT
+ printf("</varnishstat>\n");
+}
+
+static void
do_once(struct varnish_stats *VSL_stats, const char* fields)
{
struct timeval tv;
@@ -259,6 +284,8 @@
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 @@
{
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 @@
case 'w':
delay = atoi(optarg);
break;
+ case 'x':
+ xml = 1;
+ break;
default:
usage();
}
@@ -366,8 +396,10 @@
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);
Added: trunk/varnish-cache/bin/varnishstat/varnishstat.xsd
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.xsd (rev 0)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.xsd 2009-02-25 07:46:42 UTC (rev 3824)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="varnishstat">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="stat" maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="name" type="xs:string"/>
+ <xs:element name="value" type="xs:integer"/>
+ <xs:element name="description" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="timestamp" type="xs:dateTime"/>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
More information about the varnish-commit
mailing list