Skip to content

Commit

Permalink
Add config option to disable cmdline cache for System Process Metrics…
Browse files Browse the repository at this point in the history
…et (#3891)

Add the ability to disable the caching of the system process metricset's `system.process.cmdline` value. Some systems allow processes to update their command line so having these changes reflected in the MetricSet's data is desired.

The default behavior is caching enabled.

Closes #3799
  • Loading branch information
martinscholz83 authored and andrewkroh committed Apr 5, 2017
1 parent 6b8cab6 commit 30d9baa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- Add the ability to collect the environment variables from system processes. {pull}3337[3337]
- Add experimental metricset `perfmon` to Windows module. {pull}3758[3758]
- Add memcached module with stats metricset. {pull}3693[3693]
- Add the `process.cmdline.cache.enabled` config option to the System Process Metricset. {pull}3891[3891]

*Packetbeat*
- Add `fields` and `fields_under_root` to packetbeat protocols configurations. {pull}3518[3518]
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/metricbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ metricbeat.modules:
# if true, exports the CPU usage in ticks, together with the percentage values
#cpu_ticks: false

# If false, cmdline of a process is not cached.
#process.cmdline.cache.enabled: true

# Enable collection of cgroup metrics from processes on Linux.
#process.cgroups.enabled: true

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/_meta/config.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
# if true, exports the CPU usage in ticks, together with the percentage values
#cpu_ticks: false

# If false, cmdline of a process is not cached.
#process.cmdline.cache.enabled: true

# Enable collection of cgroup metrics from processes on Linux.
#process.cgroups.enabled: true

Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/system/process/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ This metricset is available on:
- Linux
- Windows
[float]
=== Cache CmdLine

This metricset caches the command line args for a running process. This means if you alter
the command line for a process while this metricset is running, these changes are not detected.
This feature can be disabled by adding
`process.cmdline.cache.enabled: false` to the system module configuration.

[float]
=== Control Group (cgroup) Metrics

Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/system/process/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ProcStats struct {
ProcsMap ProcsMap
CpuTicks bool
EnvWhitelist []string
CacheCmdLine bool

procRegexps []match.Matcher // List of regular expressions used to whitelist processes.
envRegexps []match.Matcher // List of regular expressions used to whitelist env vars.
Expand Down Expand Up @@ -342,7 +343,9 @@ func (procStats *ProcStats) GetProcStats() ([]common.MapStr, error) {
var cmdline string
var env common.MapStr
if previousProc := procStats.ProcsMap[pid]; previousProc != nil {
cmdline = previousProc.CmdLine
if procStats.CacheCmdLine {
cmdline = previousProc.CmdLine
}
env = previousProc.Env
}

Expand Down
10 changes: 7 additions & 3 deletions metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func init() {
// MetricSet that fetches process metrics.
type MetricSet struct {
mb.BaseMetricSet
stats *ProcStats
cgroup *cgroup.Reader
stats *ProcStats
cgroup *cgroup.Reader
cacheCmdLine bool
}

// New creates and returns a new MetricSet.
Expand All @@ -38,8 +39,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
Cgroups *bool `config:"process.cgroups.enabled"`
EnvWhitelist []string `config:"process.env.whitelist"`
CPUTicks bool `config:"cpu_ticks"`
CacheCmdLine bool `config:"process.cmdline.cache.enabled"`
}{
Procs: []string{".*"}, // collect all processes by default
Procs: []string{".*"}, // collect all processes by default
CacheCmdLine: true,
}
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
Expand All @@ -51,6 +54,7 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
Procs: config.Procs,
EnvWhitelist: config.EnvWhitelist,
CpuTicks: config.CPUTicks,
CacheCmdLine: config.CacheCmdLine,
},
}
err := m.stats.InitProcStats()
Expand Down

0 comments on commit 30d9baa

Please sign in to comment.