[master] 1625f9c Reformat JSON output for 80 character width.

Lasse Karstensen lkarsten at varnish-software.com
Mon Jul 6 14:33:08 CEST 2015


commit 1625f9c778165a3e65909f5d4fdc9d9cfb320b6b
Author: Lasse Karstensen <lkarsten at varnish-software.com>
Date:   Mon Jul 6 14:22:46 2015 +0200

    Reformat JSON output for 80 character width.
    
    This output was very wide and hard to get any sense out of without
    actually reading it closely.
    
    The things you are interested in, typically counter name, description
    and value, are now on separate lines.
    
    In addition the output should now fit nicely on any VT100 terminals in
    80 character mode, I'm sure there are some still in use somewhere.
    
    JSON document layout (key names, hierarchy) is the same as before.

diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index cfa819f..871aca7 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -113,22 +113,23 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
 	else
 		printf(",\n");
 
-	printf("\t\"");
+	printf("  \"");
 	/* build the JSON key name.  */
 	if (sec->fantom->type[0])
 		printf("%s.", sec->fantom->type);
 	if (sec->fantom->ident[0])
 		printf("%s.", sec->fantom->ident);
-	printf("%s\": {", pt->desc->name);
+	printf("%s\": {\n", pt->desc->name);
+	printf("    \"description\": \"%s\",\n", pt->desc->sdesc);
+
 	if (strcmp(sec->fantom->type, ""))
-		printf("\"type\": \"%s\", ", sec->fantom->type);
+		printf("    \"type\": \"%s\", ", sec->fantom->type);
 	if (strcmp(sec->fantom->ident, ""))
 		printf("\"ident\": \"%s\", ", sec->fantom->ident);
-	printf("\"value\": %ju, ", (uintmax_t)val);
 	printf("\"flag\": \"%c\", ", pt->desc->semantics);
-	printf("\"format\": \"%c\", ", pt->desc->format);
-	printf("\"description\": \"%s\"", pt->desc->sdesc);
-	printf("}");
+	printf("\"format\": \"%c\",\n", pt->desc->format);
+	printf("    \"value\": %ju", (uintmax_t)val);
+	printf("\n  }");
 
 	if (*jp)
 		printf("\n");
@@ -148,7 +149,7 @@ do_json(struct VSM_data *vd)
 	now = time(NULL);
 
 	(void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now));
-	printf("\t\"timestamp\": \"%s\",\n", time_stamp);
+	printf("  \"timestamp\": \"%s\",\n", time_stamp);
 	(void)VSC_Iter(vd, NULL, do_json_cb, &jp);
 	printf("\n}\n");
 	fflush(stdout);



More information about the varnish-commit mailing list