From bd0c18b22d055ae1ad387ab7480df6132a506f85 Mon Sep 17 00:00:00 2001 From: kongfei Date: Mon, 23 Dec 2024 14:31:45 +0800 Subject: [PATCH] chore: do not attach pid tag for jstat when there is only one process --- inputs/procstat/procstat.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inputs/procstat/procstat.go b/inputs/procstat/procstat.go index 4bc5b9ee..ceb27a06 100644 --- a/inputs/procstat/procstat.go +++ b/inputs/procstat/procstat.go @@ -524,6 +524,10 @@ func (ins *Instance) gatherLimit(slist *types.SampleList, procs map[PID]Process, } func (ins *Instance) gatherJvm(slist *types.SampleList, procs map[PID]Process, tags map[string]string) { + attachPid := false + if len(procs) > 1 { + attachPid = true + } for pid := range procs { jvmStat, err := execJstat(pid) if err != nil { @@ -531,7 +535,10 @@ func (ins *Instance) gatherJvm(slist *types.SampleList, procs map[PID]Process, t continue } - pidTag := map[string]string{"pid": fmt.Sprint(pid)} + pidTag := map[string]string{} + if attachPid { + pidTag["pid"] = fmt.Sprint(pid) + } for k, v := range jvmStat { slist.PushSample(inputName, "jvm_"+k, v, pidTag, ins.makeCmdlineLabelReggroupTag(procs[pid]), tags) }