Add support for parked process state on Linux (#6308)

This commit is contained in:
Daniel Nelson 2019-08-26 16:05:56 -07:00 committed by GitHub
parent 718f60bb4a
commit 628edfa9b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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"
@ -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
}