Skip to content

Commit

Permalink
Add support for parked process state on Linux (influxdata#6308)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and bitcharmer committed Oct 18, 2019
1 parent dd35d76 commit 52abd8e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/inputs/processes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Using the environment variable `HOST_PROC` the plugin will retrieve process info
- wait (freebsd only)
- idle (bsd and Linux 4+ only)
- paging (linux only)
- parked (linux only)
- total_threads (linux only)

### Process State Mappings
Expand Down
5 changes: 5 additions & 0 deletions plugins/inputs/processes/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
fields["paging"] = fields["paging"].(int64) + int64(1)
case 'I':
fields["idle"] = fields["idle"].(int64) + int64(1)
case 'P':
if _, ok := fields["parked"]; ok {
fields["parked"] = fields["parked"].(int64) + int64(1)
}
fields["parked"] = int64(1)
default:
log.Printf("I! processes: Unknown state [ %s ] in file %s",
string(stats[0][0]), filename)
Expand Down
52 changes: 52 additions & 0 deletions plugins/inputs/processes/processes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"runtime"
"testing"
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -107,6 +109,56 @@ func TestFromProcFilesWithSpaceInCmd(t *testing.T) {
acc.AssertContainsTaggedFields(t, "processes", fields, map[string]string{})
}

// Based on `man 5 proc`, parked processes an be found in a
// limited range of Linux versions:
//
// > P Parked (Linux 3.9 to 3.13 only)
//
// However, we have had reports of this process state on Ubuntu
// Bionic w/ Linux 4.15 (#6270)
func TestParkedProcess(t *testing.T) {
procstat := `88 (watchdog/13) P 2 0 0 0 -1 69238848 0 0 0 0 0 0 0 0 20 0 1 0 20 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 1 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
`
plugin := &Processes{
readProcFile: func(string) ([]byte, error) {
return []byte(procstat), nil
},
forceProc: true,
}

var acc testutil.Accumulator
err := plugin.Gather(&acc)
require.NoError(t, err)

expected := []telegraf.Metric{
testutil.MustMetric(
"processes",
map[string]string{},
map[string]interface{}{
"blocked": 0,
"dead": 0,
"idle": 0,
"paging": 0,
"parked": 1,
"running": 0,
"sleeping": 0,
"stopped": 0,
"unknown": 0,
"zombies": 0,
},
time.Unix(0, 0),
telegraf.Untyped,
),
}
actual := acc.GetTelegrafMetrics()
for _, a := range actual {
a.RemoveField("total")
a.RemoveField("total_threads")
}
testutil.RequireMetricsEqual(t, expected, actual,
testutil.IgnoreTime())
}

func testExecPS() ([]byte, error) {
return []byte(testPSOut), nil
}
Expand Down

0 comments on commit 52abd8e

Please sign in to comment.