Blame SOURCES/0005-Filesystems-statistics-part-5-JSON-output-format.patch

72abff
From 653c316533bbadd6e5f75abb69b3953dd43232d9 Mon Sep 17 00:00:00 2001
72abff
From: Sebastien GODARD <sysstat@orange.fr.fake>
72abff
Date: Sun, 12 May 2013 16:07:55 +0200
72abff
Subject: [PATCH] Filesystems statistics (part 5): JSON output format
72abff
72abff
This patch adds JSON output format for filesystems statistics. This
72abff
format can be displayed with sadf option -j.
72abff
72abff
(cherry picked from commit 9a5447d081141289de2736f7f31f25b3b340ace9)
72abff
---
72abff
 json_stats.c | 42 +++++++++++++++++++++++++++++++++++++++++-
72abff
 1 file changed, 41 insertions(+), 1 deletion(-)
72abff
72abff
diff --git a/json_stats.c b/json_stats.c
72abff
index 10d88e9..a5b4dcd 100644
72abff
--- a/json_stats.c
72abff
+++ b/json_stats.c
72abff
@@ -2100,5 +2100,45 @@ close_json_markup:
72abff
 __print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
72abff
 					    unsigned long long itv)
72abff
 {
72abff
-	/* FIXME */
72abff
+	int i;
72abff
+	struct stats_filesystem *sfc;
72abff
+	int sep = FALSE;
72abff
+
72abff
+	xprintf(tab++, "\"filesystems\": [");
72abff
+
72abff
+	for (i = 0; i < a->nr; i++) {
72abff
+		sfc = (struct stats_filesystem *) ((char *) a->buf[curr]  + i * a->msize);
72abff
+
72abff
+		if (!sfc->f_blocks)
72abff
+			/* Size of filesystem is null: We are at the end of the list */
72abff
+			break;
72abff
+
72abff
+		if (sep) {
72abff
+			printf(",\n");
72abff
+		}
72abff
+		sep = TRUE;
72abff
+		
72abff
+		xprintf0(tab, "{\"filesystem\": \"%s\", "
72abff
+			 "\"MBfsfree\": %.0f, "
72abff
+			 "\"MBfsused\": %.0f, "
72abff
+			 "\"%%fsused\": %.2f, "
72abff
+			 "\"%%ufsused\": %.2f, "
72abff
+			 "\"Ifree\": %llu, "
72abff
+			 "\"Iused\": %llu, "
72abff
+			 "\"%%Iused\": %.2f}",
72abff
+			 sfc->fs_name,
72abff
+			 (double) sfc->f_bfree / 1024 / 1024,
72abff
+			 (double) (sfc->f_blocks - sfc->f_bfree) / 1024 / 1024,
72abff
+			 sfc->f_blocks ? SP_VALUE(sfc->f_bfree, sfc->f_blocks, sfc->f_blocks)
72abff
+				     : 0.0,
72abff
+			 sfc->f_blocks ? SP_VALUE(sfc->f_bavail, sfc->f_blocks, sfc->f_blocks)
72abff
+				     : 0.0,
72abff
+			 sfc->f_ffree,
72abff
+			 sfc->f_files - sfc->f_ffree,
72abff
+			 sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files)
72abff
+				    : 0.0);
72abff
+	}
72abff
+
72abff
+	printf("\n");
72abff
+	xprintf0(--tab, "]");
72abff
 }
72abff
-- 
72abff
2.14.3
72abff