From dcf740adbc6f5e4ebafc1d29f55d7a42b636db8e Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 29 Mar 2019 07:34:30 +0100 Subject: [PATCH] sadf: PCP: Add support for A_NET_IP and A_NET_EIP activities Add metrics displayed by "sar -n IP" and "sar -n EIP" (network IP statistics) to PCP archive. Signed-off-by: Sebastien GODARD --- activity.c | 2 + pcp_def_metrics.c | 84 ++++++++++++++++++++++++++++++++++++ pcp_def_metrics.h | 2 + pcp_stats.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++ pcp_stats.h | 4 ++ sadf_misc.c | 8 ++++ 6 files changed, 208 insertions(+) diff --git a/activity.c b/activity.c index 45a32198..0df8e208 100644 --- a/activity.c +++ b/activity.c @@ -831,6 +831,7 @@ struct activity net_ip_act = { .f_json_print = json_print_net_ip_stats, .f_svg_print = svg_print_net_ip_stats, .f_raw_print = raw_print_net_ip_stats, + .f_pcp_print = pcp_print_net_ip_stats, .f_count_new = NULL, .item_list = NULL, .desc = "IPv4 traffic statistics", @@ -876,6 +877,7 @@ struct activity net_eip_act = { .f_json_print = json_print_net_eip_stats, .f_svg_print = svg_print_net_eip_stats, .f_raw_print = raw_print_net_eip_stats, + .f_pcp_print = pcp_print_net_eip_stats, .f_count_new = NULL, .item_list = NULL, .desc = "IPv4 traffic errors statistics", diff --git a/pcp_def_metrics.c b/pcp_def_metrics.c index ffa1a9aa..1ced8b2c 100644 --- a/pcp_def_metrics.c +++ b/pcp_def_metrics.c @@ -686,3 +686,87 @@ void pcp_def_net_nfsd_metrics(void) pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); #endif /* HAVE_PCP */ } + +/* + *************************************************************************** + * Define PCP metrics for IP network statistics. + *************************************************************************** + */ +void pcp_def_net_ip_metrics(void) +{ +#ifdef HAVE_PCP + pmiAddMetric("network.snmp.ip.ipInReceives", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipForwDatagrams", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipInDelivers", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipOutRequests", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipReasmReqds", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipReasmOKs", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipFragOKs", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipFragCreates", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); +#endif /* HAVE_PCP */ +} + +/* + *************************************************************************** + * Define PCP metrics for IP network errors statistics. + *************************************************************************** + */ +void pcp_def_net_eip_metrics(void) +{ +#ifdef HAVE_PCP + pmiAddMetric("network.snmp.ip.ipInHdrErrors", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipInAddrErrors", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipInUnknownProtos", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipInDiscards", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipOutDiscards", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipOutNoRoutes", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipReasmFails", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); + + pmiAddMetric("network.snmp.ip.ipFragFails", + PM_IN_NULL, PM_TYPE_FLOAT, PM_INDOM_NULL, PM_SEM_INSTANT, + pmiUnits(0, -1, 1, 0, PM_TIME_SEC, PM_COUNT_ONE)); +#endif /* HAVE_PCP */ +} diff --git a/pcp_def_metrics.h b/pcp_def_metrics.h index a1a555f9..a0374960 100644 --- a/pcp_def_metrics.h +++ b/pcp_def_metrics.h @@ -25,6 +25,8 @@ 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_ip_metrics(void); +void pcp_def_net_eip_metrics(void); /* Define domains number */ #define PM_INDOM_CPU 0 diff --git a/pcp_stats.c b/pcp_stats.c index 88b68389..784988ad 100644 --- a/pcp_stats.c +++ b/pcp_stats.c @@ -904,3 +904,111 @@ __print_funct_t pcp_print_net_nfsd_stats(struct activity *a, int curr, unsigned pmiPutValue("network.fs.server.getattr", NULL, buf); #endif /* HAVE_PCP */ } + +/* + *************************************************************************** + * Display IP network 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_ip_stats(struct activity *a, int curr, unsigned long long itv, + struct record_header *record_hdr) +{ +#ifdef HAVE_PCP + char buf[64]; + struct stats_net_ip + *snic = (struct stats_net_ip *) a->buf[curr], + *snip = (struct stats_net_ip *) a->buf[!curr]; + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->InReceives, snic->InReceives, itv)); + pmiPutValue("network.snmp.ip.ipInReceives", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->ForwDatagrams, snic->ForwDatagrams, itv)); + pmiPutValue("network.snmp.ip.ipForwDatagrams", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->InDelivers, snic->InDelivers, itv)); + pmiPutValue("network.snmp.ip.ipInDelivers", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->OutRequests, snic->OutRequests, itv)); + pmiPutValue("network.snmp.ip.ipOutRequests", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->ReasmReqds, snic->ReasmReqds, itv)); + pmiPutValue("network.snmp.ip.ipReasmReqds", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->ReasmOKs, snic->ReasmOKs, itv)); + pmiPutValue("network.snmp.ip.ipReasmOKs", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->FragOKs, snic->FragOKs, itv)); + pmiPutValue("network.snmp.ip.ipFragOKs", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(snip->FragCreates, snic->FragCreates, itv)); + pmiPutValue("network.snmp.ip.ipFragCreates", NULL, buf); +#endif /* HAVE_PCP */ +} + +/* + *************************************************************************** + * Display IP network errors 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_eip_stats(struct activity *a, int curr, unsigned long long itv, + struct record_header *record_hdr) +{ +#ifdef HAVE_PCP + char buf[64]; + struct stats_net_eip + *sneic = (struct stats_net_eip *) a->buf[curr], + *sneip = (struct stats_net_eip *) a->buf[!curr]; + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->InHdrErrors, sneic->InHdrErrors, itv)); + pmiPutValue("network.snmp.ip.ipInHdrErrors", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->InAddrErrors, sneic->InAddrErrors, itv)); + pmiPutValue("network.snmp.ip.ipInAddrErrors", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->InUnknownProtos, sneic->InUnknownProtos, itv)); + pmiPutValue("network.snmp.ip.ipInUnknownProtos", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->InDiscards, sneic->InDiscards, itv)); + pmiPutValue("network.snmp.ip.ipInDiscards", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->OutDiscards, sneic->OutDiscards, itv)); + pmiPutValue("network.snmp.ip.ipOutDiscards", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->OutNoRoutes, sneic->OutNoRoutes, itv)); + pmiPutValue("network.snmp.ip.ipOutNoRoutes", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->ReasmFails, sneic->ReasmFails, itv)); + pmiPutValue("network.snmp.ip.ipReasmFails", NULL, buf); + + snprintf(buf, sizeof(buf), "%f", + S_VALUE(sneip->FragFails, sneic->FragFails, itv)); + pmiPutValue("network.snmp.ip.ipFragFails", NULL, buf); +#endif /* HAVE_PCP */ +} diff --git a/pcp_stats.h b/pcp_stats.h index 60c3e36d..fd93d757 100644 --- a/pcp_stats.h +++ b/pcp_stats.h @@ -41,5 +41,9 @@ __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_ip_stats + (struct activity *, int, unsigned long long, struct record_header *); +__print_funct_t pcp_print_net_eip_stats + (struct activity *, int, unsigned long long, struct record_header *); #endif /* _PCP_STATS_H */ diff --git a/sadf_misc.c b/sadf_misc.c index 799f6aa8..79a18889 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -549,6 +549,14 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act case A_NET_NFSD: pcp_def_net_nfsd_metrics(); break; + + case A_NET_IP: + pcp_def_net_ip_metrics(); + break; + + case A_NET_EIP: + pcp_def_net_eip_metrics(); + break; } } }