2 * json_stats.c: Funtions used by sadf to display statistics in JSON format.
3 * (C) 1999-2016 by Sebastien GODARD (sysstat <at> orange.fr)
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. *
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 *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *
19 ***************************************************************************
29 #include "json_stats.h"
34 #define _(string) gettext(string)
36 #define _(string) (string)
39 extern unsigned int flags;
40 extern unsigned int dm_major;
43 ***************************************************************************
44 * Open or close "network" markup.
47 * @tab Number of tabulations.
48 * @action Open or close action.
49 ***************************************************************************
51 void json_markup_network(int tab, int action)
53 static int markup_state = CLOSE_JSON_MARKUP;
55 if (action == markup_state)
57 markup_state = action;
59 if (action == OPEN_JSON_MARKUP) {
61 xprintf(tab, "\"network\": {");
71 ***************************************************************************
72 * Open or close "power-management" markup.
75 * @tab Number of tabulations.
76 * @action Open or close action.
77 ***************************************************************************
79 void json_markup_power_management(int tab, int action)
81 static int markup_state = CLOSE_JSON_MARKUP;
83 if (action == markup_state)
85 markup_state = action;
87 if (action == OPEN_JSON_MARKUP) {
89 xprintf(tab, "\"power-management\": {");
99 ***************************************************************************
100 * Display CPU statistics in JSON.
103 * @a Activity structure with statistics.
104 * @curr Index in array for current sample statistics.
105 * @tab Indentation in output.
106 * @g_itv Interval of time in jiffies mutliplied by the number of
108 ***************************************************************************
110 __print_funct_t json_print_cpu_stats(struct activity *a, int curr, int tab,
111 unsigned long long g_itv)
115 struct stats_cpu *scc, *scp;
118 xprintf(tab++, "\"cpu-load\": [");
120 for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
122 scc = (struct stats_cpu *) ((char *) a->buf[curr] + i * a->msize);
123 scp = (struct stats_cpu *) ((char *) a->buf[!curr] + i * a->msize);
125 /* Should current CPU (including CPU "all") be displayed? */
126 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))))
130 /* Yes: Display current CPU stats */
138 /* This is CPU "all" */
139 strcpy(cpuno, "all");
142 sprintf(cpuno, "%d", i - 1);
145 * If the CPU is offline then it is omited from /proc/stat:
146 * All the fields couldn't have been read and the sum of them is zero.
147 * (Remember that guest/guest_nice times are already included in
150 if ((scc->cpu_user + scc->cpu_nice + scc->cpu_sys +
151 scc->cpu_iowait + scc->cpu_idle + scc->cpu_steal +
152 scc->cpu_hardirq + scc->cpu_softirq) == 0) {
154 * Set current struct fields (which have been set to zero)
155 * to values from previous iteration. Hence their values won't
156 * jump from zero when the CPU comes back online.
165 * Recalculate interval for current proc.
166 * If result is 0 then current CPU is a tickless one.
168 g_itv = get_per_cpu_interval(scc, scp);
173 /* Current CPU is offline or tickless */
174 if (DISPLAY_CPU_DEF(a->opt_flags)) {
175 xprintf0(tab, "{\"cpu\": \"%d\", "
182 i - 1, 0.0, 0.0, 0.0, 0.0, 0.0,
183 cpu_offline ? 0.0 : 100.0);
185 else if (DISPLAY_CPU_ALL(a->opt_flags)) {
186 xprintf0(tab, "{\"cpu\": \"%d\", "
197 i - 1, 0.0, 0.0, 0.0, 0.0,
198 0.0, 0.0, 0.0, 0.0, 0.0,
199 cpu_offline ? 0.0 : 100.0);
205 if (DISPLAY_CPU_DEF(a->opt_flags)) {
206 xprintf0(tab, "{\"cpu\": \"%s\", "
214 ll_sp_value(scp->cpu_user, scc->cpu_user, g_itv),
215 ll_sp_value(scp->cpu_nice, scc->cpu_nice, g_itv),
216 ll_sp_value(scp->cpu_sys + scp->cpu_hardirq + scp->cpu_softirq,
217 scc->cpu_sys + scc->cpu_hardirq + scc->cpu_softirq,
219 ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
220 ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
221 scc->cpu_idle < scp->cpu_idle ?
223 ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
225 else if (DISPLAY_CPU_ALL(a->opt_flags)) {
226 xprintf0(tab, "{\"cpu\": \"%s\", "
238 (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
240 ll_sp_value(scp->cpu_user - scp->cpu_guest,
241 scc->cpu_user - scc->cpu_guest, g_itv),
242 (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
244 ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
245 scc->cpu_nice - scc->cpu_guest_nice, g_itv),
246 ll_sp_value(scp->cpu_sys, scc->cpu_sys, g_itv),
247 ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, g_itv),
248 ll_sp_value(scp->cpu_steal, scc->cpu_steal, g_itv),
249 ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, g_itv),
250 ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, g_itv),
251 ll_sp_value(scp->cpu_guest, scc->cpu_guest, g_itv),
252 ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, g_itv),
253 scc->cpu_idle < scp->cpu_idle ?
255 ll_sp_value(scp->cpu_idle, scc->cpu_idle, g_itv));
260 xprintf0(--tab, "]");
264 ***************************************************************************
265 * Display task creation and context switch statistics in JSON.
268 * @a Activity structure with statistics.
269 * @curr Index in array for current sample statistics.
270 * @tab Indentation in output.
271 * @itv Interval of time in jiffies.
272 ***************************************************************************
274 __print_funct_t json_print_pcsw_stats(struct activity *a, int curr, int tab,
275 unsigned long long itv)
278 *spc = (struct stats_pcsw *) a->buf[curr],
279 *spp = (struct stats_pcsw *) a->buf[!curr];
281 /* proc/s and cswch/s */
282 xprintf0(tab, "\"process-and-context-switch\": {"
285 S_VALUE(spp->processes, spc->processes, itv),
286 S_VALUE(spp->context_switch, spc->context_switch, itv));
290 ***************************************************************************
291 * Display interrupts statistics in JSON.
294 * @a Activity structure with statistics.
295 * @curr Index in array for current sample statistics.
296 * @tab Indentation in output.
297 * @itv Interval of time in jiffies.
298 ***************************************************************************
300 __print_funct_t json_print_irq_stats(struct activity *a, int curr, int tab,
301 unsigned long long itv)
304 struct stats_irq *sic, *sip;
308 xprintf(tab++, "\"interrupts\": [");
310 for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
312 sic = (struct stats_irq *) ((char *) a->buf[curr] + i * a->msize);
313 sip = (struct stats_irq *) ((char *) a->buf[!curr] + i * a->msize);
315 /* Should current interrupt (including int "sum") be displayed? */
316 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
318 /* Yes: Display it */
326 /* This is interrupt "sum" */
327 strcpy(irqno, "sum");
330 sprintf(irqno, "%d", i - 1);
333 xprintf0(tab, "{\"intr\": \"%s\", "
336 S_VALUE(sip->irq_nr, sic->irq_nr, itv));
341 xprintf0(--tab, "]");
345 ***************************************************************************
346 * Display swapping statistics in JSON.
349 * @a Activity structure with statistics.
350 * @curr Index in array for current sample statistics.
351 * @tab Indentation in output.
352 * @itv Interval of time in jiffies.
353 ***************************************************************************
355 __print_funct_t json_print_swap_stats(struct activity *a, int curr, int tab,
356 unsigned long long itv)
359 *ssc = (struct stats_swap *) a->buf[curr],
360 *ssp = (struct stats_swap *) a->buf[!curr];
362 xprintf0(tab, "\"swap-pages\": {"
364 "\"pswpout\": %.2f}",
365 S_VALUE(ssp->pswpin, ssc->pswpin, itv),
366 S_VALUE(ssp->pswpout, ssc->pswpout, itv));
370 ***************************************************************************
371 * Display paging statistics in JSON.
374 * @a Activity structure with statistics.
375 * @curr Index in array for current sample statistics.
376 * @tab Indentation in output.
377 * @itv Interval of time in jiffies.
378 ***************************************************************************
380 __print_funct_t json_print_paging_stats(struct activity *a, int curr, int tab,
381 unsigned long long itv)
384 *spc = (struct stats_paging *) a->buf[curr],
385 *spp = (struct stats_paging *) a->buf[!curr];
387 xprintf0(tab, "\"paging\": {"
389 "\"pgpgout\": %.2f, "
393 "\"pgscank\": %.2f, "
394 "\"pgscand\": %.2f, "
395 "\"pgsteal\": %.2f, "
396 "\"vmeff-percent\": %.2f}",
397 S_VALUE(spp->pgpgin, spc->pgpgin, itv),
398 S_VALUE(spp->pgpgout, spc->pgpgout, itv),
399 S_VALUE(spp->pgfault, spc->pgfault, itv),
400 S_VALUE(spp->pgmajfault, spc->pgmajfault, itv),
401 S_VALUE(spp->pgfree, spc->pgfree, itv),
402 S_VALUE(spp->pgscan_kswapd, spc->pgscan_kswapd, itv),
403 S_VALUE(spp->pgscan_direct, spc->pgscan_direct, itv),
404 S_VALUE(spp->pgsteal, spc->pgsteal, itv),
405 (spc->pgscan_kswapd + spc->pgscan_direct -
406 spp->pgscan_kswapd - spp->pgscan_direct) ?
407 SP_VALUE(spp->pgsteal, spc->pgsteal,
408 spc->pgscan_kswapd + spc->pgscan_direct -
409 spp->pgscan_kswapd - spp->pgscan_direct) : 0.0);
413 ***************************************************************************
414 * Display I/O and transfer rate statistics in JSON.
417 * @a Activity structure with statistics.
418 * @curr Index in array for current sample statistics.
419 * @tab Indentation in output.
420 * @itv Interval of time in jiffies.
421 ***************************************************************************
423 __print_funct_t json_print_io_stats(struct activity *a, int curr, int tab,
424 unsigned long long itv)
427 *sic = (struct stats_io *) a->buf[curr],
428 *sip = (struct stats_io *) a->buf[!curr];
430 xprintf0(tab, "\"io\": {"
438 S_VALUE(sip->dk_drive, sic->dk_drive, itv),
439 S_VALUE(sip->dk_drive_rio, sic->dk_drive_rio, itv),
440 S_VALUE(sip->dk_drive_rblk, sic->dk_drive_rblk, itv),
441 S_VALUE(sip->dk_drive_wio, sic->dk_drive_wio, itv),
442 S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv));
446 ***************************************************************************
447 * Display memory statistics in JSON.
450 * @a Activity structure with statistics.
451 * @curr Index in array for current sample statistics.
452 * @tab Indentation in output.
453 * @itv Interval of time in jiffies.
454 ***************************************************************************
456 __print_funct_t json_print_memory_stats(struct activity *a, int curr, int tab,
457 unsigned long long itv)
460 *smc = (struct stats_memory *) a->buf[curr],
461 *smp = (struct stats_memory *) a->buf[!curr];
464 xprintf0(tab, "\"memory\": {");
466 if (DISPLAY_MEM_AMT(a->opt_flags)) {
470 printf("\"memfree\": %lu, "
472 "\"memused-percent\": %.2f, "
476 "\"commit-percent\": %.2f, "
478 "\"inactive\": %lu, "
481 smc->tlmkb - smc->frmkb,
483 SP_VALUE(smc->frmkb, smc->tlmkb, smc->tlmkb) :
488 (smc->tlmkb + smc->tlskb) ?
489 SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) :
495 if (DISPLAY_MEM_ALL(a->opt_flags)) {
496 /* Display extended memory stats */
497 printf(", \"anonpg\": %lu, "
510 if (DISPLAY_SWAP(a->opt_flags)) {
517 printf("\"swpfree\": %lu, "
519 "\"swpused-percent\": %.2f, "
521 "\"swpcad-percent\": %.2f",
523 smc->tlskb - smc->frskb,
525 SP_VALUE(smc->frskb, smc->tlskb, smc->tlskb) :
528 (smc->tlskb - smc->frskb) ?
529 SP_VALUE(0, smc->caskb, smc->tlskb - smc->frskb) :
533 if (DISPLAY_MEMORY(a->opt_flags)) {
539 printf("\"frmpg\": %.2f, "
542 S_VALUE((double) KB_TO_PG(smp->frmkb),
543 (double) KB_TO_PG(smc->frmkb), itv),
544 S_VALUE((double) KB_TO_PG(smp->bufkb),
545 (double) KB_TO_PG(smc->bufkb), itv),
546 S_VALUE((double) KB_TO_PG(smp->camkb),
547 (double) KB_TO_PG(smc->camkb), itv));
554 ***************************************************************************
555 * Display kernel tables statistics in JSON.
558 * @a Activity structure with statistics.
559 * @curr Index in array for current sample statistics.
560 * @tab Indentation in output.
561 * @itv Interval of time in jiffies.
562 ***************************************************************************
564 __print_funct_t json_print_ktables_stats(struct activity *a, int curr, int tab,
565 unsigned long long itv)
568 *skc = (struct stats_ktables *) a->buf[curr];
570 xprintf0(tab, "\"kernel\": {"
571 "\"dentunusd\": %u, "
582 ***************************************************************************
583 * Display queue and load statistics in JSON.
586 * @a Activity structure with statistics.
587 * @curr Index in array for current sample statistics.
588 * @tab Indentation in output.
589 * @itv Interval of time in jiffies.
590 ***************************************************************************
592 __print_funct_t json_print_queue_stats(struct activity *a, int curr, int tab,
593 unsigned long long itv)
596 *sqc = (struct stats_queue *) a->buf[curr];
598 xprintf0(tab, "\"queue\": {"
601 "\"ldavg-1\": %.2f, "
602 "\"ldavg-5\": %.2f, "
603 "\"ldavg-15\": %.2f, "
607 (double) sqc->load_avg_1 / 100,
608 (double) sqc->load_avg_5 / 100,
609 (double) sqc->load_avg_15 / 100,
614 ***************************************************************************
615 * Display serial lines statistics in JSON.
618 * @a Activity structure with statistics.
619 * @curr Index in array for current sample statistics.
620 * @tab Indentation in output.
621 * @itv Interval of time in jiffies.
622 ***************************************************************************
624 __print_funct_t json_print_serial_stats(struct activity *a, int curr, int tab,
625 unsigned long long itv)
628 struct stats_serial *ssc, *ssp;
631 xprintf(tab++, "\"serial\": [");
633 for (i = 0; i < a->nr; i++) {
635 ssc = (struct stats_serial *) ((char *) a->buf[curr] + i * a->msize);
636 ssp = (struct stats_serial *) ((char *) a->buf[!curr] + i * a->msize);
641 if (ssc->line == ssp->line) {
648 xprintf0(tab, "{\"line\": %d, "
651 "\"framerr\": %.2f, "
652 "\"prtyerr\": %.2f, "
656 S_VALUE(ssp->rx, ssc->rx, itv),
657 S_VALUE(ssp->tx, ssc->tx, itv),
658 S_VALUE(ssp->frame, ssc->frame, itv),
659 S_VALUE(ssp->parity, ssc->parity, itv),
660 S_VALUE(ssp->brk, ssc->brk, itv),
661 S_VALUE(ssp->overrun, ssc->overrun, itv));
666 xprintf0(--tab, "]");
670 ***************************************************************************
671 * Display disks statistics in JSON.
674 * @a Activity structure with statistics.
675 * @curr Index in array for current sample statistics.
676 * @tab Indentation in output.
677 * @itv Interval of time in jiffies.
678 ***************************************************************************
680 __print_funct_t json_print_disk_stats(struct activity *a, int curr, int tab,
681 unsigned long long itv)
684 struct stats_disk *sdc, *sdp;
685 struct ext_disk_stats xds;
687 char *dev_name, *persist_dev_name;
689 xprintf(tab++, "\"disk\": [");
691 for (i = 0; i < a->nr; i++) {
693 sdc = (struct stats_disk *) ((char *) a->buf[curr] + i * a->msize);
695 if (!(sdc->major + sdc->minor))
698 j = check_disk_reg(a, curr, !curr, i);
699 sdp = (struct stats_disk *) ((char *) a->buf[!curr] + j * a->msize);
701 /* Compute extended statistics values */
702 compute_ext_disk_stats(sdc, sdp, itv, &xds);
705 persist_dev_name = NULL;
707 if (DISPLAY_PERSIST_NAME_S(flags)) {
708 persist_dev_name = get_persistent_name_from_pretty(get_devname(sdc->major, sdc->minor, TRUE));
711 if (persist_dev_name) {
712 dev_name = persist_dev_name;
715 if ((USE_PRETTY_OPTION(flags)) && (sdc->major == dm_major)) {
716 dev_name = transform_devmapname(sdc->major, sdc->minor);
720 dev_name = get_devname(sdc->major, sdc->minor,
721 USE_PRETTY_OPTION(flags));
730 xprintf0(tab, "{\"disk-device\": \"%s\", "
734 "\"avgrq-sz\": %.2f, "
735 "\"avgqu-sz\": %.2f, "
738 "\"util-percent\": %.2f}",
739 /* Confusion possible here between index and minor numbers */
741 S_VALUE(sdp->nr_ios, sdc->nr_ios, itv),
742 S_VALUE(sdp->rd_sect, sdc->rd_sect, itv),
743 S_VALUE(sdp->wr_sect, sdc->wr_sect, itv),
744 /* See iostat for explanations */
746 S_VALUE(sdp->rq_ticks, sdc->rq_ticks, itv) / 1000.0,
753 xprintf0(--tab, "]");
757 ***************************************************************************
758 * Display network interfaces statistics in JSON.
761 * @a Activity structure with statistics.
762 * @curr Index in array for current sample statistics.
763 * @tab Indentation in output.
764 * @itv Interval of time in jiffies.
765 ***************************************************************************
767 __print_funct_t json_print_net_dev_stats(struct activity *a, int curr, int tab,
768 unsigned long long itv)
771 struct stats_net_dev *sndc, *sndp;
773 double rxkb, txkb, ifutil;
775 if (!IS_SELECTED(a->options) || (a->nr <= 0))
776 goto close_json_markup;
778 json_markup_network(tab, OPEN_JSON_MARKUP);
781 xprintf(tab++, "\"net-dev\": [");
783 for (i = 0; i < a->nr; i++) {
785 sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
787 if (!strcmp(sndc->interface, ""))
790 j = check_net_dev_reg(a, curr, !curr, i);
791 sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
798 rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
799 txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
800 ifutil = compute_ifutil(sndc, rxkb, txkb);
802 xprintf0(tab, "{\"iface\": \"%s\", "
810 "\"ifutil-percent\": %.2f}",
812 S_VALUE(sndp->rx_packets, sndc->rx_packets, itv),
813 S_VALUE(sndp->tx_packets, sndc->tx_packets, itv),
816 S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv),
817 S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv),
818 S_VALUE(sndp->multicast, sndc->multicast, itv),
823 xprintf0(--tab, "]");
828 if (CLOSE_MARKUP(a->options)) {
829 json_markup_network(tab, CLOSE_JSON_MARKUP);
834 ***************************************************************************
835 * Display network interfaces errors statistics in JSON.
838 * @a Activity structure with statistics.
839 * @curr Index in array for current sample statistics.
840 * @tab Indentation in output.
841 * @itv Interval of time in jiffies.
842 ***************************************************************************
844 __print_funct_t json_print_net_edev_stats(struct activity *a, int curr, int tab,
845 unsigned long long itv)
848 struct stats_net_edev *snedc, *snedp;
851 if (!IS_SELECTED(a->options) || (a->nr <= 0))
852 goto close_json_markup;
854 json_markup_network(tab, OPEN_JSON_MARKUP);
857 xprintf(tab++, "\"net-edev\": [");
859 for (i = 0; i < a->nr; i++) {
861 snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize);
863 if (!strcmp(snedc->interface, ""))
866 j = check_net_edev_reg(a, curr, !curr, i);
867 snedp = (struct stats_net_edev *) ((char *) a->buf[!curr] + j * a->msize);
874 xprintf0(tab, "{\"iface\": \"%s\", "
885 S_VALUE(snedp->rx_errors, snedc->rx_errors, itv),
886 S_VALUE(snedp->tx_errors, snedc->tx_errors, itv),
887 S_VALUE(snedp->collisions, snedc->collisions, itv),
888 S_VALUE(snedp->rx_dropped, snedc->rx_dropped, itv),
889 S_VALUE(snedp->tx_dropped, snedc->tx_dropped, itv),
890 S_VALUE(snedp->tx_carrier_errors, snedc->tx_carrier_errors, itv),
891 S_VALUE(snedp->rx_frame_errors, snedc->rx_frame_errors, itv),
892 S_VALUE(snedp->rx_fifo_errors, snedc->rx_fifo_errors, itv),
893 S_VALUE(snedp->tx_fifo_errors, snedc->tx_fifo_errors, itv));
897 xprintf0(--tab, "]");
902 if (CLOSE_MARKUP(a->options)) {
903 json_markup_network(tab, CLOSE_JSON_MARKUP);
908 ***************************************************************************
909 * Display NFS client statistics in JSON.
912 * @a Activity structure with statistics.
913 * @curr Index in array for current sample statistics.
914 * @tab Indentation in output.
915 * @itv Interval of time in jiffies.
916 ***************************************************************************
918 __print_funct_t json_print_net_nfs_stats(struct activity *a, int curr, int tab,
919 unsigned long long itv)
922 *snnc = (struct stats_net_nfs *) a->buf[curr],
923 *snnp = (struct stats_net_nfs *) a->buf[!curr];
925 if (!IS_SELECTED(a->options) || (a->nr <= 0))
926 goto close_json_markup;
928 json_markup_network(tab, OPEN_JSON_MARKUP);
931 xprintf0(tab, "\"net-nfs\": {"
933 "\"retrans\": %.2f, "
938 S_VALUE(snnp->nfs_rpccnt, snnc->nfs_rpccnt, itv),
939 S_VALUE(snnp->nfs_rpcretrans, snnc->nfs_rpcretrans, itv),
940 S_VALUE(snnp->nfs_readcnt, snnc->nfs_readcnt, itv),
941 S_VALUE(snnp->nfs_writecnt, snnc->nfs_writecnt, itv),
942 S_VALUE(snnp->nfs_accesscnt, snnc->nfs_accesscnt, itv),
943 S_VALUE(snnp->nfs_getattcnt, snnc->nfs_getattcnt, itv));
947 if (CLOSE_MARKUP(a->options)) {
948 json_markup_network(tab, CLOSE_JSON_MARKUP);
953 ***************************************************************************
954 * Display NFS server statistics in JSON.
957 * @a Activity structure with statistics.
958 * @curr Index in array for current sample statistics.
959 * @tab Indentation in output.
960 * @itv Interval of time in jiffies.
961 ***************************************************************************
963 __print_funct_t json_print_net_nfsd_stats(struct activity *a, int curr, int tab,
964 unsigned long long itv)
966 struct stats_net_nfsd
967 *snndc = (struct stats_net_nfsd *) a->buf[curr],
968 *snndp = (struct stats_net_nfsd *) a->buf[!curr];
970 if (!IS_SELECTED(a->options) || (a->nr <= 0))
971 goto close_json_markup;
973 json_markup_network(tab, OPEN_JSON_MARKUP);
976 xprintf0(tab, "\"net-nfsd\": {"
978 "\"badcall\": %.2f, "
986 "\"saccess\": %.2f, "
987 "\"sgetatt\": %.2f}",
988 S_VALUE(snndp->nfsd_rpccnt, snndc->nfsd_rpccnt, itv),
989 S_VALUE(snndp->nfsd_rpcbad, snndc->nfsd_rpcbad, itv),
990 S_VALUE(snndp->nfsd_netcnt, snndc->nfsd_netcnt, itv),
991 S_VALUE(snndp->nfsd_netudpcnt, snndc->nfsd_netudpcnt, itv),
992 S_VALUE(snndp->nfsd_nettcpcnt, snndc->nfsd_nettcpcnt, itv),
993 S_VALUE(snndp->nfsd_rchits, snndc->nfsd_rchits, itv),
994 S_VALUE(snndp->nfsd_rcmisses, snndc->nfsd_rcmisses, itv),
995 S_VALUE(snndp->nfsd_readcnt, snndc->nfsd_readcnt, itv),
996 S_VALUE(snndp->nfsd_writecnt, snndc->nfsd_writecnt, itv),
997 S_VALUE(snndp->nfsd_accesscnt, snndc->nfsd_accesscnt, itv),
998 S_VALUE(snndp->nfsd_getattcnt, snndc->nfsd_getattcnt, itv));
1002 if (CLOSE_MARKUP(a->options)) {
1003 json_markup_network(tab, CLOSE_JSON_MARKUP);
1008 ***************************************************************************
1009 * Display network socket statistics in JSON.
1012 * @a Activity structure with statistics.
1013 * @curr Index in array for current sample statistics.
1014 * @tab Indentation in output.
1015 * @itv Interval of time in jiffies.
1016 ***************************************************************************
1018 __print_funct_t json_print_net_sock_stats(struct activity *a, int curr, int tab,
1019 unsigned long long itv)
1021 struct stats_net_sock
1022 *snsc = (struct stats_net_sock *) a->buf[curr];
1024 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1025 goto close_json_markup;
1027 json_markup_network(tab, OPEN_JSON_MARKUP);
1030 xprintf0(tab, "\"net-sock\": {"
1046 if (CLOSE_MARKUP(a->options)) {
1047 json_markup_network(tab, CLOSE_JSON_MARKUP);
1052 ***************************************************************************
1053 * Display IP network statistics in JSON.
1056 * @a Activity structure with statistics.
1057 * @curr Index in array for current sample statistics.
1058 * @tab Indentation in output.
1059 * @itv Interval of time in jiffies.
1060 ***************************************************************************
1062 __print_funct_t json_print_net_ip_stats(struct activity *a, int curr, int tab,
1063 unsigned long long itv)
1066 *snic = (struct stats_net_ip *) a->buf[curr],
1067 *snip = (struct stats_net_ip *) a->buf[!curr];
1069 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1070 goto close_json_markup;
1072 json_markup_network(tab, OPEN_JSON_MARKUP);
1075 xprintf0(tab, "\"net-ip\": {"
1077 "\"fwddgm\": %.2f, "
1082 "\"fragok\": %.2f, "
1083 "\"fragcrt\": %.2f}",
1084 S_VALUE(snip->InReceives, snic->InReceives, itv),
1085 S_VALUE(snip->ForwDatagrams, snic->ForwDatagrams, itv),
1086 S_VALUE(snip->InDelivers, snic->InDelivers, itv),
1087 S_VALUE(snip->OutRequests, snic->OutRequests, itv),
1088 S_VALUE(snip->ReasmReqds, snic->ReasmReqds, itv),
1089 S_VALUE(snip->ReasmOKs, snic->ReasmOKs, itv),
1090 S_VALUE(snip->FragOKs, snic->FragOKs, itv),
1091 S_VALUE(snip->FragCreates, snic->FragCreates, itv));
1095 if (CLOSE_MARKUP(a->options)) {
1096 json_markup_network(tab, CLOSE_JSON_MARKUP);
1101 ***************************************************************************
1102 * Display IP network errors statistics in JSON.
1105 * @a Activity structure with statistics.
1106 * @curr Index in array for current sample statistics.
1107 * @tab Indentation in output.
1108 * @itv Interval of time in jiffies.
1109 ***************************************************************************
1111 __print_funct_t json_print_net_eip_stats(struct activity *a, int curr, int tab,
1112 unsigned long long itv)
1114 struct stats_net_eip
1115 *sneic = (struct stats_net_eip *) a->buf[curr],
1116 *sneip = (struct stats_net_eip *) a->buf[!curr];
1118 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1119 goto close_json_markup;
1121 json_markup_network(tab, OPEN_JSON_MARKUP);
1124 xprintf0(tab, "\"net-eip\": {"
1125 "\"ihdrerr\": %.2f, "
1126 "\"iadrerr\": %.2f, "
1127 "\"iukwnpr\": %.2f, "
1133 S_VALUE(sneip->InHdrErrors, sneic->InHdrErrors, itv),
1134 S_VALUE(sneip->InAddrErrors, sneic->InAddrErrors, itv),
1135 S_VALUE(sneip->InUnknownProtos, sneic->InUnknownProtos, itv),
1136 S_VALUE(sneip->InDiscards, sneic->InDiscards, itv),
1137 S_VALUE(sneip->OutDiscards, sneic->OutDiscards, itv),
1138 S_VALUE(sneip->OutNoRoutes, sneic->OutNoRoutes, itv),
1139 S_VALUE(sneip->ReasmFails, sneic->ReasmFails, itv),
1140 S_VALUE(sneip->FragFails, sneic->FragFails, itv));
1144 if (CLOSE_MARKUP(a->options)) {
1145 json_markup_network(tab, CLOSE_JSON_MARKUP);
1150 ***************************************************************************
1151 * Display ICMP network statistics in JSON.
1154 * @a Activity structure with statistics.
1155 * @curr Index in array for current sample statistics.
1156 * @tab Indentation in output.
1157 * @itv Interval of time in jiffies.
1158 ***************************************************************************
1160 __print_funct_t json_print_net_icmp_stats(struct activity *a, int curr, int tab,
1161 unsigned long long itv)
1163 struct stats_net_icmp
1164 *snic = (struct stats_net_icmp *) a->buf[curr],
1165 *snip = (struct stats_net_icmp *) a->buf[!curr];
1167 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1168 goto close_json_markup;
1170 json_markup_network(tab, OPEN_JSON_MARKUP);
1173 xprintf0(tab, "\"net-icmp\": {"
1184 "\"iadrmk\": %.2f, "
1185 "\"iadrmkr\": %.2f, "
1186 "\"oadrmk\": %.2f, "
1187 "\"oadrmkr\": %.2f}",
1188 S_VALUE(snip->InMsgs, snic->InMsgs, itv),
1189 S_VALUE(snip->OutMsgs, snic->OutMsgs, itv),
1190 S_VALUE(snip->InEchos, snic->InEchos, itv),
1191 S_VALUE(snip->InEchoReps, snic->InEchoReps, itv),
1192 S_VALUE(snip->OutEchos, snic->OutEchos, itv),
1193 S_VALUE(snip->OutEchoReps, snic->OutEchoReps, itv),
1194 S_VALUE(snip->InTimestamps, snic->InTimestamps, itv),
1195 S_VALUE(snip->InTimestampReps, snic->InTimestampReps, itv),
1196 S_VALUE(snip->OutTimestamps, snic->OutTimestamps, itv),
1197 S_VALUE(snip->OutTimestampReps, snic->OutTimestampReps, itv),
1198 S_VALUE(snip->InAddrMasks, snic->InAddrMasks, itv),
1199 S_VALUE(snip->InAddrMaskReps, snic->InAddrMaskReps, itv),
1200 S_VALUE(snip->OutAddrMasks, snic->OutAddrMasks, itv),
1201 S_VALUE(snip->OutAddrMaskReps, snic->OutAddrMaskReps, itv));
1205 if (CLOSE_MARKUP(a->options)) {
1206 json_markup_network(tab, CLOSE_JSON_MARKUP);
1211 ***************************************************************************
1212 * Display ICMP errors message statistics in JSON.
1215 * @a Activity structure with statistics.
1216 * @curr Index in array for current sample statistics.
1217 * @tab Indentation in output.
1218 * @itv Interval of time in jiffies.
1219 ***************************************************************************
1221 __print_funct_t json_print_net_eicmp_stats(struct activity *a, int curr, int tab,
1222 unsigned long long itv)
1224 struct stats_net_eicmp
1225 *sneic = (struct stats_net_eicmp *) a->buf[curr],
1226 *sneip = (struct stats_net_eicmp *) a->buf[!curr];
1228 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1229 goto close_json_markup;
1231 json_markup_network(tab, OPEN_JSON_MARKUP);
1234 xprintf0(tab, "\"net-eicmp\": {"
1237 "\"idstunr\": %.2f, "
1238 "\"odstunr\": %.2f, "
1241 "\"iparmpb\": %.2f, "
1242 "\"oparmpb\": %.2f, "
1245 "\"iredir\": %.2f, "
1246 "\"oredir\": %.2f}",
1247 S_VALUE(sneip->InErrors, sneic->InErrors, itv),
1248 S_VALUE(sneip->OutErrors, sneic->OutErrors, itv),
1249 S_VALUE(sneip->InDestUnreachs, sneic->InDestUnreachs, itv),
1250 S_VALUE(sneip->OutDestUnreachs, sneic->OutDestUnreachs, itv),
1251 S_VALUE(sneip->InTimeExcds, sneic->InTimeExcds, itv),
1252 S_VALUE(sneip->OutTimeExcds, sneic->OutTimeExcds, itv),
1253 S_VALUE(sneip->InParmProbs, sneic->InParmProbs, itv),
1254 S_VALUE(sneip->OutParmProbs, sneic->OutParmProbs, itv),
1255 S_VALUE(sneip->InSrcQuenchs, sneic->InSrcQuenchs, itv),
1256 S_VALUE(sneip->OutSrcQuenchs, sneic->OutSrcQuenchs, itv),
1257 S_VALUE(sneip->InRedirects, sneic->InRedirects, itv),
1258 S_VALUE(sneip->OutRedirects, sneic->OutRedirects, itv));
1262 if (CLOSE_MARKUP(a->options)) {
1263 json_markup_network(tab, CLOSE_JSON_MARKUP);
1268 ***************************************************************************
1269 * Display TCP network statistics in JSON.
1272 * @a Activity structure with statistics.
1273 * @curr Index in array for current sample statistics.
1274 * @tab Indentation in output.
1275 * @itv Interval of time in jiffies.
1276 ***************************************************************************
1278 __print_funct_t json_print_net_tcp_stats(struct activity *a, int curr, int tab,
1279 unsigned long long itv)
1281 struct stats_net_tcp
1282 *sntc = (struct stats_net_tcp *) a->buf[curr],
1283 *sntp = (struct stats_net_tcp *) a->buf[!curr];
1285 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1286 goto close_json_markup;
1288 json_markup_network(tab, OPEN_JSON_MARKUP);
1291 xprintf0(tab, "\"net-tcp\": {"
1292 "\"active\": %.2f, "
1293 "\"passive\": %.2f, "
1296 S_VALUE(sntp->ActiveOpens, sntc->ActiveOpens, itv),
1297 S_VALUE(sntp->PassiveOpens, sntc->PassiveOpens, itv),
1298 S_VALUE(sntp->InSegs, sntc->InSegs, itv),
1299 S_VALUE(sntp->OutSegs, sntc->OutSegs, itv));
1303 if (CLOSE_MARKUP(a->options)) {
1304 json_markup_network(tab, CLOSE_JSON_MARKUP);
1309 ***************************************************************************
1310 * Display TCP network errors statistics in JSON.
1313 * @a Activity structure with statistics.
1314 * @curr Index in array for current sample statistics.
1315 * @tab Indentation in XML output.
1316 * @itv Interval of time in jiffies.
1317 ***************************************************************************
1319 __print_funct_t json_print_net_etcp_stats(struct activity *a, int curr, int tab,
1320 unsigned long long itv)
1322 struct stats_net_etcp
1323 *snetc = (struct stats_net_etcp *) a->buf[curr],
1324 *snetp = (struct stats_net_etcp *) a->buf[!curr];
1326 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1327 goto close_json_markup;
1329 json_markup_network(tab, OPEN_JSON_MARKUP);
1332 xprintf0(tab, "\"net-etcp\": {"
1333 "\"atmptf\": %.2f, "
1334 "\"estres\": %.2f, "
1335 "\"retrans\": %.2f, "
1336 "\"isegerr\": %.2f, "
1338 S_VALUE(snetp->AttemptFails, snetc->AttemptFails, itv),
1339 S_VALUE(snetp->EstabResets, snetc->EstabResets, itv),
1340 S_VALUE(snetp->RetransSegs, snetc->RetransSegs, itv),
1341 S_VALUE(snetp->InErrs, snetc->InErrs, itv),
1342 S_VALUE(snetp->OutRsts, snetc->OutRsts, itv));
1346 if (CLOSE_MARKUP(a->options)) {
1347 json_markup_network(tab, CLOSE_JSON_MARKUP);
1352 ***************************************************************************
1353 * Display UDP network statistics in JSON.
1356 * @a Activity structure with statistics.
1357 * @curr Index in array for current sample statistics.
1358 * @tab Indentation in output.
1359 * @itv Interval of time in jiffies.
1360 ***************************************************************************
1362 __print_funct_t json_print_net_udp_stats(struct activity *a, int curr, int tab,
1363 unsigned long long itv)
1365 struct stats_net_udp
1366 *snuc = (struct stats_net_udp *) a->buf[curr],
1367 *snup = (struct stats_net_udp *) a->buf[!curr];
1369 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1370 goto close_json_markup;
1372 json_markup_network(tab, OPEN_JSON_MARKUP);
1375 xprintf0(tab, "\"net-udp\": {"
1378 "\"noport\": %.2f, "
1379 "\"idgmerr\": %.2f}",
1380 S_VALUE(snup->InDatagrams, snuc->InDatagrams, itv),
1381 S_VALUE(snup->OutDatagrams, snuc->OutDatagrams, itv),
1382 S_VALUE(snup->NoPorts, snuc->NoPorts, itv),
1383 S_VALUE(snup->InErrors, snuc->InErrors, itv));
1387 if (CLOSE_MARKUP(a->options)) {
1388 json_markup_network(tab, CLOSE_JSON_MARKUP);
1393 ***************************************************************************
1394 * Display IPv6 network socket statistics in JSON.
1397 * @a Activity structure with statistics.
1398 * @curr Index in array for current sample statistics.
1399 * @tab Indentation in output.
1400 * @itv Interval of time in jiffies.
1401 ***************************************************************************
1403 __print_funct_t json_print_net_sock6_stats(struct activity *a, int curr, int tab,
1404 unsigned long long itv)
1406 struct stats_net_sock6
1407 *snsc = (struct stats_net_sock6 *) a->buf[curr];
1409 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1410 goto close_json_markup;
1412 json_markup_network(tab, OPEN_JSON_MARKUP);
1415 xprintf0(tab, "\"net-sock6\": {"
1419 "\"ip6-frag\": %u}",
1427 if (CLOSE_MARKUP(a->options)) {
1428 json_markup_network(tab, CLOSE_JSON_MARKUP);
1433 ***************************************************************************
1434 * Display IPv6 network statistics in JSON.
1437 * @a Activity structure with statistics.
1438 * @curr Index in array for current sample statistics.
1439 * @tab Indentation in output.
1440 * @itv Interval of time in jiffies.
1441 ***************************************************************************
1443 __print_funct_t json_print_net_ip6_stats(struct activity *a, int curr, int tab,
1444 unsigned long long itv)
1446 struct stats_net_ip6
1447 *snic = (struct stats_net_ip6 *) a->buf[curr],
1448 *snip = (struct stats_net_ip6 *) a->buf[!curr];
1450 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1451 goto close_json_markup;
1453 json_markup_network(tab, OPEN_JSON_MARKUP);
1456 xprintf0(tab, "\"net-ip6\": {"
1458 "\"fwddgm6\": %.2f, "
1461 "\"asmrq6\": %.2f, "
1462 "\"asmok6\": %.2f, "
1463 "\"imcpck6\": %.2f, "
1464 "\"omcpck6\": %.2f, "
1465 "\"fragok6\": %.2f, "
1466 "\"fragcr6\": %.2f}",
1467 S_VALUE(snip->InReceives6, snic->InReceives6, itv),
1468 S_VALUE(snip->OutForwDatagrams6, snic->OutForwDatagrams6, itv),
1469 S_VALUE(snip->InDelivers6, snic->InDelivers6, itv),
1470 S_VALUE(snip->OutRequests6, snic->OutRequests6, itv),
1471 S_VALUE(snip->ReasmReqds6, snic->ReasmReqds6, itv),
1472 S_VALUE(snip->ReasmOKs6, snic->ReasmOKs6, itv),
1473 S_VALUE(snip->InMcastPkts6, snic->InMcastPkts6, itv),
1474 S_VALUE(snip->OutMcastPkts6, snic->OutMcastPkts6, itv),
1475 S_VALUE(snip->FragOKs6, snic->FragOKs6, itv),
1476 S_VALUE(snip->FragCreates6, snic->FragCreates6, itv));
1480 if (CLOSE_MARKUP(a->options)) {
1481 json_markup_network(tab, CLOSE_JSON_MARKUP);
1486 ***************************************************************************
1487 * Display IPv6 network errors statistics in JSON.
1490 * @a Activity structure with statistics.
1491 * @curr Index in array for current sample statistics.
1492 * @tab Indentation in output.
1493 * @itv Interval of time in jiffies.
1494 ***************************************************************************
1496 __print_funct_t json_print_net_eip6_stats(struct activity *a, int curr, int tab,
1497 unsigned long long itv)
1499 struct stats_net_eip6
1500 *sneic = (struct stats_net_eip6 *) a->buf[curr],
1501 *sneip = (struct stats_net_eip6 *) a->buf[!curr];
1503 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1504 goto close_json_markup;
1506 json_markup_network(tab, OPEN_JSON_MARKUP);
1509 xprintf0(tab, "\"net-eip6\": {"
1510 "\"ihdrer6\": %.2f, "
1511 "\"iadrer6\": %.2f, "
1512 "\"iukwnp6\": %.2f, "
1513 "\"i2big6\": %.2f, "
1514 "\"idisc6\": %.2f, "
1515 "\"odisc6\": %.2f, "
1516 "\"inort6\": %.2f, "
1517 "\"onort6\": %.2f, "
1519 "\"fragf6\": %.2f, "
1520 "\"itrpck6\": %.2f}",
1521 S_VALUE(sneip->InHdrErrors6, sneic->InHdrErrors6, itv),
1522 S_VALUE(sneip->InAddrErrors6, sneic->InAddrErrors6, itv),
1523 S_VALUE(sneip->InUnknownProtos6, sneic->InUnknownProtos6, itv),
1524 S_VALUE(sneip->InTooBigErrors6, sneic->InTooBigErrors6, itv),
1525 S_VALUE(sneip->InDiscards6, sneic->InDiscards6, itv),
1526 S_VALUE(sneip->OutDiscards6, sneic->OutDiscards6, itv),
1527 S_VALUE(sneip->InNoRoutes6, sneic->InNoRoutes6, itv),
1528 S_VALUE(sneip->OutNoRoutes6, sneic->OutNoRoutes6, itv),
1529 S_VALUE(sneip->ReasmFails6, sneic->ReasmFails6, itv),
1530 S_VALUE(sneip->FragFails6, sneic->FragFails6, itv),
1531 S_VALUE(sneip->InTruncatedPkts6, sneic->InTruncatedPkts6, itv));
1535 if (CLOSE_MARKUP(a->options)) {
1536 json_markup_network(tab, CLOSE_JSON_MARKUP);
1541 ***************************************************************************
1542 * Display ICMPv6 network statistics in JSON.
1545 * @a Activity structure with statistics.
1546 * @curr Index in array for current sample statistics.
1547 * @tab Indentation in output.
1548 * @itv Interval of time in jiffies.
1549 ***************************************************************************
1551 __print_funct_t json_print_net_icmp6_stats(struct activity *a, int curr, int tab,
1552 unsigned long long itv)
1554 struct stats_net_icmp6
1555 *snic = (struct stats_net_icmp6 *) a->buf[curr],
1556 *snip = (struct stats_net_icmp6 *) a->buf[!curr];
1558 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1559 goto close_json_markup;
1561 json_markup_network(tab, OPEN_JSON_MARKUP);
1564 xprintf0(tab, "\"net-icmp6\": {"
1568 "\"iechr6\": %.2f, "
1569 "\"oechr6\": %.2f, "
1570 "\"igmbq6\": %.2f, "
1571 "\"igmbr6\": %.2f, "
1572 "\"ogmbr6\": %.2f, "
1573 "\"igmbrd6\": %.2f, "
1574 "\"ogmbrd6\": %.2f, "
1575 "\"irtsol6\": %.2f, "
1576 "\"ortsol6\": %.2f, "
1577 "\"irtad6\": %.2f, "
1578 "\"inbsol6\": %.2f, "
1579 "\"onbsol6\": %.2f, "
1580 "\"inbad6\": %.2f, "
1581 "\"onbad6\": %.2f}",
1582 S_VALUE(snip->InMsgs6, snic->InMsgs6, itv),
1583 S_VALUE(snip->OutMsgs6, snic->OutMsgs6, itv),
1584 S_VALUE(snip->InEchos6, snic->InEchos6, itv),
1585 S_VALUE(snip->InEchoReplies6, snic->InEchoReplies6, itv),
1586 S_VALUE(snip->OutEchoReplies6, snic->OutEchoReplies6, itv),
1587 S_VALUE(snip->InGroupMembQueries6, snic->InGroupMembQueries6, itv),
1588 S_VALUE(snip->InGroupMembResponses6, snic->InGroupMembResponses6, itv),
1589 S_VALUE(snip->OutGroupMembResponses6, snic->OutGroupMembResponses6, itv),
1590 S_VALUE(snip->InGroupMembReductions6, snic->InGroupMembReductions6, itv),
1591 S_VALUE(snip->OutGroupMembReductions6, snic->OutGroupMembReductions6, itv),
1592 S_VALUE(snip->InRouterSolicits6, snic->InRouterSolicits6, itv),
1593 S_VALUE(snip->OutRouterSolicits6, snic->OutRouterSolicits6, itv),
1594 S_VALUE(snip->InRouterAdvertisements6, snic->InRouterAdvertisements6, itv),
1595 S_VALUE(snip->InNeighborSolicits6, snic->InNeighborSolicits6, itv),
1596 S_VALUE(snip->OutNeighborSolicits6, snic->OutNeighborSolicits6, itv),
1597 S_VALUE(snip->InNeighborAdvertisements6, snic->InNeighborAdvertisements6, itv),
1598 S_VALUE(snip->OutNeighborAdvertisements6, snic->OutNeighborAdvertisements6, itv));
1602 if (CLOSE_MARKUP(a->options)) {
1603 json_markup_network(tab, CLOSE_JSON_MARKUP);
1608 ***************************************************************************
1609 * Display ICMPv6 error messages statistics in JSON.
1612 * @a Activity structure with statistics.
1613 * @curr Index in array for current sample statistics.
1614 * @tab Indentation in output.
1615 * @itv Interval of time in jiffies.
1616 ***************************************************************************
1618 __print_funct_t json_print_net_eicmp6_stats(struct activity *a, int curr, int tab,
1619 unsigned long long itv)
1621 struct stats_net_eicmp6
1622 *sneic = (struct stats_net_eicmp6 *) a->buf[curr],
1623 *sneip = (struct stats_net_eicmp6 *) a->buf[!curr];
1625 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1626 goto close_json_markup;
1628 json_markup_network(tab, OPEN_JSON_MARKUP);
1631 xprintf0(tab, "\"net-eicmp6\": {"
1633 "\"idtunr6\": %.2f, "
1634 "\"odtunr6\": %.2f, "
1635 "\"itmex6\": %.2f, "
1636 "\"otmex6\": %.2f, "
1637 "\"iprmpb6\": %.2f, "
1638 "\"oprmpb6\": %.2f, "
1639 "\"iredir6\": %.2f, "
1640 "\"oredir6\": %.2f, "
1641 "\"ipck2b6\": %.2f, "
1642 "\"opck2b6\": %.2f}",
1643 S_VALUE(sneip->InErrors6, sneic->InErrors6, itv),
1644 S_VALUE(sneip->InDestUnreachs6, sneic->InDestUnreachs6, itv),
1645 S_VALUE(sneip->OutDestUnreachs6, sneic->OutDestUnreachs6, itv),
1646 S_VALUE(sneip->InTimeExcds6, sneic->InTimeExcds6, itv),
1647 S_VALUE(sneip->OutTimeExcds6, sneic->OutTimeExcds6, itv),
1648 S_VALUE(sneip->InParmProblems6, sneic->InParmProblems6, itv),
1649 S_VALUE(sneip->OutParmProblems6, sneic->OutParmProblems6, itv),
1650 S_VALUE(sneip->InRedirects6, sneic->InRedirects6, itv),
1651 S_VALUE(sneip->OutRedirects6, sneic->OutRedirects6, itv),
1652 S_VALUE(sneip->InPktTooBigs6, sneic->InPktTooBigs6, itv),
1653 S_VALUE(sneip->OutPktTooBigs6, sneic->OutPktTooBigs6, itv));
1657 if (CLOSE_MARKUP(a->options)) {
1658 json_markup_network(tab, CLOSE_JSON_MARKUP);
1663 ***************************************************************************
1664 * Display UDPv6 network statistics in JSON.
1667 * @a Activity structure with statistics.
1668 * @curr Index in array for current sample statistics.
1669 * @tab Indentation in output.
1670 * @itv Interval of time in jiffies.
1671 ***************************************************************************
1673 __print_funct_t json_print_net_udp6_stats(struct activity *a, int curr, int tab,
1674 unsigned long long itv)
1676 struct stats_net_udp6
1677 *snuc = (struct stats_net_udp6 *) a->buf[curr],
1678 *snup = (struct stats_net_udp6 *) a->buf[!curr];
1680 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1681 goto close_json_markup;
1683 json_markup_network(tab, OPEN_JSON_MARKUP);
1686 xprintf0(tab, "\"net-udp6\": {"
1689 "\"noport6\": %.2f, "
1690 "\"idgmer6\": %.2f}",
1691 S_VALUE(snup->InDatagrams6, snuc->InDatagrams6, itv),
1692 S_VALUE(snup->OutDatagrams6, snuc->OutDatagrams6, itv),
1693 S_VALUE(snup->NoPorts6, snuc->NoPorts6, itv),
1694 S_VALUE(snup->InErrors6, snuc->InErrors6, itv));
1698 if (CLOSE_MARKUP(a->options)) {
1699 json_markup_network(tab, CLOSE_JSON_MARKUP);
1704 ***************************************************************************
1705 * Display CPU frequency statistics in JSON.
1708 * @a Activity structure with statistics.
1709 * @curr Index in array for current sample statistics.
1710 * @tab Indentation in output.
1711 * @itv Interval of time in jiffies.
1712 ***************************************************************************
1714 __print_funct_t json_print_pwr_cpufreq_stats(struct activity *a, int curr, int tab,
1715 unsigned long long itv)
1718 struct stats_pwr_cpufreq *spc;
1722 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1723 goto close_json_markup;
1725 json_markup_power_management(tab, OPEN_JSON_MARKUP);
1728 xprintf(tab++, "\"cpu-frequency\": [");
1730 for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
1732 spc = (struct stats_pwr_cpufreq *) ((char *) a->buf[curr] + i * a->msize);
1734 /* Should current CPU (including CPU "all") be displayed? */
1735 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
1737 /* Yes: Display it */
1739 /* This is CPU "all" */
1740 strcpy(cpuno, "all");
1743 sprintf(cpuno, "%d", i - 1);
1751 xprintf0(tab, "{\"number\": \"%s\", "
1752 "\"frequency\": %.2f}",
1754 ((double) spc->cpufreq) / 100);
1759 xprintf0(--tab, "]");
1763 if (CLOSE_MARKUP(a->options)) {
1764 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1769 ***************************************************************************
1770 * Display fan statistics in JSON.
1773 * @a Activity structure with statistics.
1774 * @curr Index in array for current sample statistics.
1775 * @tab Indentation in output.
1776 * @itv Interval of time in jiffies.
1777 ***************************************************************************
1779 __print_funct_t json_print_pwr_fan_stats(struct activity *a, int curr, int tab,
1780 unsigned long long itv)
1783 struct stats_pwr_fan *spc;
1786 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1787 goto close_json_markup;
1789 json_markup_power_management(tab, OPEN_JSON_MARKUP);
1792 xprintf(tab++, "\"fan-speed\": [");
1794 for (i = 0; i < a->nr; i++) {
1795 spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize);
1802 xprintf0(tab, "{\"number\": %d, "
1805 "\"device\": \"%s\"}",
1807 (unsigned long long) spc->rpm,
1808 (unsigned long long) (spc->rpm - spc->rpm_min),
1813 xprintf0(--tab, "]");
1817 if (CLOSE_MARKUP(a->options)) {
1818 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1823 ***************************************************************************
1824 * Display temperature statistics in JSON.
1827 * @a Activity structure with statistics.
1828 * @curr Index in array for current sample statistics.
1829 * @tab Indentation in output.
1830 * @itv Interval of time in jiffies.
1831 ***************************************************************************
1833 __print_funct_t json_print_pwr_temp_stats(struct activity *a, int curr, int tab,
1834 unsigned long long itv)
1837 struct stats_pwr_temp *spc;
1840 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1841 goto close_json_markup;
1843 json_markup_power_management(tab, OPEN_JSON_MARKUP);
1846 xprintf(tab++, "\"temperature\": [");
1848 for (i = 0; i < a->nr; i++) {
1849 spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize);
1856 xprintf0(tab, "{\"number\": %d, "
1858 "\"percent-temp\": %.2f, "
1859 "\"device\": \"%s\"}",
1862 (spc->temp_max - spc->temp_min) ?
1863 (spc->temp - spc->temp_min) / (spc->temp_max - spc->temp_min) * 100 :
1869 xprintf0(--tab, "]");
1873 if (CLOSE_MARKUP(a->options)) {
1874 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1879 ***************************************************************************
1880 * Display voltage inputs statistics in JSON.
1883 * @a Activity structure with statistics.
1884 * @curr Index in array for current sample statistics.
1885 * @tab Indentation in output.
1886 * @itv Interval of time in jiffies.
1887 ***************************************************************************
1889 __print_funct_t json_print_pwr_in_stats(struct activity *a, int curr, int tab,
1890 unsigned long long itv)
1893 struct stats_pwr_in *spc;
1896 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1897 goto close_json_markup;
1899 json_markup_power_management(tab, OPEN_JSON_MARKUP);
1902 xprintf(tab++, "\"voltage-input\": [");
1904 for (i = 0; i < a->nr; i++) {
1905 spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize);
1912 xprintf0(tab, "{\"number\": %d, "
1914 "\"percent-in\": %.2f, "
1915 "\"device\": \"%s\"}",
1918 (spc->in_max - spc->in_min) ?
1919 (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100 :
1925 xprintf0(--tab, "]");
1929 if (CLOSE_MARKUP(a->options)) {
1930 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
1935 ***************************************************************************
1936 * Display huge pages statistics in JSON.
1939 * @a Activity structure with statistics.
1940 * @curr Index in array for current sample statistics.
1941 * @tab Indentation in output.
1942 * @itv Interval of time in jiffies.
1943 ***************************************************************************
1945 __print_funct_t json_print_huge_stats(struct activity *a, int curr, int tab,
1946 unsigned long long itv)
1949 *smc = (struct stats_huge *) a->buf[curr];
1951 xprintf0(tab, "\"hugepages\": {"
1952 "\"hugfree\": %lu, "
1953 "\"hugused\": %lu, "
1954 "\"hugused-percent\": %.2f}",
1956 smc->tlhkb - smc->frhkb,
1958 SP_VALUE(smc->frhkb, smc->tlhkb, smc->tlhkb) :
1963 ***************************************************************************
1964 * Display weighted CPU frequency statistics in JSON.
1967 * @a Activity structure with statistics.
1968 * @curr Index in array for current sample statistics.
1969 * @tab Indentation in output.
1970 * @itv Interval of time in jiffies.
1971 ***************************************************************************
1973 __print_funct_t json_print_pwr_wghfreq_stats(struct activity *a, int curr, int tab,
1974 unsigned long long itv)
1977 struct stats_pwr_wghfreq *spc, *spp, *spc_k, *spp_k;
1978 unsigned long long tis, tisfreq;
1982 if (!IS_SELECTED(a->options) || (a->nr <= 0))
1983 goto close_json_markup;
1985 json_markup_power_management(tab, OPEN_JSON_MARKUP);
1988 xprintf(tab++, "\"cpu-weighted-frequency\": [");
1990 for (i = 0; (i < a->nr) && (i < a->bitmap->b_size + 1); i++) {
1992 spc = (struct stats_pwr_wghfreq *) ((char *) a->buf[curr] + i * a->msize * a->nr2);
1993 spp = (struct stats_pwr_wghfreq *) ((char *) a->buf[!curr] + i * a->msize * a->nr2);
1995 /* Should current CPU (including CPU "all") be displayed? */
1996 if (a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) {
2002 for (k = 0; k < a->nr2; k++) {
2004 spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * a->msize);
2007 spp_k = (struct stats_pwr_wghfreq *) ((char *) spp + k * a->msize);
2009 tisfreq += (spc_k->freq / 1000) *
2010 (spc_k->time_in_state - spp_k->time_in_state);
2011 tis += (spc_k->time_in_state - spp_k->time_in_state);
2015 /* This is CPU "all" */
2016 strcpy(cpuno, "all");
2019 sprintf(cpuno, "%d", i - 1);
2027 xprintf0(tab, "{\"number\": \"%s\", "
2028 "\"weighted-frequency\": %.2f}",
2030 tis ? ((double) tisfreq) / tis : 0.0);
2035 xprintf0(--tab, "]");
2039 if (CLOSE_MARKUP(a->options)) {
2040 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
2045 ***************************************************************************
2046 * Display USB devices statistics in JSON.
2049 * @a Activity structure with statistics.
2050 * @curr Index in array for current sample statistics.
2051 * @tab Indentation in output.
2052 * @itv Interval of time in jiffies.
2053 ***************************************************************************
2055 __print_funct_t json_print_pwr_usb_stats(struct activity *a, int curr, int tab,
2056 unsigned long long itv)
2059 struct stats_pwr_usb *suc;
2062 if (!IS_SELECTED(a->options) || (a->nr <= 0))
2063 goto close_json_markup;
2065 json_markup_power_management(tab, OPEN_JSON_MARKUP);
2068 xprintf(tab++, "\"usb-devices\": [");
2070 for (i = 0; i < a->nr; i++) {
2071 suc = (struct stats_pwr_usb *) ((char *) a->buf[curr] + i * a->msize);
2074 /* Bus#0 doesn't exist: We are at the end of the list */
2082 xprintf0(tab, "{\"bus_number\": %d, "
2083 "\"idvendor\": \"%x\", "
2084 "\"idprod\": \"%x\", "
2085 "\"maxpower\": %u, "
2086 "\"manufact\": \"%s\", "
2087 "\"product\": \"%s\"}",
2091 suc->bmaxpower << 1,
2097 xprintf0(--tab, "]");
2101 if (CLOSE_MARKUP(a->options)) {
2102 json_markup_power_management(tab, CLOSE_JSON_MARKUP);
2107 ***************************************************************************
2108 * Display filesystems statistics in JSON.
2111 * @a Activity structure with statistics.
2112 * @curr Index in array for current sample statistics.
2113 * @tab Indentation in output.
2114 * @itv Interval of time in jiffies.
2115 ***************************************************************************
2117 __print_funct_t json_print_filesystem_stats(struct activity *a, int curr, int tab,
2118 unsigned long long itv)
2121 struct stats_filesystem *sfc;
2124 xprintf(tab++, "\"filesystems\": [");
2126 for (i = 0; i < a->nr; i++) {
2127 sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize);
2130 /* Size of filesystem is zero: We are at the end of the list */
2138 xprintf0(tab, "{\"%s\": \"%s\", "
2139 "\"MBfsfree\": %.0f, "
2140 "\"MBfsused\": %.0f, "
2141 "\"%%fsused\": %.2f, "
2142 "\"%%ufsused\": %.2f, "
2145 "\"%%Iused\": %.2f}",
2146 DISPLAY_MOUNT(a->opt_flags) ? "mountpoint" : "filesystem",
2147 DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name,
2148 (double) sfc->f_bfree / 1024 / 1024,
2149 (double) (sfc->f_blocks - sfc->f_bfree) / 1024 / 1024,
2150 sfc->f_blocks ? SP_VALUE(sfc->f_bfree, sfc->f_blocks, sfc->f_blocks)
2152 sfc->f_blocks ? SP_VALUE(sfc->f_bavail, sfc->f_blocks, sfc->f_blocks)
2155 sfc->f_files - sfc->f_ffree,
2156 sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files)
2161 xprintf0(--tab, "]");
2165 ***************************************************************************
2166 * Display Fibre Channel HBA statistics in JSON.
2169 * @a Activity structure with statistics.
2170 * @curr Index in array for current sample statistics.
2171 * @tab Indentation in output.
2172 * @itv Interval of time in jiffies.
2173 ***************************************************************************
2175 __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab,
2176 unsigned long long itv)
2179 struct stats_fchost *sfcc, *sfcp;
2182 if (!IS_SELECTED(a->options) || (a->nr <= 0))
2183 goto close_json_markup;
2185 json_markup_network(tab, OPEN_JSON_MARKUP);
2188 xprintf(tab++, "\"fchosts\": [");
2190 for (i = 0; i < a->nr; i++) {
2191 sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
2192 sfcp = (struct stats_fchost *) ((char *) a->buf[!curr] + i * a->msize);
2194 if (!sfcc->fchost_name[0])
2195 /* We are at the end of the list */
2203 xprintf0(tab, "{\"fchost\": \"%s\", "
2204 "\"fch_rxf\": %.2f, "
2205 "\"fch_txf\": %.2f, "
2206 "\"fch_rxw\": %.2f, "
2207 "\"fch_txw\": %.2f}",
2209 S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv),
2210 S_VALUE(sfcp->f_txframes, sfcc->f_txframes, itv),
2211 S_VALUE(sfcp->f_rxwords, sfcc->f_rxwords, itv),
2212 S_VALUE(sfcp->f_txwords, sfcc->f_txwords, itv));
2216 xprintf0(--tab, "]");
2221 if (CLOSE_MARKUP(a->options)) {
2222 json_markup_network(tab, CLOSE_JSON_MARKUP);