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

fix(inputs.procstat): Handle running processes correctly across multiple filters #16257

Merged
Merged
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
17 changes: 8 additions & 9 deletions plugins/inputs/procstat/procstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (p *Procstat) gatherOld(acc telegraf.Accumulator) error {

func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
now := time.Now()

running := make(map[PID]bool)
srebhan marked this conversation as resolved.
Show resolved Hide resolved
for _, f := range p.Filter {
groups, err := f.ApplyFilter()
if err != nil {
Expand All @@ -347,7 +347,6 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
}

var count int
running := make(map[PID]bool)
for _, g := range groups {
count += len(g.processes)
for _, gp := range g.processes {
Expand Down Expand Up @@ -397,13 +396,6 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
}
}

// Cleanup processes that are not running anymore
for pid := range p.processes {
if !running[pid] {
delete(p.processes, pid)
}
}

// Add lookup statistics-metric
acc.AddFields(
"procstat_lookup",
Expand All @@ -419,6 +411,13 @@ func (p *Procstat) gatherNew(acc telegraf.Accumulator) error {
now,
)
}

// Cleanup processes that are not running anymore across all filters/groups
for pid := range p.processes {
if !running[pid] {
delete(p.processes, pid)
}
}
return nil
}

Expand Down
Loading