diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 41643bc8f7b..ec49824e1ad 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -304,6 +304,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Update config in `windows.yml` file. {issue}23027[23027]{pull}23327[23327] - Add stack monitoring section to elasticsearch module documentation {pull}#23286[23286] - Fix metric grouping for windows/perfmon module {issue}23489[23489] {pull}23505[23505] +- Add system.hostfs configuration option for system module. {pull}23831[23831] *Packetbeat* diff --git a/metricbeat/docs/modules/system.asciidoc b/metricbeat/docs/modules/system.asciidoc index bdfe4bbe84c..315cae1201b 100644 --- a/metricbeat/docs/modules/system.asciidoc +++ b/metricbeat/docs/modules/system.asciidoc @@ -178,6 +178,9 @@ metricbeat.modules: period: 10s processes: ['.*'] + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" + # Configure the metric types that are included by these metricsets. cpu.metrics: ["percentages","normalized_percentages"] # The other available option is ticks. core.metrics: ["percentages"] # The other available option is ticks. diff --git a/metricbeat/metricbeat.reference.yml b/metricbeat/metricbeat.reference.yml index 23e8f23c909..e2ec23cfa74 100644 --- a/metricbeat/metricbeat.reference.yml +++ b/metricbeat/metricbeat.reference.yml @@ -79,6 +79,9 @@ metricbeat.modules: period: 10s processes: ['.*'] + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" + # Configure the metric types that are included by these metricsets. cpu.metrics: ["percentages","normalized_percentages"] # The other available option is ticks. core.metrics: ["percentages"] # The other available option is ticks. diff --git a/metricbeat/module/system/_meta/config.reference.yml b/metricbeat/module/system/_meta/config.reference.yml index 39438686dbd..929f585e7d9 100644 --- a/metricbeat/module/system/_meta/config.reference.yml +++ b/metricbeat/module/system/_meta/config.reference.yml @@ -19,6 +19,9 @@ period: 10s processes: ['.*'] + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" + # Configure the metric types that are included by these metricsets. cpu.metrics: ["percentages","normalized_percentages"] # The other available option is ticks. core.metrics: ["percentages"] # The other available option is ticks. diff --git a/metricbeat/module/system/_meta/config.yml b/metricbeat/module/system/_meta/config.yml index 6fe06489217..3f22bc5a496 100644 --- a/metricbeat/module/system/_meta/config.yml +++ b/metricbeat/module/system/_meta/config.yml @@ -17,6 +17,8 @@ process.include_top_n: by_cpu: 5 # include top 5 processes by CPU by_memory: 5 # include top 5 processes by memory + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" - module: system period: 1m diff --git a/metricbeat/module/system/system.go b/metricbeat/module/system/system.go index 0efba5c0f16..a6af865ca49 100644 --- a/metricbeat/module/system/system.go +++ b/metricbeat/module/system/system.go @@ -22,10 +22,12 @@ import ( "sync" "github.com/elastic/beats/v7/libbeat/common/fleetmode" + "github.com/elastic/beats/v7/libbeat/logp" "github.com/elastic/beats/v7/metricbeat/mb" ) var ( + // TODO: remove this flag in 8.0 since it should be replaced by system.hostfs configuration option (config.HostFS) // HostFS is an alternate mountpoint for the filesytem root, for when metricbeat is running inside a container. HostFS = flag.String("system.hostfs", "", "mountpoint of the host's filesystem for use in monitoring a host from within a container") ) @@ -39,6 +41,11 @@ func init() { } } +// Config for the system module. +type Config struct { + HostFS string `config:"system.hostfs"` // Specifies the mount point of the host’s filesystem for use in monitoring a host from within a container. +} + // Module represents the system module type Module struct { mb.BaseModule @@ -48,10 +55,25 @@ type Module struct { // NewModule instatiates the system module func NewModule(base mb.BaseModule) (mb.Module, error) { + + config := Config{ + HostFS: "", + } + err := base.UnpackConfig(&config) + if err != nil { + return nil, err + } + if *HostFS != "" { + if config.HostFS != "" { + logp.Warn("-system.hostfs flag is set and will override configuration setting") + } + config.HostFS = *HostFS + } + // This only needs to be configured once for all system modules. once.Do(func() { - initModule() + initModule(config) }) - return &Module{BaseModule: base, HostFS: *HostFS, IsAgent: fleetmode.Enabled()}, nil + return &Module{BaseModule: base, HostFS: config.HostFS, IsAgent: fleetmode.Enabled()}, nil } diff --git a/metricbeat/module/system/system_linux.go b/metricbeat/module/system/system_linux.go index 72477566a93..6f3f15a1135 100644 --- a/metricbeat/module/system/system_linux.go +++ b/metricbeat/module/system/system_linux.go @@ -24,12 +24,12 @@ import ( "github.com/elastic/gosigar" ) -func initModule() { - configureHostFS() +func initModule(config Config) { + configureHostFS(config) } -func configureHostFS() { - dir := *HostFS +func configureHostFS(config Config) { + dir := config.HostFS if dir == "" { dir = "/" } diff --git a/metricbeat/module/system/system_other.go b/metricbeat/module/system/system_other.go index 8d89efbd485..c526d363b28 100644 --- a/metricbeat/module/system/system_other.go +++ b/metricbeat/module/system/system_other.go @@ -19,6 +19,6 @@ package system -func initModule() { +func initModule(config Config) { // Stub method for non-linux. } diff --git a/metricbeat/module/system/system_windows.go b/metricbeat/module/system/system_windows.go index 154481eb657..1c95b3e92f9 100644 --- a/metricbeat/module/system/system_windows.go +++ b/metricbeat/module/system/system_windows.go @@ -22,7 +22,7 @@ import ( "github.com/elastic/beats/v7/metricbeat/helper" ) -func initModule() { +func initModule(config Config) { if err := helper.CheckAndEnableSeDebugPrivilege(); err != nil { logp.Warn("%v", err) } diff --git a/metricbeat/modules.d/system.yml b/metricbeat/modules.d/system.yml index 57fca1b0345..339d66abc3a 100644 --- a/metricbeat/modules.d/system.yml +++ b/metricbeat/modules.d/system.yml @@ -20,6 +20,8 @@ process.include_top_n: by_cpu: 5 # include top 5 processes by CPU by_memory: 5 # include top 5 processes by memory + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" - module: system period: 1m diff --git a/x-pack/metricbeat/metricbeat.reference.yml b/x-pack/metricbeat/metricbeat.reference.yml index 8717b9df2b4..58c6e9df7a5 100644 --- a/x-pack/metricbeat/metricbeat.reference.yml +++ b/x-pack/metricbeat/metricbeat.reference.yml @@ -79,6 +79,9 @@ metricbeat.modules: period: 10s processes: ['.*'] + # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container + #system.hostfs: "/hostfs" + # Configure the metric types that are included by these metricsets. cpu.metrics: ["percentages","normalized_percentages"] # The other available option is ticks. core.metrics: ["percentages"] # The other available option is ticks.