Compare commits

...

2 Commits

Author SHA1 Message Date
7ae07d5447 Add support for linux snapshot naming pattern. 2023-01-15 11:04:52 -08:00
5fd7f8266b Rename user for better clarity. 2023-01-14 14:25:47 -08:00
2 changed files with 39 additions and 10 deletions

View File

@ -1 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjNg0CLtUgQedbmKEJkUfefwiRQQLxsjPUN603bpSKSYkXbAJarUH33iUrIiRLf3IbJ/Nhc0yfo3hUfvrx6W7aQO2w/aaf3dugnCXXXE1FpFgIN9QJqRkMs7P/WuMI7RBYlkvPitbf85krzYuE4sJ/gt+wqGykWO6Yop4xF08BrVoxbWTe6I94ekkYcAAY77IqO2814l/ob4QY7l63DTHAvf5MN/yiUnLu7uYr71eeci4tAFl1IB37XrOyM0BndUbY6WKy7ymbSazJ8/TXX3TYk761TEMzvO79IB2OU0fD1frA17li4iF5vq14Bome2HCxZ44BWH2hDCq09U8cqYrr wathiede@big
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCjNg0CLtUgQedbmKEJkUfefwiRQQLxsjPUN603bpSKSYkXbAJarUH33iUrIiRLf3IbJ/Nhc0yfo3hUfvrx6W7aQO2w/aaf3dugnCXXXE1FpFgIN9QJqRkMs7P/WuMI7RBYlkvPitbf85krzYuE4sJ/gt+wqGykWO6Yop4xF08BrVoxbWTe6I94ekkYcAAY77IqO2814l/ob4QY7l63DTHAvf5MN/yiUnLu7uYr71eeci4tAFl1IB37XrOyM0BndUbY6WKy7ymbSazJ8/TXX3TYk761TEMzvO79IB2OU0fD1frA17li4iF5vq14Bome2HCxZ44BWH2hDCq09U8cqYrr zfs_replcation_exporter

View File

@ -32,9 +32,21 @@ var (
const snapshotListCmd = "/sbin/zfs list -t snapshot -H -o name -s name"
var (
// Example: @auto-20171001.1400-2w
snapshotPattern = regexp.MustCompile(`^[^@]+@auto-(\d{8}\.\d{4})-\d+[mwy]$`)
snapshotFormat = "20060102.1504"
// FreeNAS example:
// @auto-20171001.1400-2w
freenasSnapshotPattern = regexp.MustCompile(`^[^@]+@auto-(\d{8}\.\d{4})-\d+[mwy]$`)
// Linux examples:
// @zfs-auto-snap_frequent-2023-01-15-18h00U
// @zfs-auto-snap_frequent-2023-01-15-18h15U
// @zfs-auto-snap_frequent-2023-01-15-18h30U
// @zfs-auto-snap_frequent-2023-01-15-18h45U
// @zfs-auto-snap_daily-2023-01-14-08h00U
// @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)$`)
freenasSnapshotFormat = "20060102.1504"
linuxSnapshotFormat = "2006-01-02-15h04U"
fetchRequestDurationMetric = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ssh_fetch_duration_seconds",
@ -130,8 +142,6 @@ func fetchSnapshotStats(host string, c *ssh.Client) (snapshotStats, error) {
stats := snapshotStats(make(map[filesystemName]*filesystemStat))
for scanner.Scan() {
l := scanner.Text()
m := snapshotPattern.FindStringSubmatch(l)
filesystem := l
if idx := strings.Index(l, "@"); idx != -1 {
filesystem = l[:idx]
@ -141,10 +151,13 @@ func fetchSnapshotStats(host string, c *ssh.Client) (snapshotStats, error) {
stats[name] = &filesystemStat{}
}
stats[name].Counts++
if len(m) == 2 {
t, err := time.Parse(snapshotFormat, m[1])
var foundSnapshot bool
if m := freenasSnapshotPattern.FindStringSubmatch(l); len(m) == 2 {
foundSnapshot = true
t, err := time.Parse(freenasSnapshotFormat, m[1])
if err != nil {
glog.Errorf("[%s] Malformed time in snapshot %q: %v", host, m[1], err)
glog.Errorf("[%s] Malformed time in freenas snapshot %q: %v", host, m[1], err)
continue
}
glog.V(3).Infof("filesystem: %s timestamp %v", l, t)
@ -154,7 +167,23 @@ func fetchSnapshotStats(host string, c *ssh.Client) (snapshotStats, error) {
if snapshotTime.Before(t) {
stats[name].Timestamp = t
}
} else {
}
if m := linuxSnapshotPattern.FindStringSubmatch(l); len(m) == 2 {
foundSnapshot = true
t, err := time.Parse(linuxSnapshotFormat, m[1])
if err != nil {
glog.Errorf("[%s] Malformed time in linux snapshot %q: %v", host, m[1], err)
continue
}
glog.V(3).Infof("filesystem: %s timestamp %v", l, t)
stats[name].FreenasCounts++
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)
}
}