Skip to content

Commit

Permalink
add a configuration to ignore filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
stanaka committed Jan 29, 2016
1 parent 06d85e6 commit afed6bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions command/command_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
specLinux "github.com/mackerelio/mackerel-agent/spec/linux"
)

func specGenerators() []spec.Generator {
func specGenerators(conf *config.Config) []spec.Generator {
return []spec.Generator{
&specLinux.KernelGenerator{},
&specLinux.CPUGenerator{},
&specLinux.MemoryGenerator{},
&specLinux.BlockDeviceGenerator{},
&specLinux.FilesystemGenerator{},
&specLinux.FilesystemGenerator{Ignore: conf.Filesystems.Ignore},
}
}

Expand All @@ -30,7 +30,7 @@ func metricsGenerators(conf *config.Config) []metrics.Generator {
&metricsLinux.UptimeGenerator{},
&metricsLinux.InterfaceGenerator{Interval: metricsInterval},
&metricsLinux.DiskGenerator{Interval: metricsInterval},
&metricsLinux.FilesystemGenerator{},
&metricsLinux.FilesystemGenerator{Ignore: conf.Filesystems.Ignore},
}

return generators
Expand Down
10 changes: 8 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ type Config struct {
Verbose bool
Diagnostic bool `toml:"diagnostic"`
Connection ConnectionConfig
DisplayName string `toml:"display_name"`
HostStatus HostStatus `toml:"host_status"`
DisplayName string `toml:"display_name"`
HostStatus HostStatus `toml:"host_status"`
Filesystems Filesystems `toml:"filesystems"`

// Corresponds to the set of [plugin.<kind>.<name>] sections
// the key of the map is <kind>, which should be one of "metrics" or "checks".
Expand Down Expand Up @@ -88,6 +89,11 @@ type HostStatus struct {
OnStop string `toml:"on_stop"`
}

// Filesystems configure filesystem related settings
type Filesystems struct {
Ignore string `toml:"ignore"`
}

// CheckNames return list of plugin.checks._name_
func (conf *Config) CheckNames() []string {
checks := []string{}
Expand Down
7 changes: 7 additions & 0 deletions mackerel-agent.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# verbose = false
# apikey = ""

# [host_status]
# on_start = "working"
# on_stop = "poweroff"

# [filesystems]
# ignore = "/dev/ram.*"

# Configuration for connection
# [connection]
# post_metrics_dequeue_delay_seconds = 30 # delay for dequeuing from buffer queue
Expand Down
4 changes: 3 additions & 1 deletion metrics/linux/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

// FilesystemGenerator XXX
type FilesystemGenerator struct {
Ignore string
}

var logger = logging.GetLogger("metrics.filesystem")
Expand All @@ -31,7 +32,8 @@ func (g *FilesystemGenerator) Generate() (metrics.Values, error) {
ret := make(map[string]float64)
for name, values := range filesystems {
// https://github.com/docker/docker/blob/v1.5.0/daemon/graphdriver/devmapper/deviceset.go#L981
if regexp.MustCompile(`^/dev/mapper/docker-`).FindStringSubmatch(name) != nil {
if regexp.MustCompile(`^/dev/mapper/docker-`).FindStringSubmatch(name) != nil ||
(g.Ignore != "" && regexp.MustCompile(g.Ignore).FindStringSubmatch(name) != nil) {
continue
}
if matches := regexp.MustCompile(`^/dev/(.*)$`).FindStringSubmatch(name); matches != nil {
Expand Down

0 comments on commit afed6bb

Please sign in to comment.