From b410d1f1ec5088809b8f26763c466e89c314fbb3 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 16 Aug 2023 10:09:20 -0700 Subject: [PATCH] Add support for zfs-autosnapshot format --- zfs_replication_exporter.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/zfs_replication_exporter.go b/zfs_replication_exporter.go index fcf7bb1..312d8d3 100644 --- a/zfs_replication_exporter.go +++ b/zfs_replication_exporter.go @@ -44,9 +44,13 @@ var ( // @zfs-auto-snap_hourly-2023-01-14-19h00U // @zfs-auto-snap_weekly-2022-12-19-08h00U // @zfs-auto-snap_monthly-2022-12-01-08h00U - linuxSnapshotPattern = regexp.MustCompile(`^[^@]+@zfs-auto-snap_(?:frequent|daily|hourly|weekly|monthly)-(\d{4}-\d{2}-\d{2}-\d{2}h\d{2}U)$`) + linuxSnapshotPattern = regexp.MustCompile(`^[^@]+@zfs-auto-snap_(?:frequent|daily|hourly|weekly|monthly)-(\d{4}-\d{2}-\d{2}-\d{2}h\d{2}U)$`) + // @mom-20230812163001 + autosnapshotPattern = regexp.MustCompile(`^[^@]+@[^-]+-(\d{14})$`) + freenasSnapshotFormat = "20060102.1504" linuxSnapshotFormat = "2006-01-02-15h04U" + autosnapshotFormat = "20060102150405" fetchRequestDurationMetric = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "ssh_fetch_duration_seconds", @@ -186,6 +190,21 @@ func fetchSnapshotStats(host string, c *ssh.Client) (snapshotStats, error) { stats[name].Timestamp = t } } + if m := autosnapshotPattern.FindStringSubmatch(l); len(m) == 2 { + foundSnapshot = true + t, err := time.Parse(autosnapshotFormat, m[1]) + if err != nil { + glog.Errorf("[%s] Malformed time in autosnapshot %q: %v", host, m[1], err) + continue + } + glog.V(3).Infof("filesystem: %s timestamp %v", l, t) + stats[name].LinuxCounts++ + 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) { + stats[name].Timestamp = t + } + } if !foundSnapshot { glog.V(3).Infof("[%s] Skipping snapshot with non-conforming timestamp %q", host, l) }