]> granicus.if.org Git - sysstat/blob - format.c
New output format added to sadf: JSON.
[sysstat] / format.c
1 /*
2  * format.c: Output format definitions for sadf
3  * (C) 2011 by Sebastien GODARD (sysstat <at> orange.fr)
4  *
5  ***************************************************************************
6  * This program is free software; you can redistribute it and/or modify it *
7  * under the terms of the GNU General Public License as published  by  the *
8  * Free Software Foundation; either version 2 of the License, or (at  your *
9  * option) any later version.                                              *
10  *                                                                         *
11  * This program is distributed in the hope that it  will  be  useful,  but *
12  * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
14  * for more details.                                                       *
15  *                                                                         *
16  * You should have received a copy of the GNU General Public License along *
17  * with this program; if not, write to the Free Software Foundation, Inc., *
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                   *
19  ***************************************************************************
20  */
21
22 #include "sadf.h"
23
24 /*
25  ***************************************************************************
26  * Definitions of output formats.
27  * See sadf.h file for format structure definition.
28  ***************************************************************************
29  */
30
31 /*
32  * Display only datafile header.
33  */
34 struct report_format hdr_fmt = {
35         .id             = F_HEADER_OUTPUT,
36         .options        = FO_HEADER_ONLY + FO_BAD_FILE_FORMAT,
37         .f_header       = print_hdr_header,
38         .f_statistics   = NULL,
39         .f_timestamp    = NULL,
40         .f_restart      = NULL,
41         .f_comment      = NULL
42 };
43
44 /*
45  * Database friendly format.
46  */
47 struct report_format db_fmt = {
48         .id             = F_DB_OUTPUT,
49         .options        = FO_GROUPED_STATS + FO_TRUE_TIME + FO_HORIZONTALLY +
50                           FO_SEC_EPOCH + FO_FIELD_LIST,
51         .f_header       = NULL,
52         .f_statistics   = NULL,
53         .f_timestamp    = NULL,
54         .f_restart      = print_db_restart,
55         .f_comment      = print_db_comment
56 };
57
58 /*
59  * Format easily handled by pattern processing commands like awk.
60  */
61 struct report_format ppc_fmt = {
62         .id             = F_PPC_OUTPUT,
63         .options        = FO_GROUPED_STATS + FO_TRUE_TIME + FO_SEC_EPOCH,
64         .f_header       = NULL,
65         .f_statistics   = NULL,
66         .f_timestamp    = NULL,
67         .f_restart      = print_ppc_restart,
68         .f_comment      = print_ppc_comment
69 };
70
71 /*
72  * XML output.
73  */
74 struct report_format xml_fmt = {
75         .id             = F_XML_OUTPUT,
76         .options        = FO_HEADER_ONLY + FO_TRUE_TIME,
77         .f_header       = print_xml_header,
78         .f_statistics   = print_xml_statistics,
79         .f_timestamp    = print_xml_timestamp,
80         .f_restart      = print_xml_restart,
81         .f_comment      = print_xml_comment
82 };
83
84 /*
85  * JSON output.
86  */
87 struct report_format json_fmt = {
88         .id             = F_JSON_OUTPUT,
89         .options        = FO_HEADER_ONLY + FO_TRUE_TIME,
90         .f_header       = print_json_header,
91         .f_statistics   = print_json_statistics,
92         .f_timestamp    = print_json_timestamp,
93         .f_restart      = print_json_restart,
94         .f_comment      = print_json_comment
95 };
96
97 /*
98  * Array of output formats.
99  */
100 struct report_format *fmt[NR_FMT] = {
101         &hdr_fmt,
102         &db_fmt,
103         &ppc_fmt,
104         &xml_fmt,
105         &json_fmt
106 };