Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system shutdown timestamp #3111

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions collector/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
unitTasksCurrentDesc *prometheus.Desc
unitTasksMaxDesc *prometheus.Desc
systemRunningDesc *prometheus.Desc
systemShutdownDesc *prometheus.Desc
summaryDesc *prometheus.Desc
nRestartsDesc *prometheus.Desc
timerLastTriggerDesc *prometheus.Desc
Expand Down Expand Up @@ -111,6 +112,11 @@
"Whether the system is operational (see 'systemctl is-system-running')",
nil, nil,
)
systemShutdownDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "system_shutdown_timestamp_seconds"),
"The scheduled shutdown timestamp')",
nil, nil,
)
summaryDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "units"),
"Summary of systemd unit states", []string{"state"}, nil)
Expand Down Expand Up @@ -160,6 +166,7 @@
unitTasksCurrentDesc: unitTasksCurrentDesc,
unitTasksMaxDesc: unitTasksMaxDesc,
systemRunningDesc: systemRunningDesc,
systemShutdownDesc: systemShutdownDesc,
summaryDesc: summaryDesc,
nRestartsDesc: nRestartsDesc,
timerLastTriggerDesc: timerLastTriggerDesc,
Expand Down Expand Up @@ -262,8 +269,15 @@
begin = time.Now()
err = c.collectSystemState(conn, ch)
c.logger.Debug("collectSystemState took", "duration_seconds", time.Since(begin).Seconds())
if err != nil {
return err
}
}

begin = time.Now()
err = c.collectScheduledShutdownMetrics(conn, ch)
c.logger.Debug("collectScheduledShutdownMetrics took", "duration_seconds", time.Since(begin).Seconds())

return err
}

Expand Down Expand Up @@ -342,6 +356,26 @@
}
}

func (c *systemdCollector) collectScheduledShutdownMetrics(conn *dbus.Conn, ch chan<- prometheus.Metric) error {
// var shutdownTimeUsec uint64

// timestampValue, err := conn.GetServicePropertyContext(context.TODO(), "org.freedesktop.login1.Manager", "ScheduledShutdown")
shutdownValue, err := conn.GetManagerProperty("ScheduledShutdown")

Check failure on line 363 in collector/systemd_linux.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

Check failure on line 363 in collector/systemd_linux.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
c.logger.Info("got ScheduledShutdown", "value", shutdownValue)
return nil
if err != nil {

Check failure on line 366 in collector/systemd_linux.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)

Check failure on line 366 in collector/systemd_linux.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
c.logger.Debug("couldn't get ScheduledShutdown", "err", err)
return errors.New("Couldn't get ScheduledShutdown property")
}
// shutdownTimeUsec = timestampValue.Value.Value().(uint64)

// ch <- prometheus.MustNewConstMetric(
// c.systemShutdownDesc, prometheus.GaugeValue,
// float64(shutdownTimeUsec)/1e6,
// )
return nil
}

func (c *systemdCollector) collectUnitStartTimeMetrics(conn *dbus.Conn, ch chan<- prometheus.Metric, units []unit) {
var startTimeUsec uint64

Expand Down
Loading