Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to disable or enable cmdline cache for System Process Metricset #3891

Merged
merged 3 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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