Skip to content

Commit

Permalink
sadf: PCP: Add support for A_NET_SOCK activity
Browse files Browse the repository at this point in the history
Add metrics displayed by "sar -n SOCK" (network sockets statistics) to
PCP archive.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
  • Loading branch information
sysstat committed Apr 6, 2019
1 parent 7ad8133 commit 92626df
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ struct activity net_sock_act = {
.f_json_print = json_print_net_sock_stats,
.f_svg_print = svg_print_net_sock_stats,
.f_raw_print = raw_print_net_sock_stats,
.f_pcp_print = pcp_print_net_sock_stats,
.f_count_new = NULL,
.item_list = NULL,
.desc = "IPv4 sockets statistics",
Expand Down
34 changes: 34 additions & 0 deletions pcp_def_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,40 @@ void pcp_def_net_nfsd_metrics(void)
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Define PCP metrics for network sockets statistics.
***************************************************************************
*/
void pcp_def_net_sock_metrics(void)
{
#ifdef HAVE_PCP
pmiAddMetric("network.socket.sock_inuse",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));

pmiAddMetric("network.socket.tcp_inuse",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));

pmiAddMetric("network.socket.udp_inuse",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));

pmiAddMetric("network.socket.raw_inuse",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));

pmiAddMetric("network.socket.frag_inuse",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));

pmiAddMetric("network.socket.tcp_tw",
PM_IN_NULL, PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
pmiUnits(0, 0, 1, 0, 0, PM_COUNT_ONE));
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Define PCP metrics for IP network statistics.
Expand Down
1 change: 1 addition & 0 deletions pcp_def_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void pcp_def_serial_metrics(struct activity *);
void pcp_def_net_dev_metrics(struct activity *);
void pcp_def_net_nfs_metrics(void);
void pcp_def_net_nfsd_metrics(void);
void pcp_def_net_sock_metrics(void);
void pcp_def_net_ip_metrics(void);
void pcp_def_net_eip_metrics(void);
void pcp_def_net_icmp_metrics(void);
Expand Down
39 changes: 39 additions & 0 deletions pcp_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,45 @@ __print_funct_t pcp_print_net_nfsd_stats(struct activity *a, int curr, unsigned
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Display network sockets statistics in PCP format.
*
* IN:
* @a Activity structure with statistics.
* @curr Index in array for current sample statistics.
* @itv Interval of time in 1/100th of a second.
* @record_hdr Record header for current sample.
***************************************************************************
*/
__print_funct_t pcp_print_net_sock_stats(struct activity *a, int curr, unsigned long long itv,
struct record_header *record_hdr)
{
#ifdef HAVE_PCP
char buf[64];
struct stats_net_sock
*snsc = (struct stats_net_sock *) a->buf[curr];

snprintf(buf, sizeof(buf), "%u", snsc->sock_inuse);
pmiPutValue("network.socket.sock_inuse", NULL, buf);

snprintf(buf, sizeof(buf), "%u", snsc->tcp_inuse);
pmiPutValue("network.socket.tcp_inuse", NULL, buf);

snprintf(buf, sizeof(buf), "%u", snsc->udp_inuse);
pmiPutValue("network.socket.udp_inuse", NULL, buf);

snprintf(buf, sizeof(buf), "%u", snsc->raw_inuse);
pmiPutValue("network.socket.raw_inuse", NULL, buf);

snprintf(buf, sizeof(buf), "%u", snsc->frag_inuse);
pmiPutValue("network.socket.frag_inuse", NULL, buf);

snprintf(buf, sizeof(buf), "%u", snsc->tcp_tw);
pmiPutValue("network.socket.tcp_tw", NULL, buf);
#endif /* HAVE_PCP */
}

/*
***************************************************************************
* Display IP network statistics in PCP format.
Expand Down
2 changes: 2 additions & 0 deletions pcp_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ __print_funct_t pcp_print_net_nfs_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_nfsd_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_sock_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_ip_stats
(struct activity *, int, unsigned long long, struct record_header *);
__print_funct_t pcp_print_net_eip_stats
Expand Down
4 changes: 4 additions & 0 deletions sadf_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
pcp_def_net_nfsd_metrics();
break;

case A_NET_SOCK:
pcp_def_net_sock_metrics();
break;

case A_NET_IP:
pcp_def_net_ip_metrics();
break;
Expand Down

0 comments on commit 92626df

Please sign in to comment.