Add support for parked process state on Linux (#6308)
This commit is contained in:
parent
718f60bb4a
commit
628edfa9b4
|
@ -32,6 +32,7 @@ Using the environment variable `HOST_PROC` the plugin will retrieve process info
|
||||||
- wait (freebsd only)
|
- wait (freebsd only)
|
||||||
- idle (bsd and Linux 4+ only)
|
- idle (bsd and Linux 4+ only)
|
||||||
- paging (linux only)
|
- paging (linux only)
|
||||||
|
- parked (linux only)
|
||||||
- total_threads (linux only)
|
- total_threads (linux only)
|
||||||
|
|
||||||
### Process State Mappings
|
### Process State Mappings
|
||||||
|
|
|
@ -178,6 +178,11 @@ func (p *Processes) gatherFromProc(fields map[string]interface{}) error {
|
||||||
fields["paging"] = fields["paging"].(int64) + int64(1)
|
fields["paging"] = fields["paging"].(int64) + int64(1)
|
||||||
case 'I':
|
case 'I':
|
||||||
fields["idle"] = fields["idle"].(int64) + int64(1)
|
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:
|
default:
|
||||||
log.Printf("I! processes: Unknown state [ %s ] in file %s",
|
log.Printf("I! processes: Unknown state [ %s ] in file %s",
|
||||||
string(stats[0][0]), filename)
|
string(stats[0][0]), filename)
|
||||||
|
|
|
@ -6,7 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -107,6 +109,56 @@ func TestFromProcFilesWithSpaceInCmd(t *testing.T) {
|
||||||
acc.AssertContainsTaggedFields(t, "processes", fields, map[string]string{})
|
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) {
|
func testExecPS() ([]byte, error) {
|
||||||
return []byte(testPSOut), nil
|
return []byte(testPSOut), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue