From 82b837275dde7a0227619b02fa6f61dcfc820b1c Mon Sep 17 00:00:00 2001 From: Alex K <8418476+fearful-symmetry@users.noreply.github.com> Date: Tue, 17 Nov 2020 07:47:59 -0800 Subject: [PATCH] Trim down beat name if it's longer than 15 characters (#22550) * Trim down beat name if it's longer than 15 characters * add OS guard, changelog --- CHANGELOG.next.asciidoc | 1 + libbeat/cmd/instance/metrics.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 65e2dbe017d..cdf8d58d31c 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -434,6 +434,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Add interval information to `monitor` metricset in azure. {pull}22152[22152] - Change Session ID type from int to string {pull}22359[22359] - Fix filesystem types on Windows in filesystem metricset. {pull}22531[22531] +- Fix failiures caused by custom beat names with more than 15 characters {pull}22550[22550] *Packetbeat* diff --git a/libbeat/cmd/instance/metrics.go b/libbeat/cmd/instance/metrics.go index 24d3d12e3e1..2e727446d5d 100644 --- a/libbeat/cmd/instance/metrics.go +++ b/libbeat/cmd/instance/metrics.go @@ -43,6 +43,12 @@ func init() { func setupMetrics(name string) error { monitoring.NewFunc(systemMetrics, "cpu", reportSystemCPUUsage, monitoring.Report) + //if the beat name is longer than 15 characters, truncate it so we don't fail process checks later on + // On *nix, the process name comes from /proc/PID/stat, which uses a comm value of 16 bytes, plus the null byte + if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") && len(name) > 15 { + name = name[:15] + } + beatProcessStats = &process.Stats{ Procs: []string{name}, EnvWhitelist: nil,