aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--collector/fixtures/e2e-64k-page-output.txt4
-rw-r--r--collector/fixtures/e2e-output.txt4
-rw-r--r--collector/fixtures/sys.ttar30
-rw-r--r--collector/thermal_zone_linux.go68
-rwxr-xr-xend-to-end-test.sh1
6 files changed, 108 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c1893f..a131266 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
22* [BUGFIX] Renamed label `state` to `name` on `node_systemd_service_restart_total`. #1393 22* [BUGFIX] Renamed label `state` to `name` on `node_systemd_service_restart_total`. #1393
23* [BUGFIX] Fix netdev nil reference on Darwin #1414 23* [BUGFIX] Fix netdev nil reference on Darwin #1414
24* [BUGFIX] Strip path.rootfs from mountpoint labels #1421 24* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
25* [FEATURE] Add new thermal_zone collector #1425
25 26
26## 0.18.1 / 2019-06-04 27## 0.18.1 / 2019-06-04
27 28
diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt
index 5e83c60..b7e56ed 100644
--- a/collector/fixtures/e2e-64k-page-output.txt
+++ b/collector/fixtures/e2e-64k-page-output.txt
@@ -2488,6 +2488,7 @@ node_scrape_collector_success{collector="schedstat"} 1
2488node_scrape_collector_success{collector="sockstat"} 1 2488node_scrape_collector_success{collector="sockstat"} 1
2489node_scrape_collector_success{collector="stat"} 1 2489node_scrape_collector_success{collector="stat"} 1
2490node_scrape_collector_success{collector="textfile"} 1 2490node_scrape_collector_success{collector="textfile"} 1
2491node_scrape_collector_success{collector="thermal_zone"} 1
2491node_scrape_collector_success{collector="vmstat"} 1 2492node_scrape_collector_success{collector="vmstat"} 1
2492node_scrape_collector_success{collector="wifi"} 1 2493node_scrape_collector_success{collector="wifi"} 1
2493node_scrape_collector_success{collector="xfs"} 1 2494node_scrape_collector_success{collector="xfs"} 1
@@ -2539,6 +2540,9 @@ node_sockstat_sockets_used 229
2539# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise 2540# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
2540# TYPE node_textfile_scrape_error gauge 2541# TYPE node_textfile_scrape_error gauge
2541node_textfile_scrape_error 0 2542node_textfile_scrape_error 0
2543# HELP node_thermal_zone_temp Zone temperature in Celsius
2544# TYPE node_thermal_zone_temp gauge
2545node_thermal_zone_temp{type="cpu-thermal",zone="0"} 12.376
2542# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill. 2546# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill.
2543# TYPE node_vmstat_oom_kill untyped 2547# TYPE node_vmstat_oom_kill untyped
2544node_vmstat_oom_kill 0 2548node_vmstat_oom_kill 0
diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt
index 258e765..1d392d8 100644
--- a/collector/fixtures/e2e-output.txt
+++ b/collector/fixtures/e2e-output.txt
@@ -2488,6 +2488,7 @@ node_scrape_collector_success{collector="schedstat"} 1
2488node_scrape_collector_success{collector="sockstat"} 1 2488node_scrape_collector_success{collector="sockstat"} 1
2489node_scrape_collector_success{collector="stat"} 1 2489node_scrape_collector_success{collector="stat"} 1
2490node_scrape_collector_success{collector="textfile"} 1 2490node_scrape_collector_success{collector="textfile"} 1
2491node_scrape_collector_success{collector="thermal_zone"} 1
2491node_scrape_collector_success{collector="vmstat"} 1 2492node_scrape_collector_success{collector="vmstat"} 1
2492node_scrape_collector_success{collector="wifi"} 1 2493node_scrape_collector_success{collector="wifi"} 1
2493node_scrape_collector_success{collector="xfs"} 1 2494node_scrape_collector_success{collector="xfs"} 1
@@ -2539,6 +2540,9 @@ node_sockstat_sockets_used 229
2539# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise 2540# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
2540# TYPE node_textfile_scrape_error gauge 2541# TYPE node_textfile_scrape_error gauge
2541node_textfile_scrape_error 0 2542node_textfile_scrape_error 0
2543# HELP node_thermal_zone_temp Zone temperature in Celsius
2544# TYPE node_thermal_zone_temp gauge
2545node_thermal_zone_temp{type="cpu-thermal",zone="0"} 12.376
2542# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill. 2546# HELP node_vmstat_oom_kill /proc/vmstat information field oom_kill.
2543# TYPE node_vmstat_oom_kill untyped 2547# TYPE node_vmstat_oom_kill untyped
2544node_vmstat_oom_kill 0 2548node_vmstat_oom_kill 0
diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar
index ee30c81..2880390 100644
--- a/collector/fixtures/sys.ttar
+++ b/collector/fixtures/sys.ttar
@@ -920,6 +920,12 @@ Lines: 1
9201 9201
921Mode: 644 921Mode: 644
922# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 922# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
923Directory: sys/class/thermal
924Mode: 755
925# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
926Path: sys/class/thermal/thermal_zone0
927SymlinkTo: ../../devices/virtual/thermal/thermal_zone0
928# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
923Directory: sys/devices 929Directory: sys/devices
924Mode: 755 930Mode: 755
925# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 931# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -2460,6 +2466,30 @@ local_node 26719046550
2460other_node 9860526920 2466other_node 9860526920
2461Mode: 644 2467Mode: 644
2462# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2468# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2469Directory: sys/devices/virtual
2470Mode: 755
2471# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2472Directory: sys/devices/virtual/thermal
2473Mode: 755
2474# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2475Directory: sys/devices/virtual/thermal/thermal_zone0
2476Mode: 755
2477# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2478Path: sys/devices/virtual/thermal/thermal_zone0/policy
2479Lines: 1
2480step_wise
2481Mode: 644
2482# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2483Path: sys/devices/virtual/thermal/thermal_zone0/temp
2484Lines: 1
248512376
2486Mode: 644
2487# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2488Path: sys/devices/virtual/thermal/thermal_zone0/type
2489Lines: 1
2490cpu-thermal
2491Mode: 644
2492# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2463Directory: sys/fs 2493Directory: sys/fs
2464Mode: 755 2494Mode: 755
2465# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2495# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/collector/thermal_zone_linux.go b/collector/thermal_zone_linux.go
new file mode 100644
index 0000000..16fe61c
--- /dev/null
+++ b/collector/thermal_zone_linux.go
@@ -0,0 +1,68 @@
1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// +build !nothermalzone
15
16package collector
17
18import (
19 "fmt"
20
21 "github.com/prometheus/client_golang/prometheus"
22 "github.com/prometheus/procfs/sysfs"
23)
24
25type thermalZoneCollector struct {
26 fs sysfs.FS
27 zoneTemp *prometheus.Desc
28}
29
30func init() {
31 registerCollector("thermal_zone", defaultEnabled, NewThermalZoneCollector)
32}
33
34// NewThermalZoneCollector returns a new Collector exposing kernel/system statistics.
35func NewThermalZoneCollector() (Collector, error) {
36 fs, err := sysfs.NewFS(*sysPath)
37 if err != nil {
38 return nil, fmt.Errorf("failed to open sysfs: %v", err)
39 }
40
41 return &thermalZoneCollector{
42 fs: fs,
43 zoneTemp: prometheus.NewDesc(
44 prometheus.BuildFQName(namespace, "thermal_zone", "temp"),
45 "Zone temperature in Celsius",
46 []string{"zone", "type"}, nil,
47 ),
48 }, nil
49}
50
51func (c *thermalZoneCollector) Update(ch chan<- prometheus.Metric) error {
52 thermalZones, err := c.fs.ClassThermalZoneStats()
53 if err != nil {
54 return err
55 }
56
57 for _, stats := range thermalZones {
58 ch <- prometheus.MustNewConstMetric(
59 c.zoneTemp,
60 prometheus.GaugeValue,
61 float64(stats.Temp)/1000.0,
62 stats.Name,
63 stats.Type,
64 )
65 }
66
67 return nil
68}
diff --git a/end-to-end-test.sh b/end-to-end-test.sh
index 56ed04c..469b811 100755
--- a/end-to-end-test.sh
+++ b/end-to-end-test.sh
@@ -33,6 +33,7 @@ enabled_collectors=$(cat << COLLECTORS
33 schedstat 33 schedstat
34 sockstat 34 sockstat
35 stat 35 stat
36 thermal_zone
36 textfile 37 textfile
37 bonding 38 bonding
38 vmstat 39 vmstat