From c73f52338d9c17e329397b5f1207fe1ecf4b7568 Mon Sep 17 00:00:00 2001 From: Stewart Thomson Date: Fri, 12 Jul 2019 14:54:20 -0400 Subject: [PATCH 1/3] Added thermal zone information and documentation --- README.md | 1 + collector/thermalzone.go | 105 ++++++++++++++++++++++++++++++++++ docs/collector.thermalzone.md | 31 ++++++++++ 3 files changed, 137 insertions(+) create mode 100644 collector/thermalzone.go create mode 100644 docs/collector.thermalzone.md diff --git a/README.md b/README.md index 827db57b..0f73b644 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Name | Description | Enabled by default [service](docs/collector.service.md) | Service state metrics | ✓ [system](docs/collector.system.md) | System calls | ✓ [tcp](docs/collector.tcp.md) | TCP connections | +[thermalzone](docs/collector.thermalzone.md) | Thermal information [textfile](docs/collector.textfile.md) | Read prometheus metrics from a text file | ✓ [vmware](docs/collector.vmware.md) | Performance counters installed by the Vmware Guest agent | diff --git a/collector/thermalzone.go b/collector/thermalzone.go new file mode 100644 index 00000000..bb90a940 --- /dev/null +++ b/collector/thermalzone.go @@ -0,0 +1,105 @@ +package collector + +import ( + "github.com/StackExchange/wmi" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/log" +) + +func init() { + Factories["thermalzone"] = NewThermalZoneCollector +} + +// A ThermalZoneCollector is a Prometheus collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics +type ThermalZoneCollector struct { + HighPrecisionTemperature *prometheus.Desc + PercentPassiveLimit *prometheus.Desc + Temperature *prometheus.Desc + ThrottleReasons *prometheus.Desc +} + +// NewThermalZoneCollector ... +func NewThermalZoneCollector() (Collector, error) { + const subsystem = "thermalzone" + return &ThermalZoneCollector{ + HighPrecisionTemperature: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "high_precision_temperature"), + "(HighPrecisionTemperature)", + nil, + nil, + ), + PercentPassiveLimit: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "percent_passive_limit"), + "(PercentPassiveLimit)", + nil, + nil, + ), + Temperature: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "temperature"), + "(Temperature)", + nil, + nil, + ), + ThrottleReasons: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "throttle_reasons"), + "(ThrottleReasons)", + nil, + nil, + ), + }, nil +} + +// Collect sends the metric values for each metric +// to the provided prometheus Metric channel. +func (c *ThermalZoneCollector) Collect(ch chan<- prometheus.Metric) error { + if desc, err := c.collect(ch); err != nil { + log.Error("failed collecting thermalzone metrics:", desc, err) + return err + } + return nil +} + +// Win32_PerfRawData_Counters_ThermalZoneInformation docs: +// - +type Win32_PerfRawData_Counters_ThermalZoneInformation struct { + Name string + + HighPrecisionTemperature uint32 + PercentPassiveLimit uint32 + Temperature uint32 + ThrottleReasons uint32 +} + +func (c *ThermalZoneCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { + var dst []Win32_PerfRawData_Counters_ThermalZoneInformation + q := queryAll(&dst) + if err := wmi.Query(q, &dst); err != nil { + return nil, err + } + + ch <- prometheus.MustNewConstMetric( + c.HighPrecisionTemperature, + prometheus.GaugeValue, + float64(dst[0].HighPrecisionTemperature), + ) + + ch <- prometheus.MustNewConstMetric( + c.PercentPassiveLimit, + prometheus.GaugeValue, + float64(dst[0].PercentPassiveLimit), + ) + + ch <- prometheus.MustNewConstMetric( + c.Temperature, + prometheus.GaugeValue, + float64(dst[0].Temperature), + ) + + ch <- prometheus.MustNewConstMetric( + c.ThrottleReasons, + prometheus.GaugeValue, + float64(dst[0].ThrottleReasons), + ) + + return nil, nil +} diff --git a/docs/collector.thermalzone.md b/docs/collector.thermalzone.md new file mode 100644 index 00000000..5a054ffd --- /dev/null +++ b/docs/collector.thermalzone.md @@ -0,0 +1,31 @@ +# tcp collector + +The thermalzone collector exposes metrics about system temps. Note that temperature is given in Kelvin + +||| +-|- +Metric name prefix | `thermalzone` +Classes | [`Win32_PerfRawData_Counters_ThermalZoneInformation`](https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx) +Enabled by default? | No + +## Flags + +None + +## Metrics + +Name | Description | Type | Labels +-----|-------------|------|------- +`wmi_thermalzone_high_precision_temperature` | _Not yet documented_ | gauge | None +`wmi_thermalzone_percent_passive_limit` | _Not yet documented_ | gauge | None +`wmi_thermalzone_temperature ` | _Not yet documented_ | gauge | None +`wmi_thermalzone_throttle_reasons ` | _Not yet documented_ | gauge | None + +### Example metric +_This collector does not yet have explained examples, we would appreciate your help adding them!_ + +## Useful queries +_This collector does not yet have any useful queries added, we would appreciate your help adding them!_ + +## Alerting examples +_This collector does not yet have alerting examples, we would appreciate your help adding them!_ From 1a67ca54b6ecfb68840242d55ffe4be626213712 Mon Sep 17 00:00:00 2001 From: Stewart Thomson Date: Sat, 13 Jul 2019 08:55:10 -0400 Subject: [PATCH 2/3] Update collector.thermalzone.md Removed references to tcp in collector.thermalzone.md --- docs/collector.thermalzone.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/collector.thermalzone.md b/docs/collector.thermalzone.md index 5a054ffd..96ceac34 100644 --- a/docs/collector.thermalzone.md +++ b/docs/collector.thermalzone.md @@ -1,11 +1,11 @@ -# tcp collector +# thermalzone collector The thermalzone collector exposes metrics about system temps. Note that temperature is given in Kelvin ||| -|- Metric name prefix | `thermalzone` -Classes | [`Win32_PerfRawData_Counters_ThermalZoneInformation`](https://msdn.microsoft.com/en-us/library/aa394341(v=vs.85).aspx) +Classes | [`Win32_PerfRawData_Counters_ThermalZoneInformation`](https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_thermalzoneinformation/#temperature_properties) Enabled by default? | No ## Flags From 47656b16bd681ca0d9d2adf8d9d38eb4b9bf6083 Mon Sep 17 00:00:00 2001 From: Stewart Thomson Date: Mon, 15 Jul 2019 09:50:02 -0400 Subject: [PATCH 3/3] - Removed HighPrecisionTemperature property and just mapped it to Temperature - Converted decikelvin to Celsius - Added a loop to get the values from each zone - Added documentation for percent passive limit and throttle reasons --- collector/thermalzone.go | 76 +++++++++++++++++------------------ docs/collector.thermalzone.md | 9 +++-- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/collector/thermalzone.go b/collector/thermalzone.go index bb90a940..99693a55 100644 --- a/collector/thermalzone.go +++ b/collector/thermalzone.go @@ -12,38 +12,37 @@ func init() { // A ThermalZoneCollector is a Prometheus collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics type ThermalZoneCollector struct { - HighPrecisionTemperature *prometheus.Desc - PercentPassiveLimit *prometheus.Desc - Temperature *prometheus.Desc - ThrottleReasons *prometheus.Desc + PercentPassiveLimit *prometheus.Desc + Temperature *prometheus.Desc + ThrottleReasons *prometheus.Desc } // NewThermalZoneCollector ... func NewThermalZoneCollector() (Collector, error) { const subsystem = "thermalzone" return &ThermalZoneCollector{ - HighPrecisionTemperature: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, subsystem, "high_precision_temperature"), - "(HighPrecisionTemperature)", - nil, + Temperature: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "temperature_celsius"), + "(Temperature)", + []string{ + "Name", + }, nil, ), PercentPassiveLimit: prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "percent_passive_limit"), "(PercentPassiveLimit)", - nil, - nil, - ), - Temperature: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, subsystem, "temperature"), - "(Temperature)", - nil, + []string{ + "Name", + }, nil, ), ThrottleReasons: prometheus.NewDesc( prometheus.BuildFQName(Namespace, subsystem, "throttle_reasons"), "(ThrottleReasons)", - nil, + []string{ + "Name", + }, nil, ), }, nil @@ -60,13 +59,12 @@ func (c *ThermalZoneCollector) Collect(ch chan<- prometheus.Metric) error { } // Win32_PerfRawData_Counters_ThermalZoneInformation docs: -// - +// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_thermalzoneinformation/ type Win32_PerfRawData_Counters_ThermalZoneInformation struct { Name string HighPrecisionTemperature uint32 PercentPassiveLimit uint32 - Temperature uint32 ThrottleReasons uint32 } @@ -77,29 +75,29 @@ func (c *ThermalZoneCollector) collect(ch chan<- prometheus.Metric) (*prometheus return nil, err } - ch <- prometheus.MustNewConstMetric( - c.HighPrecisionTemperature, - prometheus.GaugeValue, - float64(dst[0].HighPrecisionTemperature), - ) + for _, info := range dst { + //Divide by 10 and subtract 273.15 to convert decikelvin to celsius + ch <- prometheus.MustNewConstMetric( + c.Temperature, + prometheus.GaugeValue, + (float64(info.HighPrecisionTemperature)/10.0)-273.15, + info.Name, + ) - ch <- prometheus.MustNewConstMetric( - c.PercentPassiveLimit, - prometheus.GaugeValue, - float64(dst[0].PercentPassiveLimit), - ) + ch <- prometheus.MustNewConstMetric( + c.PercentPassiveLimit, + prometheus.GaugeValue, + float64(info.PercentPassiveLimit), + info.Name, + ) - ch <- prometheus.MustNewConstMetric( - c.Temperature, - prometheus.GaugeValue, - float64(dst[0].Temperature), - ) - - ch <- prometheus.MustNewConstMetric( - c.ThrottleReasons, - prometheus.GaugeValue, - float64(dst[0].ThrottleReasons), - ) + ch <- prometheus.MustNewConstMetric( + c.ThrottleReasons, + prometheus.GaugeValue, + float64(info.ThrottleReasons), + info.Name, + ) + } return nil, nil } diff --git a/docs/collector.thermalzone.md b/docs/collector.thermalzone.md index 96ceac34..71f36c75 100644 --- a/docs/collector.thermalzone.md +++ b/docs/collector.thermalzone.md @@ -16,10 +16,11 @@ None Name | Description | Type | Labels -----|-------------|------|------- -`wmi_thermalzone_high_precision_temperature` | _Not yet documented_ | gauge | None -`wmi_thermalzone_percent_passive_limit` | _Not yet documented_ | gauge | None -`wmi_thermalzone_temperature ` | _Not yet documented_ | gauge | None -`wmi_thermalzone_throttle_reasons ` | _Not yet documented_ | gauge | None +`wmi_thermalzone_percent_passive_limit` | % Passive Limit is the current limit this thermal zone is placing on the devices it controls. A limit of 100% indicates the devices are unconstrained. A limit of 0% indicates the devices are fully constrained. | gauge | None +`wmi_thermalzone_temperature_celsius ` | Temperature of the thermal zone, in degrees Celsius. | gauge | None +`wmi_thermalzone_throttle_reasons ` | Throttle Reasons indicate reasons why the thermal zone is limiting performance of the devices it controls. 0x0 – The zone is not throttled. 0x1 – The zone is throttled for thermal reasons. 0x2 – The zone is throttled to limit electrical current. | gauge | None + +[`Throttle reasons` source](https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/examples--requirements-and-diagnostics) ### Example metric _This collector does not yet have explained examples, we would appreciate your help adding them!_