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

Log total non-zero expvars on shutdown #2349

Merged
merged 1 commit into from
Aug 23, 2016
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
3 changes: 2 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
- Enhance contains condition to work on fields that are arrays of strings. {issue}2237[2237]
- Lookup the configuration file relative to the `-path.config` CLI flag. {pull}2245[2245]
- Re-write import_dashboards.sh in Golang. {pull}2155[2155]
- Update to Go 1.7 {pull}2306[2306]
- Update to Go 1.7. {pull}2306[2306]
- Log total non-zero internal metrics on shutdown. {pull}2349[2349]

*Metricbeat*

Expand Down
3 changes: 2 additions & 1 deletion filebeat/filebeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,8 @@ output.elasticsearch:

# If enabled, filebeat periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. The default is true.
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
#logging.metrics.enabled: true

# The period after which to log the internal metrics. The default is 30s.
Expand Down
3 changes: 2 additions & 1 deletion libbeat/_meta/config.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ output.elasticsearch:

# If enabled, beatname periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. The default is true.
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
#logging.metrics.enabled: true

# The period after which to log the internal metrics. The default is 30s.
Expand Down
1 change: 1 addition & 0 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (b *Beat) launch(bt Creator) error {

logp.Info("%s start running.", b.Name)
defer logp.Info("%s stopped.", b.Name)
defer logp.LogTotalExpvars(&b.Config.Logging)

return beater.Run(b)
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/docs/loggingconfig.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ the debug log level).

If enabled, {beatname_uc} periodically logs its internal metrics that have
changed in the last period. For each metric that changed, the delta from the
value at the beginning of the period is logged. The default is true.
value at the beginning of the period is logged. Also, the total values for
all non-zero internal metrics are logged on shutdown. The default is true.

Here is an example log line:

Expand Down
11 changes: 11 additions & 0 deletions libbeat/logp/logp.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,14 @@ func logExpvars(metricsCfg *LoggingMetricsConfig) {
}
}
}

func LogTotalExpvars(cfg *Logging) {
if cfg.Metrics.Enabled != nil && *cfg.Metrics.Enabled == false {
return
}
vals := map[string]int64{}
prevVals := map[string]int64{}
snapshotExpvars(vals)
metrics := buildMetricsOutput(prevVals, vals)
Info("Total non-zero values: %s", metrics)
}
3 changes: 3 additions & 0 deletions libbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ def test_logging_metrics(self):
lambda: self.log_contains("No non-zero metrics in the last 100ms"),
max_timeout=2)
proc.check_kill_and_wait()
self.wait_until(
lambda: self.log_contains("Total non-zero values:"),
max_timeout=2)
12 changes: 0 additions & 12 deletions metricbeat/beater/metricbeat.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package beater

import (
"expvar"
"sync"

"github.com/elastic/beats/libbeat/beat"
Expand Down Expand Up @@ -49,7 +48,6 @@ func New(b *beat.Beat, rawConfig *common.Config) (beat.Beater, error) {
// that a single unresponsive host cannot inadvertently block other hosts
// within the same Module and MetricSet from collection.
func (bt *Metricbeat) Run(b *beat.Beat) error {
defer dumpMetrics()

bt.client = b.Publisher.Connect()

Expand Down Expand Up @@ -84,13 +82,3 @@ func (bt *Metricbeat) Stop() {
bt.client.Close()
close(bt.done)
}

// dumpMetrics is used to log metrics on shutdown.
func dumpMetrics() {
logp.Info("Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
if kv.Key != "memstats" {
logp.Info("%s=%s", kv.Key, kv.Value.String())
}
})
}
4 changes: 2 additions & 2 deletions metricbeat/etc/kibana/index-pattern/metricbeat.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion metricbeat/metricbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ output.elasticsearch:

# If enabled, metricbeat periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. The default is true.
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
#logging.metrics.enabled: true

# The period after which to log the internal metrics. The default is 30s.
Expand Down
3 changes: 2 additions & 1 deletion packetbeat/packetbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ output.elasticsearch:

# If enabled, packetbeat periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. The default is true.
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
#logging.metrics.enabled: true

# The period after which to log the internal metrics. The default is 30s.
Expand Down
15 changes: 0 additions & 15 deletions winlogbeat/beater/winlogbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (eb *Winlogbeat) Run(b *beat.Beat) error {
if err := eb.setup(b); err != nil {
return err
}
defer eb.cleanup(b)

persistedState := eb.checkpoint.States()

Expand All @@ -164,20 +163,6 @@ func (eb *Winlogbeat) Run(b *beat.Beat) error {
return nil
}

// cleanup attempts to remove any files or data it may have created which should
// not be persisted.
func (eb *Winlogbeat) cleanup(b *beat.Beat) {
logp.Info("Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
logf := logp.Info
if kv.Key == "memstats" {
logf = memstatsf
}

logf("%s=%s", kv.Key, kv.Value.String())
})
}

// Stop is used to tell the winlogbeat that it should cease executing.
func (eb *Winlogbeat) Stop() {
logp.Info("Stopping Winlogbeat")
Expand Down
3 changes: 2 additions & 1 deletion winlogbeat/winlogbeat.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ output.elasticsearch:

# If enabled, winlogbeat periodically logs its internal metrics that have changed
# in the last period. For each metric that changed, the delta from the value at
# the beginning of the period is logged. The default is true.
# the beginning of the period is logged. Also, the total values for
# all non-zero internal metrics are logged on shutdown. The default is true.
#logging.metrics.enabled: true

# The period after which to log the internal metrics. The default is 30s.
Expand Down