Skip to content

Commit

Permalink
fix(inputs.procstat): Handle running processes correctly across multi…
Browse files Browse the repository at this point in the history
…ple filters (influxdata#16257)
  • Loading branch information
philjb authored Dec 3, 2024
1 parent e4b2e92 commit 543b907
Showing 1 changed file with 8 additions and 9 deletions.
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)
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

0 comments on commit 543b907

Please sign in to comment.