]> granicus.if.org Git - sysstat/commitdiff
sadf: PCP: Add support for A_PWR_IN activity
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 May 2019 14:31:12 +0000 (16:31 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 May 2019 14:31:12 +0000 (16:31 +0200)
Add metrics displayed by "sar -m IN" (voltage inputs statistics) to PCP
archive.

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

index 43853e611f694874a2381af05ea0e26d6fa245f0..52056dc54dd507d17e64a46a953e13c1d7fb7358 100644 (file)
@@ -1576,6 +1576,7 @@ struct activity pwr_in_act = {
        .f_json_print   = json_print_pwr_in_stats,
        .f_svg_print    = svg_print_pwr_in_stats,
        .f_raw_print    = raw_print_pwr_in_stats,
+       .f_pcp_print    = pcp_print_pwr_in_stats,
        .f_count_new    = NULL,
        .item_list      = NULL,
        .desc           = "Voltage inputs statistics",
index e1152c4e8cd3443de25ca40fa0fde483adb04dc1..bc1a4ab1b935e626da880548955af6f466f3d039 100644 (file)
@@ -1565,6 +1565,45 @@ void pcp_def_pwr_temp_metrics(struct activity *a)
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Define PCP metrics for voltage inputs statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ ***************************************************************************
+ */
+void pcp_def_pwr_in_metrics(struct activity *a)
+{
+#ifdef HAVE_PCP
+       int inst = 0;
+       static pmInDom indom = PM_INDOM_NULL;
+       char buf[16];
+
+       if (indom == PM_INDOM_NULL) {
+               /* Create domain */
+               indom = pmInDom_build(0, PM_INDOM_IN);
+
+               for (inst = 0; inst < a->item_list_sz; inst++) {
+                       sprintf(buf, "in%d", inst);
+                       pmiAddInstance(indom, buf, inst);
+               }
+       }
+
+       pmiAddMetric("power.in.inV",
+                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.in.in_pct",
+                    PM_IN_NULL, PM_TYPE_FLOAT, indom, PM_SEM_INSTANT,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.in.device",
+                    PM_IN_NULL, PM_TYPE_STRING, indom, PM_SEM_DISCRETE,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+#endif /* HAVE_PCP */
+}
+
 /*
  ***************************************************************************
  * Define PCP metrics for USB devices statistics.
index b51ddc5e05e37f70916c12d429d50a1562ae98c3..bc5cd89f8e9cb99783b62746283a7ee1d4ba0d54 100644 (file)
@@ -43,6 +43,7 @@ void pcp_def_net_udp6_metrics(void);
 void pcp_def_huge_metrics(void);
 void pcp_def_pwr_fan_metrics(struct activity *);
 void pcp_def_pwr_temp_metrics(struct activity *);
+void pcp_def_pwr_in_metrics(struct activity *);
 void pcp_def_pwr_usb_metrics(struct activity *);
 void pcp_def_filesystem_metrics(struct activity *);
 void pcp_def_fchost_metrics(struct activity *);
@@ -59,5 +60,6 @@ void pcp_def_fchost_metrics(struct activity *);
 #define PM_INDOM_DISK          8
 #define PM_INDOM_FAN           9
 #define PM_INDOM_TEMP          10
+#define PM_INDOM_IN            11
 
 #endif /* _PCP_DEF_METRICS_H */
index 843246ea4ade30176dd7cf0664dfa54441f0704f..836ab7bf9e34ef33f4c935dc8a83b477a0ac7eea 100644 (file)
@@ -1900,6 +1900,47 @@ __print_funct_t pcp_print_pwr_temp_stats(struct activity *a, int curr, unsigned
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Display voltage inputs 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_pwr_in_stats(struct activity *a, int curr, unsigned long long itv,
+                                      struct record_header *record_hdr)
+{
+#ifdef HAVE_PCP
+       int i;
+       struct stats_pwr_in *spc;
+       char buf[64], instance[32];
+
+       for (i = 0; i < a->nr[curr]; i++) {
+
+               spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize);
+               sprintf(instance, "in%d", i);
+
+               snprintf(buf, sizeof(buf), "%f",
+                        spc->in);
+               pmiPutValue("power.in.inV", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%f",
+                        (spc->in_max - spc->in_min) ?
+                        (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100 :
+                        0.0);
+               pmiPutValue("power.in.in_pct", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%s",
+                       spc->device);
+               pmiPutValue("power.in.device", instance, buf);
+       }
+#endif /* HAVE_PCP */
+}
+
 /*
  ***************************************************************************
  * Display huge pages statistics in PCP format.
index 5a37df566e664285e97d229e8d65bc298fb6f29b..8e21297e947ecf9d5653e69b83fa5f2f20908053 100644 (file)
@@ -77,6 +77,8 @@ __print_funct_t pcp_print_pwr_fan_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_pwr_temp_stats
        (struct activity *, int, unsigned long long, struct record_header *);
+__print_funct_t pcp_print_pwr_in_stats
+       (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_huge_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_pwr_usb_stats
index e4728435e82c6be4d3a8ca9d7b1fd0a66e271d9e..d1abca143eb91955fe84859c6064189124aebae5 100644 (file)
@@ -777,6 +777,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
                                        pcp_def_pwr_temp_metrics(act[p]);
                                        break;
 
+                               case A_PWR_IN:
+                                       pcp_def_pwr_in_metrics(act[p]);
+                                       break;
+
                                case A_PWR_USB:
                                        pcp_def_pwr_usb_metrics(act[p]);
                                        break;