Add metrics for AutosnapshotCounts

This commit is contained in:
Bill Thiede 2023-08-16 10:14:11 -07:00
parent b410d1f1ec
commit fba785f313

View File

@ -122,6 +122,9 @@ type filesystemStat struct {
// LinuxCounts is the number of snapshots matching linux' auto-snapshot
// names.
LinuxCounts int
// AutosnapshotCounts is the number of snapshots matching zfs-autosnapshot's
// auto-snapshot names.
AutosnapshotCounts int
}
type snapshotStats map[filesystemName]*filesystemStat
@ -198,7 +201,7 @@ func fetchSnapshotStats(host string, c *ssh.Client) (snapshotStats, error) {
continue
}
glog.V(3).Infof("filesystem: %s timestamp %v", l, t)
stats[name].LinuxCounts++
stats[name].AutosnapshotCounts++
snapshotTime := stats[name].Timestamp
glog.V(3).Infof("snapshotTime.Before(t) = %v snapshotTime: %v t: %v", snapshotTime.Before(t), snapshotTime, t)
if snapshotTime.Before(t) {
@ -220,6 +223,7 @@ func updateMetrics(host string, stats snapshotStats) {
snapshotCountsMetrics.WithLabelValues(host, string(filesystem), "all").Set(float64(stat.Counts))
snapshotCountsMetrics.WithLabelValues(host, string(filesystem), "freenas").Set(float64(stat.FreenasCounts))
snapshotCountsMetrics.WithLabelValues(host, string(filesystem), "linux").Set(float64(stat.LinuxCounts))
snapshotCountsMetrics.WithLabelValues(host, string(filesystem), "autosnapshot").Set(float64(stat.AutosnapshotCounts))
snapshotTimestampMetric.WithLabelValues(host, string(filesystem)).Set(float64(stat.Timestamp.Unix()))
}
}
@ -251,6 +255,7 @@ var indexTmpl = template.Must(template.New("index").Parse(`<!doctype html>
<th>Counts</th>
<th>FreeNAS Snapshots</th>
<th>Linux Snapshots</th>
<th>Autosnapshot Snapshots</th>
<th>Most Recent</th>
</tr>
{{range $name, $fsStat := .}}
@ -259,7 +264,8 @@ var indexTmpl = template.Must(template.New("index").Parse(`<!doctype html>
<td>{{$fsStat.Counts}}</td>
<td>{{$fsStat.FreenasCounts}}</td>
<td>{{$fsStat.LinuxCounts}}</td>
<td>{{if or $fsStat.LinuxCounts $fsStat.FreenasCounts }}{{$fsStat.Timestamp}}{{end}}</td>
<td>{{$fsStat.AutosnapshotCounts}}</td>
<td>{{if or $fsStat.LinuxCounts $fsStat.FreenasCounts $fsStat.AutosnapshotCounts }}{{$fsStat.Timestamp}}{{end}}</td>
</tr>
{{end}}
</table>