]> granicus.if.org Git - sysstat/commitdiff
sadf: PCP: Add support for A_PWR_FAN activity
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 May 2019 14:04:58 +0000 (16:04 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 May 2019 14:04:58 +0000 (16:04 +0200)
Add metrics displayed by "sar -m FAN" (fan 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 c30089529bd693612b0d927eff3222c4ba8207eb..46f01fe4a393e7129c20f2ff03b6c7e1cd7cd302 100644 (file)
@@ -1484,6 +1484,7 @@ struct activity pwr_fan_act = {
        .f_json_print   = json_print_pwr_fan_stats,
        .f_svg_print    = svg_print_pwr_fan_stats,
        .f_raw_print    = raw_print_pwr_fan_stats,
+       .f_pcp_print    = pcp_print_pwr_fan_stats,
        .f_count_new    = NULL,
        .item_list      = NULL,
        .desc           = "Fans speed",
index 262722c7ed1556d49a174c5eb28d3a27cdf8519c..47f83d5c045ac2e739d71bb47a20c94f65348c4f 100644 (file)
@@ -1487,6 +1487,45 @@ void pcp_def_huge_metrics()
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Define PCP metrics for fan statistics.
+ *
+ * IN:
+ * @a          Activity structure with statistics.
+ ***************************************************************************
+ */
+void pcp_def_pwr_fan_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_FAN);
+
+               for (inst = 0; inst < a->item_list_sz; inst++) {
+                       sprintf(buf, "fan%d", inst + 1);
+                       pmiAddInstance(indom, buf, inst);
+               }
+       }
+
+       pmiAddMetric("power.fan.rpm",
+                    PM_IN_NULL, PM_TYPE_U64, indom, PM_SEM_INSTANT,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.fan.drpm",
+                    PM_IN_NULL, PM_TYPE_U64, indom, PM_SEM_INSTANT,
+                    pmiUnits(0, 0, 0, 0, 0, 0));
+
+       pmiAddMetric("power.fan.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.
@@ -1508,7 +1547,7 @@ void pcp_def_pwr_usb_metrics(struct activity *a)
 
                for (inst = 0; inst < a->item_list_sz; inst++) {
                        sprintf(buf, "usb%d", inst);
-                       pmiAddInstance(indom,buf, inst);
+                       pmiAddInstance(indom, buf, inst);
                }
        }
 
index 383c32031579281b3d3366f4fff0016b71def8f0..e7d9e5927d8854e8a727a59326a5eb15fe42ef56 100644 (file)
@@ -41,6 +41,7 @@ void pcp_def_net_icmp6_metrics(void);
 void pcp_def_net_eicmp6_metrics(void);
 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_usb_metrics(struct activity *);
 void pcp_def_filesystem_metrics(struct activity *);
 void pcp_def_fchost_metrics(struct activity *);
@@ -55,6 +56,7 @@ void pcp_def_fchost_metrics(struct activity *);
 #define PM_INDOM_FCHOST                6
 #define PM_INDOM_USB           7
 #define PM_INDOM_DISK          8
+#define PM_INDOM_FAN           9
 
 
 #endif /* _PCP_DEF_METRICS_H */
index f30bd7c4aa1804ff7509e44cc3777166906e8d8c..6c05876ed9cc0ab4ce717f80a9cbc574281512aa 100644 (file)
@@ -1820,6 +1820,45 @@ __print_funct_t pcp_print_pwr_cpufreq_stats(struct activity *a, int curr, unsign
 #endif /* HAVE_PCP */
 }
 
+/*
+ ***************************************************************************
+ * Display fan 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_fan_stats(struct activity *a, int curr, unsigned long long itv,
+                                       struct record_header *record_hdr)
+{
+#ifdef HAVE_PCP
+       int i;
+       struct stats_pwr_fan *spc;
+       char buf[64], instance[32];
+
+       for (i = 0; i < a->nr[curr]; i++) {
+
+               spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize);
+               sprintf(instance, "fan%d", i + 1);
+
+               snprintf(buf, sizeof(buf), "%llu",
+                        (unsigned long long) spc->rpm);
+               pmiPutValue("power.fan.rpm", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%llu",
+                        (unsigned long long) (spc->rpm - spc->rpm_min));
+               pmiPutValue("power.fan.drpm", instance, buf);
+
+               snprintf(buf, sizeof(buf), "%s",
+                       spc->device);
+               pmiPutValue("power.fan.device", instance, buf);
+       }
+#endif /* HAVE_PCP */
+}
+
 /*
  ***************************************************************************
  * Display huge pages statistics in PCP format.
index 970664da29eaa01e05c7f2888a07155eb56aea2c..be9a034072f7b386a6a18f3ae027a3cc031d80f8 100644 (file)
@@ -73,6 +73,8 @@ __print_funct_t pcp_print_net_udp6_stats
        (struct activity *, int, unsigned long long, struct record_header *);
 __print_funct_t pcp_print_pwr_cpufreq_stats
        (struct activity *, int, unsigned long long, struct record_header *);
+__print_funct_t pcp_print_pwr_fan_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 8c33965f49f2ce8ed2a24e1873e3d0a6e191b9e5..868963700a55268e6eaee33215ea0980e7d4d589 100644 (file)
@@ -769,6 +769,10 @@ __printf_funct_t print_pcp_statistics(int *tab, int action, struct activity *act
                                        pcp_def_huge_metrics();
                                        break;
 
+                               case A_PWR_FAN:
+                                       pcp_def_pwr_fan_metrics(act[p]);
+                                       break;
+
                                case A_PWR_USB:
                                        pcp_def_pwr_usb_metrics(act[p]);
                                        break;