Skip to content

Commit

Permalink
Cherry-pick #23831 to 7.x: Add system.hostfs configuration option for…
Browse files Browse the repository at this point in the history
… system module (#23900)
  • Loading branch information
ChrsMark authored Feb 8, 2021
1 parent 4b74e6d commit 5fbd81c
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/system.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/system/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions metricbeat/module/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand All @@ -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
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions metricbeat/module/system/system_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/"
}
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/system_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

package system

func initModule() {
func initModule(config Config) {
// Stub method for non-linux.
}
2 changes: 1 addition & 1 deletion metricbeat/module/system/system_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/modules.d/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5fbd81c

Please sign in to comment.