Skip to content

Commit

Permalink
Implement skip_datasets for monitor rules
Browse files Browse the repository at this point in the history
Every item can be configured to skip some datasets from the check, like:

```yaml
- prefix: "zrepl_monthly_"
  skip_datasets:
    - pattern: "zdisk/video"
  warning: 13
  critical: 14
```

In this example it checks number of snapshots with prefix `zrepl_monthly_` for
every dataset, configured in `datasets`, except `zdisk/video`. `skip_datasets`
has the same syntax, like `datasets`.
  • Loading branch information
dsh2dsh committed Feb 7, 2025
1 parent 474ca06 commit b727097
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 49 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pkg install zrepl-dsh2dsh
is ok, latest or oldest snapshots are not too old. See
[#765](https://github.com/zrepl/zrepl/pull/765). Configuration example:

``` yaml
```yaml
monitor:
count:
- prefix: "zrepl_frequently_"
Expand Down Expand Up @@ -353,9 +353,23 @@ pkg install zrepl-dsh2dsh
critical: "168h" # 7d
```

Example of a daily script:
Every item can be configured to skip some datasets from the check, like:

```yaml
- prefix: "zrepl_monthly_"
skip_datasets:
- pattern: "zdisk/video"
warning: 13
critical: 14
```

In this example it checks number of snapshots with prefix `zrepl_monthly_`
for every dataset, configured in `datasets`, except `zdisk/video`.
`skip_datasets` has the same syntax, like `datasets`.

An example of a daily script:

``` shell
```shell
echo
echo "zrepl status:"
zrepl monitor alive
Expand Down
91 changes: 91 additions & 0 deletions internal/client/monitor/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package monitor

import (
"github.com/dsh2dsh/zrepl/internal/config"
"github.com/dsh2dsh/zrepl/internal/daemon/filters"
"github.com/dsh2dsh/zrepl/internal/zfs"
)

func CountRulesFromConfig(in []config.MonitorCount) ([]*CountRule, error) {
rules := make([]*CountRule, len(in))
for i := range in {
r, err := NewCountRule(&in[i])
if err != nil {
return nil, err
}
rules[i] = r
}
return rules, nil
}

func NewCountRule(m *config.MonitorCount) (*CountRule, error) {
r := &CountRule{MonitorCount: m}
return r.init()
}

type CountRule struct {
*config.MonitorCount

skip *filters.DatasetFilter
}

func (self *CountRule) init() (*CountRule, error) {
if length := len(self.SkipDatasets); length != 0 {
skip := filters.New(length)
if err := skip.AddList(self.SkipDatasets); err != nil {
return nil, err
}
self.skip = skip
}
return self, nil
}

func (self *CountRule) Skip(path *zfs.DatasetPath) (bool, error) {
if self.skip != nil {
return self.skip.Filter(path)
}
return false, nil
}

// --------------------------------------------------

func AgeRulesFromConfig(in []config.MonitorCreation) ([]*AgeRule, error) {
rules := make([]*AgeRule, len(in))
for i := range in {
r, err := NewAgeRule(&in[i])
if err != nil {
return nil, err
}
rules[i] = r
}
return rules, nil
}

func NewAgeRule(m *config.MonitorCreation) (*AgeRule, error) {
r := &AgeRule{MonitorCreation: m}
return r.init()
}

type AgeRule struct {
*config.MonitorCreation

skip *filters.DatasetFilter
}

func (self *AgeRule) init() (*AgeRule, error) {
if length := len(self.SkipDatasets); length != 0 {
skip := filters.New(length)
if err := skip.AddList(self.SkipDatasets); err != nil {
return nil, err
}
self.skip = skip
}
return self, nil
}

func (self *AgeRule) Skip(path *zfs.DatasetPath) (bool, error) {
if self.skip != nil {
return self.skip.Filter(path)
}
return false, nil
}
Loading

0 comments on commit b727097

Please sign in to comment.