-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ | |
unitTasksCurrentDesc *prometheus.Desc | ||
unitTasksMaxDesc *prometheus.Desc | ||
systemRunningDesc *prometheus.Desc | ||
systemShutdownDesc *prometheus.Desc | ||
summaryDesc *prometheus.Desc | ||
nRestartsDesc *prometheus.Desc | ||
timerLastTriggerDesc *prometheus.Desc | ||
|
@@ -112,6 +113,11 @@ | |
"Whether the system is operational (see 'systemctl is-system-running')", | ||
nil, nil, | ||
) | ||
systemShutdownDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, subsystem, "system_shutdown_timestamp"), | ||
"Time for a scheduled shutdown (see 'systemctl status systemd-shutdownd.service')", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that command outputs:
here. I found a
That's for the property we're (trying to) fetch(ing) here... That method referenced there is:
... which is, frankly, not that much helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also not sure how to represent the "no shutdown scheduled" state. in my script, i used "zero seconds" as a value for that, but the property returned somehow uses something else (which looks a lot like MAX_INT-1, AKA 2^64-1, AKA 18446744073709551615 ≈ 1,844 674 407 4 × 10^19) also note that on my laptop, this morning, after the device went to sleep on its own after a timeout, dbus says this:
|
||
nil, nil, | ||
) | ||
summaryDesc := prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, subsystem, "units"), | ||
"Summary of systemd unit states", []string{"state"}, nil) | ||
|
@@ -161,6 +167,7 @@ | |
unitTasksCurrentDesc: unitTasksCurrentDesc, | ||
unitTasksMaxDesc: unitTasksMaxDesc, | ||
systemRunningDesc: systemRunningDesc, | ||
systemShutdownDesc: systemShutdownDesc, | ||
summaryDesc: summaryDesc, | ||
nRestartsDesc: nRestartsDesc, | ||
timerLastTriggerDesc: timerLastTriggerDesc, | ||
|
@@ -261,10 +268,14 @@ | |
|
||
if systemdVersion >= minSystemdVersionSystemState { | ||
begin = time.Now() | ||
err = c.collectSystemState(conn, ch) | ||
Check failure on line 271 in collector/systemd_linux.go GitHub Actions / lint
|
||
level.Debug(c.logger).Log("msg", "collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) | ||
} | ||
|
||
begin = time.Now() | ||
err = c.collectScheduledShutdownMetrics(conn, ch) | ||
level.Debug(c.logger).Log("msg", "collectScheduledShutdownMetrics took", "duration_seconds", time.Since(begin).Seconds()) | ||
|
||
return err | ||
} | ||
|
||
|
@@ -343,6 +354,23 @@ | |
} | ||
} | ||
|
||
func (c *systemdCollector) collectScheduledShutdownMetrics(conn *dbus.Conn, ch chan<- prometheus.Metric) error { | ||
var shutdownTimeUsec uint64 | ||
|
||
timestampValue, err := conn.GetServicePropertyContext(context.TODO(), "org.freedesktop.login1", "ScheduledShutdown") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just so you know, i'm not sure this returns a single integer. if it behaves like the commandline tool, it returns a tuple of 3 elements. with a pending reboot:
without:
notice how the timestamp is in nanoseconds, and how completely out of whack it is when there's no scheduled shutdown. not sure what's going on there. the script i wrote in #3110 (comment) does this somewhat properly, and outputs the following metrics, with the first example:
with the second, it does that:
|
||
if err != nil { | ||
level.Debug(c.logger).Log("msg", "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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that should be
system_shutdown_timestamp_seconds
, no?