]> err.no Git - varnish/commitdiff
Added -x option to get XML output. As with the -1 option, it prints it once and quits...
authorpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 25 Feb 2009 07:46:42 +0000 (07:46 +0000)
committerpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 25 Feb 2009 07:46:42 +0000 (07:46 +0000)
<?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: svn+ssh://projects.linpro.no/svn/varnish/trunk@3824 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishstat/varnishstat.c
varnish-cache/bin/varnishstat/varnishstat.xsd [new file with mode: 0644]

index 333abb731be628459e0294ffcfd7c5b9e45daa7a..50b3cd645a802c5bacd28b8446084da13344ad71 100644 (file)
@@ -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
 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 (file)
index 0000000..84b0a6a
--- /dev/null
@@ -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>