Skip to content

Commit

Permalink
systemd.go: Used TrimLeft instead of regex for boot times metrics. (#124
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jonathan Davies <[email protected]>
  • Loading branch information
jpds authored Jan 14, 2024
1 parent 627f562 commit f146ff9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions systemd/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var (
systemdUser = kingpin.Flag("systemd.collector.user", "Connect to the user systemd instance.").Bool()
enableRestartsMetrics = kingpin.Flag("systemd.collector.enable-restart-count", "Enables service restart count metrics. This feature only works with systemd 235 and above.").Bool()
enableIPAccountingMetrics = kingpin.Flag("systemd.collector.enable-ip-accounting", "Enables service ip accounting metrics. This feature only works with systemd 235 and above.").Bool()
bootTimeRE = regexp.MustCompile(`\d+`)
)

var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"}
Expand Down Expand Up @@ -366,15 +365,12 @@ func (c *Collector) collectBootStageTimestamps(conn *dbus.Conn, ch chan<- promet
stageMonotonic := strings.TrimPrefix(strings.TrimSuffix(stageMonotonicValue, `"`), `"`)
stageTimestamp := strings.TrimPrefix(strings.TrimSuffix(stageTimestampValue, `"`), `"`)

parsedStageMonotonic := bootTimeRE.FindString(stageMonotonic)
parsedStageTime := bootTimeRE.FindString(stageTimestamp)

vMonotonic, err := strconv.ParseFloat(parsedStageMonotonic, 64)
vMonotonic, err := strconv.ParseFloat(strings.TrimLeft(stageMonotonic, "@t "), 64)
if err != nil {
return err
}

vTimestamp, err := strconv.ParseFloat(parsedStageTime, 64)
vTimestamp, err := strconv.ParseFloat(strings.TrimLeft(stageTimestamp, "@t "), 64)
if err != nil {
return err
}
Expand Down

0 comments on commit f146ff9

Please sign in to comment.