Skip to content

Commit

Permalink
New output format added to sadf: JSON.
Browse files Browse the repository at this point in the history
JSON (JavaScript Object Notation) is a lightweight data interchange
format (less verbose than XML). sadf can now display sar's data
in JSON using a new switch (-j).
  • Loading branch information
sysstat committed Nov 11, 2011
1 parent c8be028 commit 7da738b
Show file tree
Hide file tree
Showing 11 changed files with 2,576 additions and 72 deletions.
8 changes: 5 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ act_sadc.o: activity.c sa.h rd_stats.h rd_sensors.h
act_sar.o: activity.c sa.h pr_stats.h
$(CC) -o $@ -c $(CFLAGS) -DSOURCE_SAR $(DFLAGS) $<

act_sadf.o: activity.c sa.h rndr_stats.h xml_stats.h
act_sadf.o: activity.c sa.h rndr_stats.h xml_stats.h json_stats.h
$(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADF $(DFLAGS) $<

rd_stats.o: rd_stats.c common.h rd_stats.h ioconf.h sysconfig.h
Expand All @@ -183,6 +183,8 @@ rndr_stats.o: rndr_stats.c sa.h ioconf.h sysconfig.h rndr_stats.h

xml_stats.o: xml_stats.c sa.h sadf.h ioconf.h sysconfig.h xml_stats.h

json_stats.o: json_stats.c sa.h sadf.h ioconf.h sysconfig.h json_stats.h

sa_wrap.o: sa_wrap.c sa.h rd_stats.h rd_sensors.h

format.o: format.c sadf.h
Expand All @@ -207,9 +209,9 @@ sar.o: sar.c sa.h version.h common.h ioconf.h pr_stats.h sysconfig.h

sar: sar.o act_sar.o sa_common.o pr_stats.o libsyscom.a

sadf.o: sadf.c sadf.h version.h sa.h common.h ioconf.h sysconfig.h rndr_stats.h xml_stats.h
sadf.o: sadf.c sadf.h version.h sa.h common.h ioconf.h sysconfig.h

sadf: sadf.o act_sadf.o format.o sadf_misc.o rndr_stats.o xml_stats.o sa_common.o libsyscom.a
sadf: sadf.o act_sadf.o format.o sadf_misc.o rndr_stats.o xml_stats.o json_stats.o sa_common.o libsyscom.a

iostat.o: iostat.c iostat.h version.h common.h ioconf.h sysconfig.h rd_stats.h

Expand Down
37 changes: 37 additions & 0 deletions activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifdef SOURCE_SADF
#include "rndr_stats.h"
#include "xml_stats.h"
#include "json_stats.h"
#endif

/*
Expand Down Expand Up @@ -83,6 +84,7 @@ struct activity cpu_act = {
#ifdef SOURCE_SADF
.f_render = render_cpu_stats,
.f_xml_print = xml_print_cpu_stats,
.f_json_print = json_print_cpu_stats,
.hdr_line = "CPU;%user;%nice;%system;%iowait;%steal;%idle|"
"CPU;%usr;%nice;%sys;%iowait;%steal;%irq;%soft;%guest;%idle",
.name = "A_CPU",
Expand Down Expand Up @@ -114,6 +116,7 @@ struct activity pcsw_act = {
#ifdef SOURCE_SADF
.f_render = render_pcsw_stats,
.f_xml_print = xml_print_pcsw_stats,
.f_json_print = json_print_pcsw_stats,
.hdr_line = "proc/s;cswch/s",
.name = "A_PCSW",
#endif
Expand Down Expand Up @@ -144,6 +147,7 @@ struct activity irq_act = {
#ifdef SOURCE_SADF
.f_render = render_irq_stats,
.f_xml_print = xml_print_irq_stats,
.f_json_print = json_print_irq_stats,
.hdr_line = "INTR;intr/s",
.name = "A_IRQ",
#endif
Expand Down Expand Up @@ -174,6 +178,7 @@ struct activity swap_act = {
#ifdef SOURCE_SADF
.f_render = render_swap_stats,
.f_xml_print = xml_print_swap_stats,
.f_json_print = json_print_swap_stats,
.hdr_line = "pswpin/s;pswpout/s",
.name = "A_SWAP",
#endif
Expand Down Expand Up @@ -204,6 +209,7 @@ struct activity paging_act = {
#ifdef SOURCE_SADF
.f_render = render_paging_stats,
.f_xml_print = xml_print_paging_stats,
.f_json_print = json_print_paging_stats,
.hdr_line = "pgpgin/s;pgpgout/s;fault/s;majflt/s;"
"pgfree/s;pgscank/s;pgscand/s;pgsteal/s;%vmeff",
.name = "A_PAGE",
Expand Down Expand Up @@ -235,6 +241,7 @@ struct activity io_act = {
#ifdef SOURCE_SADF
.f_render = render_io_stats,
.f_xml_print = xml_print_io_stats,
.f_json_print = json_print_io_stats,
.hdr_line = "tps;rtps;wtps;bread/s;bwrtn/s",
.name = "A_IO",
#endif
Expand Down Expand Up @@ -265,6 +272,7 @@ struct activity memory_act = {
#ifdef SOURCE_SADF
.f_render = render_memory_stats,
.f_xml_print = xml_print_memory_stats,
.f_json_print = json_print_memory_stats,
.hdr_line = "frmpg/s;bufpg/s;campg/s|"
"kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact|"
"kbswpfree;kbswpused;%swpused;kbswpcad;%swpcad",
Expand Down Expand Up @@ -297,6 +305,7 @@ struct activity ktables_act = {
#ifdef SOURCE_SADF
.f_render = render_ktables_stats,
.f_xml_print = xml_print_ktables_stats,
.f_json_print = json_print_ktables_stats,
.hdr_line = "dentunusd;file-nr;inode-nr;pty-nr",
.name = "A_KTABLES",
#endif
Expand Down Expand Up @@ -327,6 +336,7 @@ struct activity queue_act = {
#ifdef SOURCE_SADF
.f_render = render_queue_stats,
.f_xml_print = xml_print_queue_stats,
.f_json_print = json_print_queue_stats,
.hdr_line = "runq-sz;plist-sz;ldavg-1;ldavg-5;ldavg-15;blocked",
.name = "A_QUEUE",
#endif
Expand Down Expand Up @@ -357,6 +367,7 @@ struct activity serial_act = {
#ifdef SOURCE_SADF
.f_render = render_serial_stats,
.f_xml_print = xml_print_serial_stats,
.f_json_print = json_print_serial_stats,
.hdr_line = "TTY;rcvin/s;txmtin/s;framerr/s;prtyerr/s;brk/s;ovrun/s",
.name = "A_SERIAL",
#endif
Expand Down Expand Up @@ -387,6 +398,7 @@ struct activity disk_act = {
#ifdef SOURCE_SADF
.f_render = render_disk_stats,
.f_xml_print = xml_print_disk_stats,
.f_json_print = json_print_disk_stats,
.hdr_line = "DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util",
.name = "A_DISK",
#endif
Expand Down Expand Up @@ -417,6 +429,7 @@ struct activity net_dev_act = {
#ifdef SOURCE_SADF
.f_render = render_net_dev_stats,
.f_xml_print = xml_print_net_dev_stats,
.f_json_print = json_print_net_dev_stats,
.hdr_line = "IFACE;rxpck/s;txpck/s;rxkB/s;txkB/s;rxcmp/s;txcmp/s;rxmcst/s",
.name = "A_NET_DEV",
#endif
Expand Down Expand Up @@ -447,6 +460,7 @@ struct activity net_edev_act = {
#ifdef SOURCE_SADF
.f_render = render_net_edev_stats,
.f_xml_print = xml_print_net_edev_stats,
.f_json_print = json_print_net_edev_stats,
.hdr_line = "IFACE;rxerr/s;txerr/s;coll/s;rxdrop/s;txdrop/s;"
"txcarr/s;rxfram/s;rxfifo/s;txfifo/s",
.name = "A_NET_EDEV",
Expand Down Expand Up @@ -478,6 +492,7 @@ struct activity net_nfs_act = {
#ifdef SOURCE_SADF
.f_render = render_net_nfs_stats,
.f_xml_print = xml_print_net_nfs_stats,
.f_json_print = json_print_net_nfs_stats,
.hdr_line = "call/s;retrans/s;read/s;write/s;access/s;getatt/s",
.name = "A_NET_NFS",
#endif
Expand Down Expand Up @@ -508,6 +523,7 @@ struct activity net_nfsd_act = {
#ifdef SOURCE_SADF
.f_render = render_net_nfsd_stats,
.f_xml_print = xml_print_net_nfsd_stats,
.f_json_print = json_print_net_nfsd_stats,
.hdr_line = "scall/s;badcall/s;packet/s;udp/s;tcp/s;hit/s;miss/s;"
"sread/s;swrite/s;saccess/s;sgetatt/s",
.name = "A_NET_NFSD",
Expand Down Expand Up @@ -539,6 +555,7 @@ struct activity net_sock_act = {
#ifdef SOURCE_SADF
.f_render = render_net_sock_stats,
.f_xml_print = xml_print_net_sock_stats,
.f_json_print = json_print_net_sock_stats,
.hdr_line = "totsck;tcpsck;udpsck;rawsck;ip-frag;tcp-tw",
.name = "A_NET_SOCK",
#endif
Expand Down Expand Up @@ -569,6 +586,7 @@ struct activity net_ip_act = {
#ifdef SOURCE_SADF
.f_render = render_net_ip_stats,
.f_xml_print = xml_print_net_ip_stats,
.f_json_print = json_print_net_ip_stats,
.hdr_line = "irec/s;fwddgm/s;idel/s;orq/s;asmrq/s;asmok/s;fragok/s;fragcrt/s",
.name = "A_NET_IP",
#endif
Expand Down Expand Up @@ -599,6 +617,7 @@ struct activity net_eip_act = {
#ifdef SOURCE_SADF
.f_render = render_net_eip_stats,
.f_xml_print = xml_print_net_eip_stats,
.f_json_print = json_print_net_eip_stats,
.hdr_line = "ihdrerr/s;iadrerr/s;iukwnpr/s;idisc/s;odisc/s;onort/s;asmf/s;fragf/s",
.name = "A_NET_EIP",
#endif
Expand Down Expand Up @@ -629,6 +648,7 @@ struct activity net_icmp_act = {
#ifdef SOURCE_SADF
.f_render = render_net_icmp_stats,
.f_xml_print = xml_print_net_icmp_stats,
.f_json_print = json_print_net_icmp_stats,
.hdr_line = "imsg/s;omsg/s;iech/s;iechr/s;oech/s;oechr/s;itm/s;itmr/s;otm/s;"
"otmr/s;iadrmk/s;iadrmkr/s;oadrmk/s;oadrmkr/s",
.name = "A_NET_ICMP",
Expand Down Expand Up @@ -660,6 +680,7 @@ struct activity net_eicmp_act = {
#ifdef SOURCE_SADF
.f_render = render_net_eicmp_stats,
.f_xml_print = xml_print_net_eicmp_stats,
.f_json_print = json_print_net_eicmp_stats,
.hdr_line = "ierr/s;oerr/s;idstunr/s;odstunr/s;itmex/s;otmex/s;"
"iparmpb/s;oparmpb/s;isrcq/s;osrcq/s;iredir/s;oredir/s",
.name = "A_NET_EICMP",
Expand Down Expand Up @@ -691,6 +712,7 @@ struct activity net_tcp_act = {
#ifdef SOURCE_SADF
.f_render = render_net_tcp_stats,
.f_xml_print = xml_print_net_tcp_stats,
.f_json_print = json_print_net_tcp_stats,
.hdr_line = "active/s;passive/s;iseg/s;oseg/s",
.name = "A_NET_TCP",
#endif
Expand Down Expand Up @@ -721,6 +743,7 @@ struct activity net_etcp_act = {
#ifdef SOURCE_SADF
.f_render = render_net_etcp_stats,
.f_xml_print = xml_print_net_etcp_stats,
.f_json_print = json_print_net_etcp_stats,
.hdr_line = "atmptf/s;estres/s;retrans/s;isegerr/s;orsts/s",
.name = "A_NET_ETCP",
#endif
Expand Down Expand Up @@ -751,6 +774,7 @@ struct activity net_udp_act = {
#ifdef SOURCE_SADF
.f_render = render_net_udp_stats,
.f_xml_print = xml_print_net_udp_stats,
.f_json_print = json_print_net_udp_stats,
.hdr_line = "idgm/s;odgm/s;noport/s;idgmerr/s",
.name = "A_NET_UDP",
#endif
Expand Down Expand Up @@ -781,6 +805,7 @@ struct activity net_sock6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_sock6_stats,
.f_xml_print = xml_print_net_sock6_stats,
.f_json_print = json_print_net_sock6_stats,
.hdr_line = "tcp6sck;udp6sck;raw6sck;ip6-frag",
.name = "A_NET_SOCK6",
#endif
Expand Down Expand Up @@ -811,6 +836,7 @@ struct activity net_ip6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_ip6_stats,
.f_xml_print = xml_print_net_ip6_stats,
.f_json_print = json_print_net_ip6_stats,
.hdr_line = "irec6/s;fwddgm6/s;idel6/s;orq6/s;asmrq6/s;asmok6/s;"
"imcpck6/s;omcpck6/s;fragok6/s;fragcr6/s",
.name = "A_NET_IP6",
Expand Down Expand Up @@ -842,6 +868,7 @@ struct activity net_eip6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_eip6_stats,
.f_xml_print = xml_print_net_eip6_stats,
.f_json_print = json_print_net_eip6_stats,
.hdr_line = "ihdrer6/s;iadrer6/s;iukwnp6/s;i2big6/s;idisc6/s;odisc6/s;"
"inort6/s;onort6/s;asmf6/s;fragf6/s;itrpck6/s",
.name = "A_NET_EIP6",
Expand Down Expand Up @@ -873,6 +900,7 @@ struct activity net_icmp6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_icmp6_stats,
.f_xml_print = xml_print_net_icmp6_stats,
.f_json_print = json_print_net_icmp6_stats,
.hdr_line = "imsg6/s;omsg6/s;iech6/s;iechr6/s;oechr6/s;igmbq6/s;igmbr6/s;ogmbr6/s;"
"igmbrd6/s;ogmbrd6/s;irtsol6/s;ortsol6/s;irtad6/s;inbsol6/s;onbsol6/s;"
"inbad6/s;onbad6/s",
Expand Down Expand Up @@ -905,6 +933,7 @@ struct activity net_eicmp6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_eicmp6_stats,
.f_xml_print = xml_print_net_eicmp6_stats,
.f_json_print = json_print_net_eicmp6_stats,
.hdr_line = "ierr6/s;idtunr6/s;odtunr6/s;itmex6/s;otmex6/s;"
"iprmpb6/s;oprmpb6/s;iredir6/s;oredir6/s;ipck2b6/s;opck2b6/s",
.name = "A_NET_EICMP6",
Expand Down Expand Up @@ -936,6 +965,7 @@ struct activity net_udp6_act = {
#ifdef SOURCE_SADF
.f_render = render_net_udp6_stats,
.f_xml_print = xml_print_net_udp6_stats,
.f_json_print = json_print_net_udp6_stats,
.hdr_line = "idgm6/s;odgm6/s;noport6/s;idgmer6/s",
.name = "A_NET_UDP6",
#endif
Expand Down Expand Up @@ -966,6 +996,7 @@ struct activity pwr_cpufreq_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_cpufreq_stats,
.f_xml_print = xml_print_pwr_cpufreq_stats,
.f_json_print = json_print_pwr_cpufreq_stats,
.hdr_line = "CPU;MHz",
.name = "A_PWR_CPUFREQ",
#endif
Expand Down Expand Up @@ -996,6 +1027,7 @@ struct activity pwr_fan_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_fan_stats,
.f_xml_print = xml_print_pwr_fan_stats,
.f_json_print = json_print_pwr_fan_stats,
.hdr_line = "FAN;DEVICE;rpm;drpm",
.name = "A_PWR_FAN",
#endif
Expand Down Expand Up @@ -1026,6 +1058,7 @@ struct activity pwr_temp_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_temp_stats,
.f_xml_print = xml_print_pwr_temp_stats,
.f_json_print = json_print_pwr_temp_stats,
.hdr_line = "TEMP;DEVICE;degC;%temp",
.name = "A_PWR_TEMP",
#endif
Expand Down Expand Up @@ -1056,6 +1089,7 @@ struct activity pwr_in_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_in_stats,
.f_xml_print = xml_print_pwr_in_stats,
.f_json_print = json_print_pwr_in_stats,
.hdr_line = "IN;DEVICE;inV;%in",
.name = "A_PWR_IN",
#endif
Expand Down Expand Up @@ -1086,6 +1120,7 @@ struct activity huge_act = {
#ifdef SOURCE_SADF
.f_render = render_huge_stats,
.f_xml_print = xml_print_huge_stats,
.f_json_print = json_print_huge_stats,
.hdr_line = "kbhugfree;kbhugused;%hugused",
.name = "A_HUGE",
#endif
Expand Down Expand Up @@ -1116,6 +1151,7 @@ struct activity pwr_wghfreq_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_wghfreq_stats,
.f_xml_print = xml_print_pwr_wghfreq_stats,
.f_json_print = json_print_pwr_wghfreq_stats,
.hdr_line = "CPU;wghMHz",
.name = "A_PWR_WGHFREQ",
#endif
Expand Down Expand Up @@ -1146,6 +1182,7 @@ struct activity pwr_usb_act = {
#ifdef SOURCE_SADF
.f_render = render_pwr_usb_stats,
.f_xml_print = xml_print_pwr_usb_stats,
.f_json_print = json_print_pwr_usb_stats,
.hdr_line = "manufact;product;BUS;idvendor;idprod;maxpower",
.name = "A_PWR_USB",
#endif
Expand Down
16 changes: 15 additions & 1 deletion format.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,26 @@ struct report_format xml_fmt = {
.f_comment = print_xml_comment
};

/*
* JSON output.
*/
struct report_format json_fmt = {
.id = F_JSON_OUTPUT,
.options = FO_HEADER_ONLY + FO_TRUE_TIME,
.f_header = print_json_header,
.f_statistics = print_json_statistics,
.f_timestamp = print_json_timestamp,
.f_restart = print_json_restart,
.f_comment = print_json_comment
};

/*
* Array of output formats.
*/
struct report_format *fmt[NR_FMT] = {
&hdr_fmt,
&db_fmt,
&ppc_fmt,
&xml_fmt
&xml_fmt,
&json_fmt
};

0 comments on commit 7da738b

Please sign in to comment.