]> granicus.if.org Git - sysstat/commitdiff
SVG: Add SVG output for network socket statistics
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 30 Apr 2016 13:36:21 +0000 (15:36 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 30 Apr 2016 13:36:21 +0000 (15:36 +0200)
These graphs correspond to the outpu of "sar -n SOCK".

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

index c1f32d14be628f2581d1f4d60eb6f36c0b5dda49..c07513168e38cc7e05bd017878f805fc8fb6fda9 100644 (file)
@@ -597,9 +597,10 @@ struct activity net_sock_act = {
        .f_render       = render_net_sock_stats,
        .f_xml_print    = xml_print_net_sock_stats,
        .f_json_print   = json_print_net_sock_stats,
+       .f_svg_print    = svg_print_net_sock_stats,
        .hdr_line       = "totsck;tcpsck;udpsck;rawsck;ip-frag;tcp-tw",
        .name           = "A_NET_SOCK",
-       .g_nr           = 0,
+       .g_nr           = 2,
 #endif
        .nr             = 1,
        .nr2            = 1,
index e69e05f076a10eccc7e4703df8abaf4ff1fc8ef5..3a09f0e5659581df09b842b1b3b31f4a45766e55 100644 (file)
@@ -1912,6 +1912,82 @@ __print_funct_t svg_print_net_dev_stats(struct activity *a, int curr, int action
        }
 }
 
+/*
+ ***************************************************************************
+ * Display network socket 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_sock_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_sock
+               *snsc = (struct stats_net_sock *) a->buf[curr];
+       int group[] = {1, 5};
+       char *title[] = {"Network sockets (1)", "Network sockets (2)"};
+       char *g_title[] = {"~totsck",
+                          "~tcpsck", "~tcp-tw", "~udpsck", "~rawsck", "~ip-frag"};
+       static double *spmin, *spmax;
+       static char **out;
+       static int *outsize;
+
+       if (action & F_BEGIN) {
+               /*
+                * Allocate arrays that will contain the graphs data
+                * and the min/max values.
+                */
+               out = allocate_graph_lines(6, &outsize, &spmin, &spmax);
+       }
+
+       if (action & F_MAIN) {
+               /* Check for min/max values */
+               save_extrema(0, 0, 6, (void *) a->buf[curr], NULL,
+                            itv, spmin, spmax);
+               /* totsck */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->sock_inuse,
+                         out, outsize, svg_p->restart);
+               /* tcpsck */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->tcp_inuse,
+                         out + 1, outsize + 1, svg_p->restart);
+               /* tcp-tw */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->tcp_tw,
+                         out + 2, outsize + 2, svg_p->restart);
+               /* udpsck */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->udp_inuse,
+                         out + 3, outsize + 3, svg_p->restart);
+               /* rawsck */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->raw_inuse,
+                         out + 4, outsize + 4, svg_p->restart);
+               /* ip-frag */
+               lniappend(record_hdr->ust_time - svg_p->record_hdr->ust_time,
+                         (unsigned long) snsc->frag_inuse,
+                         out + 5, outsize + 5, svg_p->restart);
+       }
+
+       if (action & F_END) {
+               draw_activity_graphs(a->g_nr, SVG_LINE_GRAPH, title, g_title, NULL, group,
+                                    spmin, spmax, out, outsize, svg_p, record_hdr);
+
+               /* Free remaining structures */
+               free_graphs(out, outsize, spmin, spmax);
+       }
+}
+
 /*
  ***************************************************************************
  * Display CPU frequency statistics in SVG.
index 2a048e9eda851862332ce74cb10f95ae0ffe8acc..7505fb9e2c66d6d29c3927fe5a0e49f016b7b209 100644 (file)
@@ -41,6 +41,9 @@ __print_funct_t svg_print_queue_stats
 __print_funct_t svg_print_net_dev_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);
+__print_funct_t svg_print_net_sock_stats
+       (struct activity *, int, int, struct svg_parm *, unsigned long long,
+        struct record_header *);
 __print_funct_t svg_print_pwr_cpufreq_stats
        (struct activity *, int, int, struct svg_parm *, unsigned long long,
         struct record_header *);