Skip to content

Commit

Permalink
Add snapshot age into output
Browse files Browse the repository at this point in the history
Also truncate all duration strings to seconds. Output examples:

OK: job "zdisk": latest snapshot: 20m30s
OK: job "zdisk": oldest snapshot: 1011h24m30s
CRITICAL: job "zdisk": oldest "zdisk/zrepl/zroot/ROOT/default@zrepl_daily_20240314_152614_000" too old: "1011h26m13s" > "48h0m0s"
  • Loading branch information
dsh2dsh committed Apr 25, 2024
1 parent 55f5a95 commit b935082
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions client/monitorcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type monitorSnapshots struct {
prefix string
critical time.Duration
warning time.Duration

age time.Duration
}

func (self *monitorSnapshots) run(
Expand Down Expand Up @@ -250,20 +252,25 @@ func (self *monitorSnapshots) checkDataset(
latest := self.groupSnapshots(snaps, rules)
for i, rule := range rules {
const tooOldFmt = "%s %q too old: %q > %q"
d := time.Since(latest[i].Creation).Truncate(time.Second)
switch {
case rule.Prefix == "" && latest[i].Creation.IsZero():
case latest[i].Creation.IsZero():
return newMonitorCriticalf(
err = newMonitorCriticalf(
"%q has no snapshots with prefix %q", name, rule.Prefix)
case time.Since(latest[i].Creation) >= rule.Critical:
return newMonitorCriticalf(tooOldFmt, self.snapshotType(),
latest[i].FullPath(name), time.Since(latest[i].Creation), rule.Critical)
err = newMonitorCriticalf(tooOldFmt, self.snapshotType(),
latest[i].FullPath(name), d, rule.Critical)
case rule.Warning > 0 && time.Since(latest[i].Creation) >= rule.Warning:
return newMonitorWarningf(tooOldFmt, self.snapshotType(),
latest[i].FullPath(name), time.Since(latest[i].Creation), rule.Warning)
err = newMonitorWarningf(tooOldFmt, self.snapshotType(),
latest[i].FullPath(name), d, rule.Warning)
case d > self.age:
self.age = d
}
if err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -302,8 +309,8 @@ func (self *monitorSnapshots) cmpSnapshots(
}

func (self *monitorSnapshots) outputAndExit(err error) {
resp := monitoringplugin.NewResponse(
fmt.Sprintf("job %q: %s snapshots", self.job, self.snapshotType()))
resp := monitoringplugin.NewResponse(fmt.Sprintf("job %q: %s snapshot: %v",
self.job, self.snapshotType(), self.age))

if err != nil {
status := fmt.Sprintf("job %q: %s", self.job, err)
Expand Down

0 comments on commit b935082

Please sign in to comment.