]> granicus.if.org Git - sysstat/commitdiff
SVG: Add SVG output for network statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Feb 2016 11:47:36 +0000 (12:47 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 24 Feb 2016 11:47:36 +0000 (12:47 +0100)
Add 3 new sets of graphs.
They will be displayed for each network interfaces installed.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
activity.c
svg_stats.c
svg_stats.h

index 1d6e24d9bd3dde2460baa6a6fe2547dad6e94579..1f7abb5e60ff5fcc486cc8c4454db9b6e8644707 100644 (file)
@@ -439,7 +439,7 @@ struct activity disk_act = {
 /* Network interfaces activity */
 struct activity net_dev_act = {
        .id             = A_NET_DEV,
-       .options        = AO_COLLECTED,
+       .options        = AO_COLLECTED | AO_GRAPH_PER_ITEM,
        .magic          = ACTIVITY_MAGIC_BASE + 2,
        .group          = G_DEFAULT,
 #ifdef SOURCE_SADC
@@ -455,9 +455,10 @@ struct activity net_dev_act = {
        .f_render       = render_net_dev_stats,
        .f_xml_print    = xml_print_net_dev_stats,
        .f_json_print   = json_print_net_dev_stats,
+       .f_svg_print    = svg_print_net_dev_stats,
        .hdr_line       = "IFACE;rxpck/s;txpck/s;rxkB/s;txkB/s;rxcmp/s;txcmp/s;rxmcst/s;%ifutil",
        .name           = "A_NET_DEV",
-       .g_nr           = 0,
+       .g_nr           = 3,
 #endif
        .nr             = -1,
        .nr2            = 1,
index 19ecd3a3cddc5aed263b00485156624a921a0fa5..09050276305e90532dfeb7cc877b077a42ae1930 100644 (file)
@@ -667,3 +667,112 @@ __print_funct_t svg_print_paging_stats(struct activity *a, int curr, int action,
                free_graphs(out, outsize, spmin, spmax);
        }
 }
+
+/*
+ ***************************************************************************
+ * Display network interfaces statistics in SVG
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ * @curr       Index in array for current sample statistics.
+ * @action     Action expected from current function.
+ * @svg_p      SVG specific parameters: Current graph number (.@graph_no),
+ *             flag indicating that a restart record has been previously
+ *             found (.@restart) and a pointer on a record header structure
+ *             (.@record_hdr) containing the first stats sample.
+ * @itv                Interval of time in jiffies (only with F_MAIN action).
+ * @record_hdr Pointer on record header of current stats sample.
+ ***************************************************************************
+ */
+__print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p,
+                                       unsigned long long itv, struct record_header *record_hdr)
+{
+       struct stats_net_dev *sndc, *sndp;
+       int group[] = {2, 2, 3};
+       char *title[] = {"Network statistics (1)", "Network statistics (2)", "Network statistics (3)"};
+       char *g_title[] = {"rxpck/s", "txpck/s",
+                          "rxkB/s", "txkB/s",
+                          "rxcmp/s", "txcmp/s", "rxmcst/s"};
+       static double *spmin, *spmax;
+       static char **out;
+       static int *outsize;
+       int i, j, pos;
+
+       if (action & F_BEGIN) {
+               /*
+                * Allocate arrays that will contain the graphs data
+                * and the min/max values.
+                */
+               out = allocate_graph_lines(7 * a->nr, &outsize, &spmin, &spmax);
+       }
+
+       if (action & F_MAIN) {
+
+               for (i = 0; i < a->nr; i++) {
+                       sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
+
+                       if (!strcmp(sndc->interface, ""))
+                               continue;
+
+                       j = check_net_dev_reg(a, curr, !curr, i);
+                       sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
+
+                       pos = i * 7;
+                       /* Check for min/max values */
+                       save_extrema(7, 0, 0, (void *) sndc, (void *) sndp,
+                                    itv, spmin + pos, spmax + pos);
+
+                       /* rxpck/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->rx_packets, sndc->rx_packets, itv),
+                                out + pos, outsize + pos, svg_p->restart);
+
+                       /* txpck/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->tx_packets, sndc->tx_packets, itv),
+                                out + pos + 1, outsize + pos + 1, svg_p->restart);
+
+                       /* rxkB/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv) / 1024,
+                                out + pos + 2, outsize + pos + 2, svg_p->restart);
+
+                       /* txkB/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv) / 1024,
+                                out + pos + 3, outsize + pos + 3, svg_p->restart);
+
+                       /* rxcmp/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv),
+                                out + pos + 4, outsize + pos + 4, svg_p->restart);
+
+                       /* txcmp/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv),
+                                out + pos + 5, outsize + pos + 5, svg_p->restart);
+
+                       /* rxmcst/s */
+                       lnappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                                S_VALUE(sndp->multicast, sndc->multicast, itv),
+                                out + pos + 6, outsize + pos + 6, svg_p->restart);
+               }
+       }
+
+       if (action & F_END) {
+               for (i = 0; i < a->nr; i++) {
+                       sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
+
+                       if (!strcmp(sndc->interface, ""))
+                               continue;
+
+                       pos = i * 7;
+                       draw_activity_graphs(a, title, g_title, sndc->interface, group,
+                                            spmin + pos, spmax + pos, out + pos, outsize + pos,
+                                            svg_p, record_hdr);
+               }
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
+       }
+}
index b3e919e6f884aa7c1cafe773a17738b45d3bccbc..ff493330c1173066597cae9f0085d920f796b008 100644 (file)
@@ -20,5 +20,8 @@ __print_funct_t svg_print_pcsw_stats
 __print_funct_t svg_print_paging_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);
+__print_funct_t svg_print_net_dev_stats
+       (struct activity *, int, int, struct svg_parm *, unsigned long long,
+        struct record_header *);
        
 #endif /* _SVG_STATS_H */