Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3010,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
Expand Down Expand Up @@ -3132,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
Expand Down
20 changes: 16 additions & 4 deletions collector/fixtures/sys.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -4702,7 +4718,3 @@ Lines: 1
20
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/.unpacked
Lines: 0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 changes: 22 additions & 10 deletions collector/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import (
)

type timeCollector struct {
nowDesc *prometheus.Desc
zoneDesc *prometheus.Desc
logger log.Logger
now typedDesc
zone typedDesc
clocksourcesAvailable typedDesc
clocksourceCurrent typedDesc
logger log.Logger
}

func init() {
Expand All @@ -39,16 +41,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
}
Expand All @@ -59,8 +71,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)
return nil
ch <- c.zone.mustNewConstMetric(float64(zoneOffset), zone)
return c.update(ch)
}
48 changes: 48 additions & 0 deletions collector/time_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return fmt.Errorf("failed to open procfs: %w", err)
}

clocksources, err := 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 nil
}
25 changes: 25 additions & 0 deletions collector/time_other.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ COLLECTORS
)
disabled_collectors=$(cat << COLLECTORS
filesystem
time
timex
uname
COLLECTORS
Expand All @@ -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)"

Expand Down