Commit d8841b80 authored by Petter Knudsen's avatar Petter Knudsen

Added -x option to get XML output. As with the -1 option, it prints it once...

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3824 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 6bcfba5e
...@@ -211,6 +211,31 @@ do_curses(struct varnish_stats *VSL_stats, int delay, const char *fields) ...@@ -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("<?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 static void
do_once(struct varnish_stats *VSL_stats, const char* fields) do_once(struct varnish_stats *VSL_stats, const char* fields)
{ {
...@@ -259,6 +284,8 @@ usage(void) ...@@ -259,6 +284,8 @@ usage(void)
fprintf(stderr, FMT, "-V", "Display the version number and exit"); fprintf(stderr, FMT, "-V", "Display the version number and exit");
fprintf(stderr, FMT, "-w delay", fprintf(stderr, FMT, "-w delay",
"Wait delay seconds between updates. The default is 1."); "Wait delay seconds between updates. The default is 1.");
fprintf(stderr, FMT, "-x",
"Print statistics once as XML and exit.");
#undef FMT #undef FMT
exit(1); exit(1);
} }
...@@ -330,11 +357,11 @@ main(int argc, char **argv) ...@@ -330,11 +357,11 @@ main(int argc, char **argv)
{ {
int c; int c;
struct varnish_stats *VSL_stats; struct varnish_stats *VSL_stats;
int delay = 1, once = 0; int delay = 1, once = 0, xml = 0;
const char *n_arg = NULL; const char *n_arg = NULL;
const char *fields = 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) { switch (c) {
case '1': case '1':
once = 1; once = 1;
...@@ -354,6 +381,9 @@ main(int argc, char **argv) ...@@ -354,6 +381,9 @@ main(int argc, char **argv)
case 'w': case 'w':
delay = atoi(optarg); delay = atoi(optarg);
break; break;
case 'x':
xml = 1;
break;
default: default:
usage(); usage();
} }
...@@ -366,8 +396,10 @@ main(int argc, char **argv) ...@@ -366,8 +396,10 @@ main(int argc, char **argv)
usage(); usage();
exit(1); exit(1);
} }
if (once) if (xml)
do_xml(VSL_stats, fields);
else if (once)
do_once(VSL_stats, fields); do_once(VSL_stats, fields);
else else
do_curses(VSL_stats, delay, fields); do_curses(VSL_stats, delay, fields);
......
<?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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment