From c368a01e92a5cea80827d32f8854b6ca4e4b4599 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Fri, 5 Nov 2021 13:17:31 +0100 Subject: [PATCH 1/4] Add clocksource collector This closes #1336 Signed-off-by: Johannes 'fish' Ziemke --- collector/clocksource.go | 69 +++++++++++++++++++++++++++++++ collector/fixtures/e2e-output.txt | 9 ++++ collector/fixtures/sys.ttar | 20 +++++++-- 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 collector/clocksource.go diff --git a/collector/clocksource.go b/collector/clocksource.go new file mode 100644 index 0000000000..0200f03675 --- /dev/null +++ b/collector/clocksource.go @@ -0,0 +1,69 @@ +// Copyright 2021 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build linux && !noclocksource +// +build linux,!noclocksource + +package collector + +import ( + "fmt" + "strconv" + + "github.com/go-kit/log" + "github.com/go-kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/procfs/sysfs" +) + +type clockSourceCollector struct { + fs sysfs.FS + clocksourcesAvailable typedDesc + clocksourceCurrent typedDesc + logger log.Logger +} + +func init() { + registerCollector("clocksource", defaultEnabled, NewClockSourceCollector) +} + +// NewClockSourceCollector returns a new Collector exposing clocksource info metrics from /sys/devices/system/clocksource. +func NewClockSourceCollector(logger log.Logger) (Collector, error) { + fs, err := sysfs.NewFS(*sysPath) + if err != nil { + return nil, fmt.Errorf("failed to open procfs: %w", err) + } + return &clockSourceCollector{ + fs: fs, + clocksourcesAvailable: typedDesc{prometheus.NewDesc(namespace+"_clocksource_available_info", "Available clocksources read from '/sys/devices/system/clocksource'", []string{"device", "clocksource"}, nil), prometheus.GaugeValue}, + clocksourceCurrent: typedDesc{prometheus.NewDesc(namespace+"_clocksource_current_info", "Current clocksource read from '/sys/devices/system/clocksource'", []string{"device", "clocksource"}, nil), prometheus.GaugeValue}, + logger: logger, + }, nil +} + +func (c *clockSourceCollector) Update(ch chan<- prometheus.Metric) error { + clocksources, err := c.fs.ClockSources() + if err != nil { + return fmt.Errorf("couldn't get clocksources: %w", err) + } + level.Debug(c.logger).Log("msg", "in Update", "clocksources", fmt.Sprintf("%v", clocksources)) + + for i, clocksource := range clocksources { + is := strconv.Itoa(i) + for _, cs := range clocksource.Available { + ch <- c.clocksourcesAvailable.mustNewConstMetric(1.0, is, cs) + } + ch <- c.clocksourceCurrent.mustNewConstMetric(1.0, is, clocksource.Current) + } + return err +} diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 3219c84fa4..04c93ae3c4 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -238,6 +238,14 @@ node_buddyinfo_blocks{node="0",size="8",zone="Normal"} 0 node_buddyinfo_blocks{node="0",size="9",zone="DMA"} 1 node_buddyinfo_blocks{node="0",size="9",zone="DMA32"} 0 node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0 +# HELP node_clocksource_available_info Available clocksources read from '/sys/devices/system/clocksource' +# TYPE node_clocksource_available_info gauge +node_clocksource_available_info{clocksource="acpi_pm",device="0"} 1 +node_clocksource_available_info{clocksource="hpet",device="0"} 1 +node_clocksource_available_info{clocksource="tsc",device="0"} 1 +# HELP node_clocksource_current_info Current clocksource read from '/sys/devices/system/clocksource' +# TYPE node_clocksource_current_info gauge +node_clocksource_current_info{clocksource="tsc",device="0"} 1 # HELP node_context_switches_total Total number of context switches. # TYPE node_context_switches_total counter node_context_switches_total 3.8014093e+07 @@ -2970,6 +2978,7 @@ node_scrape_collector_success{collector="bcache"} 1 node_scrape_collector_success{collector="bonding"} 1 node_scrape_collector_success{collector="btrfs"} 1 node_scrape_collector_success{collector="buddyinfo"} 1 +node_scrape_collector_success{collector="clocksource"} 1 node_scrape_collector_success{collector="conntrack"} 1 node_scrape_collector_success{collector="cpu"} 1 node_scrape_collector_success{collector="cpufreq"} 1 diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar index 6e9ebe51ef..a08e6b6119 100644 --- a/collector/fixtures/sys.ttar +++ b/collector/fixtures/sys.ttar @@ -3213,6 +3213,22 @@ Mode: 644 Directory: sys/devices/system Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: sys/devices/system/clocksource +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: sys/devices/system/clocksource/clocksource0 +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/devices/system/clocksource/clocksource0/available_clocksource +Lines: 1 +tsc hpet acpi_pm +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/devices/system/clocksource/clocksource0/current_clocksource +Lines: 1 +tsc +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: sys/devices/system/cpu Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -4702,7 +4718,3 @@ Lines: 1 20 Mode: 644 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Path: sys/.unpacked -Lines: 0 -Mode: 644 -# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 294119eb630efb28544b5dda8a3e1fdd2f8f896e Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Wed, 10 Nov 2021 15:04:30 +0100 Subject: [PATCH 2/4] Move clocksource collector to time Signed-off-by: Johannes 'fish' Ziemke --- collector/clocksource.go | 69 ------------------------------ collector/fixtures/e2e-output.txt | 22 ++++++---- collector/time.go | 4 +- collector/time_linux.go | 71 +++++++++++++++++++++++++++++++ collector/time_other.go | 25 +++++++++++ end-to-end-test.sh | 3 +- 6 files changed, 113 insertions(+), 81 deletions(-) delete mode 100644 collector/clocksource.go create mode 100644 collector/time_linux.go create mode 100644 collector/time_other.go diff --git a/collector/clocksource.go b/collector/clocksource.go deleted file mode 100644 index 0200f03675..0000000000 --- a/collector/clocksource.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2021 The Prometheus Authors -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build linux && !noclocksource -// +build linux,!noclocksource - -package collector - -import ( - "fmt" - "strconv" - - "github.com/go-kit/log" - "github.com/go-kit/log/level" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/procfs/sysfs" -) - -type clockSourceCollector struct { - fs sysfs.FS - clocksourcesAvailable typedDesc - clocksourceCurrent typedDesc - logger log.Logger -} - -func init() { - registerCollector("clocksource", defaultEnabled, NewClockSourceCollector) -} - -// NewClockSourceCollector returns a new Collector exposing clocksource info metrics from /sys/devices/system/clocksource. -func NewClockSourceCollector(logger log.Logger) (Collector, error) { - fs, err := sysfs.NewFS(*sysPath) - if err != nil { - return nil, fmt.Errorf("failed to open procfs: %w", err) - } - return &clockSourceCollector{ - fs: fs, - clocksourcesAvailable: typedDesc{prometheus.NewDesc(namespace+"_clocksource_available_info", "Available clocksources read from '/sys/devices/system/clocksource'", []string{"device", "clocksource"}, nil), prometheus.GaugeValue}, - clocksourceCurrent: typedDesc{prometheus.NewDesc(namespace+"_clocksource_current_info", "Current clocksource read from '/sys/devices/system/clocksource'", []string{"device", "clocksource"}, nil), prometheus.GaugeValue}, - logger: logger, - }, nil -} - -func (c *clockSourceCollector) Update(ch chan<- prometheus.Metric) error { - clocksources, err := c.fs.ClockSources() - if err != nil { - return fmt.Errorf("couldn't get clocksources: %w", err) - } - level.Debug(c.logger).Log("msg", "in Update", "clocksources", fmt.Sprintf("%v", clocksources)) - - for i, clocksource := range clocksources { - is := strconv.Itoa(i) - for _, cs := range clocksource.Available { - ch <- c.clocksourcesAvailable.mustNewConstMetric(1.0, is, cs) - } - ch <- c.clocksourceCurrent.mustNewConstMetric(1.0, is, clocksource.Current) - } - return err -} diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 04c93ae3c4..adef65aa1b 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -238,14 +238,6 @@ node_buddyinfo_blocks{node="0",size="8",zone="Normal"} 0 node_buddyinfo_blocks{node="0",size="9",zone="DMA"} 1 node_buddyinfo_blocks{node="0",size="9",zone="DMA32"} 0 node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0 -# HELP node_clocksource_available_info Available clocksources read from '/sys/devices/system/clocksource' -# TYPE node_clocksource_available_info gauge -node_clocksource_available_info{clocksource="acpi_pm",device="0"} 1 -node_clocksource_available_info{clocksource="hpet",device="0"} 1 -node_clocksource_available_info{clocksource="tsc",device="0"} 1 -# HELP node_clocksource_current_info Current clocksource read from '/sys/devices/system/clocksource' -# TYPE node_clocksource_current_info gauge -node_clocksource_current_info{clocksource="tsc",device="0"} 1 # HELP node_context_switches_total Total number of context switches. # TYPE node_context_switches_total counter node_context_switches_total 3.8014093e+07 @@ -2978,7 +2970,6 @@ node_scrape_collector_success{collector="bcache"} 1 node_scrape_collector_success{collector="bonding"} 1 node_scrape_collector_success{collector="btrfs"} 1 node_scrape_collector_success{collector="buddyinfo"} 1 -node_scrape_collector_success{collector="clocksource"} 1 node_scrape_collector_success{collector="conntrack"} 1 node_scrape_collector_success{collector="cpu"} 1 node_scrape_collector_success{collector="cpufreq"} 1 @@ -3019,6 +3010,7 @@ node_scrape_collector_success{collector="stat"} 1 node_scrape_collector_success{collector="tapestats"} 1 node_scrape_collector_success{collector="textfile"} 1 node_scrape_collector_success{collector="thermal_zone"} 1 +node_scrape_collector_success{collector="time"} 1 node_scrape_collector_success{collector="udp_queues"} 1 node_scrape_collector_success{collector="vmstat"} 1 node_scrape_collector_success{collector="wifi"} 1 @@ -3141,6 +3133,18 @@ node_textfile_scrape_error 0 # HELP node_thermal_zone_temp Zone temperature in Celsius # TYPE node_thermal_zone_temp gauge node_thermal_zone_temp{type="cpu-thermal",zone="0"} 12.376 +# HELP node_time_clocksource_available_info Available clocksources read from '/sys/devices/system/clocksource' +# TYPE node_time_clocksource_available_info gauge +node_time_clocksource_available_info{clocksource="acpi_pm",device="0"} 1 +node_time_clocksource_available_info{clocksource="hpet",device="0"} 1 +node_time_clocksource_available_info{clocksource="tsc",device="0"} 1 +# HELP node_time_clocksource_current_info Current clocksource read from '/sys/devices/system/clocksource' +# TYPE node_time_clocksource_current_info gauge +node_time_clocksource_current_info{clocksource="tsc",device="0"} 1 +# HELP node_time_seconds System time in seconds since epoch (1970). +# TYPE node_time_seconds gauge +# HELP node_time_zone_offset_seconds System time zone offset in seconds. +# TYPE node_time_zone_offset_seconds gauge # HELP node_udp_queues Number of allocated memory in the kernel for UDP datagrams in bytes. # TYPE node_udp_queues gauge node_udp_queues{ip="v4",queue="rx"} 0 diff --git a/collector/time.go b/collector/time.go index 34c5aad25b..e2e5260d8e 100644 --- a/collector/time.go +++ b/collector/time.go @@ -22,12 +22,14 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/procfs/sysfs" ) type timeCollector struct { nowDesc *prometheus.Desc zoneDesc *prometheus.Desc logger log.Logger + sysfs *sysfs.FS } func init() { @@ -62,5 +64,5 @@ func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.nowDesc, prometheus.GaugeValue, nowSec) level.Debug(c.logger).Log("msg", "Zone offset", "offset", zoneOffset, "time_zone", zone) ch <- prometheus.MustNewConstMetric(c.zoneDesc, prometheus.GaugeValue, float64(zoneOffset), zone) - return nil + return c.update(ch) } diff --git a/collector/time_linux.go b/collector/time_linux.go new file mode 100644 index 0000000000..12975d3752 --- /dev/null +++ b/collector/time_linux.go @@ -0,0 +1,71 @@ +// Copyright 2021 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build linux && !notime +// +build linux,!notime + +package collector + +import ( + "fmt" + "strconv" + + "github.com/go-kit/log/level" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/procfs/sysfs" +) + +func (c *timeCollector) update(ch chan<- prometheus.Metric) error { + if c.sysfs == nil { + fs, err := sysfs.NewFS(*sysPath) + if err != nil { + return fmt.Errorf("failed to open procfs: %w", err) + } + c.sysfs = &fs + } + + clocksources, err := c.sysfs.ClockSources() + if err != nil { + return fmt.Errorf("couldn't get clocksources: %w", err) + } + level.Debug(c.logger).Log("msg", "in Update", "clocksources", fmt.Sprintf("%v", clocksources)) + + for i, clocksource := range clocksources { + is := strconv.Itoa(i) + for _, cs := range clocksource.Available { + ch <- prometheus.MustNewConstMetric( + prometheus.NewDesc( + namespace+"_time_clocksource_available_info", + "Available clocksources read from '/sys/devices/system/clocksource'", + []string{"device", "clocksource"}, + nil), + prometheus.GaugeValue, + 1.0, + is, + cs, + ) + } + ch <- prometheus.MustNewConstMetric( + prometheus.NewDesc( + namespace+"_time_clocksource_current_info", + "Current clocksource read from '/sys/devices/system/clocksource'", + []string{"device", "clocksource"}, + nil), + prometheus.GaugeValue, + 1.0, + is, + clocksource.Current, + ) + } + return nil +} diff --git a/collector/time_other.go b/collector/time_other.go new file mode 100644 index 0000000000..8227435bd9 --- /dev/null +++ b/collector/time_other.go @@ -0,0 +1,25 @@ +// Copyright 2021 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build !linux && !notime +// +build !linux,!notime + +package collector + +import ( + "github.com/prometheus/client_golang/prometheus" +) + +func (c *timeCollector) update(ch chan<- prometheus.Metric) error { + return nil +} diff --git a/end-to-end-test.sh b/end-to-end-test.sh index 8739e6b67f..f024890de1 100755 --- a/end-to-end-test.sh +++ b/end-to-end-test.sh @@ -51,7 +51,6 @@ COLLECTORS ) disabled_collectors=$(cat << COLLECTORS filesystem - time timex uname COLLECTORS @@ -61,7 +60,7 @@ cd "$(dirname $0)" port="$((10000 + (RANDOM % 10000)))" tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX) -skip_re="^(go_|node_exporter_build_info|node_scrape_collector_duration_seconds|process_|node_textfile_mtime_seconds)" +skip_re="^(go_|node_exporter_build_info|node_scrape_collector_duration_seconds|process_|node_textfile_mtime_seconds|node_time_(zone|seconds))" arch="$(uname -m)" From d48ea725dc9e59754893f926f234d139131acbcf Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Thu, 11 Nov 2021 11:21:46 +0100 Subject: [PATCH 3/4] Move typedDesc to timeCollector Signed-off-by: Johannes 'fish' Ziemke --- collector/fixtures/e2e-output.txt | 4 ++-- collector/time.go | 32 +++++++++++++++++++++---------- collector/time_linux.go | 24 ++--------------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index adef65aa1b..81e1f55b79 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -3133,12 +3133,12 @@ node_textfile_scrape_error 0 # HELP node_thermal_zone_temp Zone temperature in Celsius # TYPE node_thermal_zone_temp gauge node_thermal_zone_temp{type="cpu-thermal",zone="0"} 12.376 -# HELP node_time_clocksource_available_info Available clocksources read from '/sys/devices/system/clocksource' +# HELP node_time_clocksource_available_info Available clocksources read from '/sys/devices/system/clocksource'. # TYPE node_time_clocksource_available_info gauge node_time_clocksource_available_info{clocksource="acpi_pm",device="0"} 1 node_time_clocksource_available_info{clocksource="hpet",device="0"} 1 node_time_clocksource_available_info{clocksource="tsc",device="0"} 1 -# HELP node_time_clocksource_current_info Current clocksource read from '/sys/devices/system/clocksource' +# HELP node_time_clocksource_current_info Current clocksource read from '/sys/devices/system/clocksource'. # TYPE node_time_clocksource_current_info gauge node_time_clocksource_current_info{clocksource="tsc",device="0"} 1 # HELP node_time_seconds System time in seconds since epoch (1970). diff --git a/collector/time.go b/collector/time.go index e2e5260d8e..27fba9f671 100644 --- a/collector/time.go +++ b/collector/time.go @@ -26,10 +26,12 @@ import ( ) type timeCollector struct { - nowDesc *prometheus.Desc - zoneDesc *prometheus.Desc - logger log.Logger - sysfs *sysfs.FS + now typedDesc + zone typedDesc + clocksourcesAvailable typedDesc + clocksourceCurrent typedDesc + logger log.Logger + sysfs *sysfs.FS } func init() { @@ -41,16 +43,26 @@ func init() { func NewTimeCollector(logger log.Logger) (Collector, error) { const subsystem = "time" return &timeCollector{ - nowDesc: prometheus.NewDesc( + now: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, subsystem, "seconds"), "System time in seconds since epoch (1970).", nil, nil, - ), - zoneDesc: prometheus.NewDesc( + ), prometheus.GaugeValue}, + zone: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, subsystem, "zone_offset_seconds"), "System time zone offset in seconds.", []string{"time_zone"}, nil, - ), + ), prometheus.GaugeValue}, + clocksourcesAvailable: typedDesc{prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "clocksource_available_info"), + "Available clocksources read from '/sys/devices/system/clocksource'.", + []string{"device", "clocksource"}, nil, + ), prometheus.GaugeValue}, + clocksourceCurrent: typedDesc{prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "clocksource_current_info"), + "Current clocksource read from '/sys/devices/system/clocksource'.", + []string{"device", "clocksource"}, nil, + ), prometheus.GaugeValue}, logger: logger, }, nil } @@ -61,8 +73,8 @@ func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { zone, zoneOffset := now.Zone() level.Debug(c.logger).Log("msg", "Return time", "now", nowSec) - ch <- prometheus.MustNewConstMetric(c.nowDesc, prometheus.GaugeValue, nowSec) + ch <- c.now.mustNewConstMetric(nowSec) level.Debug(c.logger).Log("msg", "Zone offset", "offset", zoneOffset, "time_zone", zone) - ch <- prometheus.MustNewConstMetric(c.zoneDesc, prometheus.GaugeValue, float64(zoneOffset), zone) + ch <- c.zone.mustNewConstMetric(float64(zoneOffset), zone) return c.update(ch) } diff --git a/collector/time_linux.go b/collector/time_linux.go index 12975d3752..c5d4a47d8e 100644 --- a/collector/time_linux.go +++ b/collector/time_linux.go @@ -43,29 +43,9 @@ func (c *timeCollector) update(ch chan<- prometheus.Metric) error { for i, clocksource := range clocksources { is := strconv.Itoa(i) for _, cs := range clocksource.Available { - ch <- prometheus.MustNewConstMetric( - prometheus.NewDesc( - namespace+"_time_clocksource_available_info", - "Available clocksources read from '/sys/devices/system/clocksource'", - []string{"device", "clocksource"}, - nil), - prometheus.GaugeValue, - 1.0, - is, - cs, - ) + ch <- c.clocksourcesAvailable.mustNewConstMetric(1.0, is, cs) } - ch <- prometheus.MustNewConstMetric( - prometheus.NewDesc( - namespace+"_time_clocksource_current_info", - "Current clocksource read from '/sys/devices/system/clocksource'", - []string{"device", "clocksource"}, - nil), - prometheus.GaugeValue, - 1.0, - is, - clocksource.Current, - ) + ch <- c.clocksourceCurrent.mustNewConstMetric(1.0, is, clocksource.Current) } return nil } From 32c520c60949946e81a3d4f464af0823f713ddd0 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Fri, 12 Nov 2021 11:32:00 +0100 Subject: [PATCH 4/4] Instantiate sysfs in update We can't declare sysfs in time.go since the sysfs package itself is linux only. Signed-off-by: Johannes 'fish' Ziemke --- collector/time.go | 2 -- collector/time_linux.go | 11 ++++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/collector/time.go b/collector/time.go index 27fba9f671..31a6e74e24 100644 --- a/collector/time.go +++ b/collector/time.go @@ -22,7 +22,6 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/procfs/sysfs" ) type timeCollector struct { @@ -31,7 +30,6 @@ type timeCollector struct { clocksourcesAvailable typedDesc clocksourceCurrent typedDesc logger log.Logger - sysfs *sysfs.FS } func init() { diff --git a/collector/time_linux.go b/collector/time_linux.go index c5d4a47d8e..a67f5a8f27 100644 --- a/collector/time_linux.go +++ b/collector/time_linux.go @@ -26,15 +26,12 @@ import ( ) func (c *timeCollector) update(ch chan<- prometheus.Metric) error { - if c.sysfs == nil { - fs, err := sysfs.NewFS(*sysPath) - if err != nil { - return fmt.Errorf("failed to open procfs: %w", err) - } - c.sysfs = &fs + fs, err := sysfs.NewFS(*sysPath) + if err != nil { + return fmt.Errorf("failed to open procfs: %w", err) } - clocksources, err := c.sysfs.ClockSources() + clocksources, err := fs.ClockSources() if err != nil { return fmt.Errorf("couldn't get clocksources: %w", err) }