From 9d4c2824fcd8ad9fbcec1c07a959246611e72cf0 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 8 Dec 2017 20:31:36 +0000 Subject: [PATCH 01/29] remove pgrep for pattern matches, use go-ps instead --- plugins/inputs/procstat/pgrep.go | 37 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go index bae5161e4fe6d..019b6993362f6 100644 --- a/plugins/inputs/procstat/pgrep.go +++ b/plugins/inputs/procstat/pgrep.go @@ -2,8 +2,10 @@ package procstat import ( "fmt" + GOPS "github.com/keybase/go-ps" "io/ioutil" "os/exec" + "regexp" "strconv" "strings" ) @@ -43,18 +45,37 @@ func (pg *Pgrep) PidFile(path string) ([]PID, error) { return pids, nil } -func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { - args := []string{pattern} - return find(pg.path, args) +func (pg Pgrep) Pattern(pattern string) (pids []PID, err error) { + pids = make([]PID, 0, 0) + procs, err := GOPS.Processes() + if err != nil { + return pids, err + } + + regx, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + for _, p := range procs { + path, err := p.Path() + if err != nil { + // ignore errors, when this fails + // it means you don't have the permissions to see the process + } + if regx.MatchString(path) { + fmt.Println("PROC PATH: ", path) + pids = append(pids, PID(p.Pid())) + } + } + return pids, nil } -func (pg *Pgrep) Uid(user string) ([]PID, error) { - args := []string{"-u", user} - return find(pg.path, args) +func (pg Pgrep) FullPattern(pattern string) ([]PID, error) { + return pg.Pattern(pattern) } -func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { - args := []string{"-f", pattern} +func (pg *Pgrep) Uid(user string) ([]PID, error) { + args := []string{"-u", user} return find(pg.path, args) } From a54fd8d2f999300df7d8a20fd9531f73cd60fb52 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 8 Dec 2017 20:35:34 +0000 Subject: [PATCH 02/29] add dep --- Godeps | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Godeps b/Godeps index 252e0b4b2ebec..fa4dec10f6570 100644 --- a/Godeps +++ b/Godeps @@ -1,4 +1,6 @@ collectd.org 2ce144541b8903101fb8f1483cc0497a68798122 +github.com/Shopify/sarama c01858abb625b73a3af51d0798e4ad42c8147093 +github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d github.com/aerospike/aerospike-client-go 95e1ad7791bdbca44707fedbb29be42024900d9c github.com/amir/raidman c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985 github.com/apache/thrift 4aaa92ece8503a6da9bc6701604f69acf2b99d07 @@ -20,26 +22,22 @@ github.com/eclipse/paho.mqtt.golang d4f545eb108a2d19f9b1a735689dbfb719bc21fb github.com/go-logfmt/logfmt 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/gobwas/glob bea32b9cd2d6f55753d94a28e959b13f0244797a -github.com/go-ini/ini 9144852efba7c4daf409943ee90767da62d55438 github.com/gogo/protobuf 7b6c6391c4ff245962047fc1e2c6e08b1cdfa0e8 github.com/golang/protobuf 8ee79997227bf9b34611aee7946ae64735e6fd93 github.com/golang/snappy 7db9049039a047d955fe8c19b83c8ff5abd765c7 -github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7 github.com/google/go-cmp f94e52cad91c65a63acc1e75d4be223ea22e99bc github.com/gorilla/mux 392c28fe23e1c45ddba891b0320b3b5df220beea -github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478 github.com/hashicorp/consul 63d2fc68239b996096a1c55a0d4b400ea4c2583f github.com/influxdata/tail a395bf99fe07c233f41fba0735fa2b13b58588ea github.com/influxdata/toml 5d1d907f22ead1cd47adde17ceec5bda9cacaf8f github.com/influxdata/wlog 7c63b0a71ef8300adc255344d275e10e5c3a71ec github.com/jackc/pgx 63f58fd32edb5684b9e9f4cfaac847c6b42b3917 -github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/kardianos/osext c2c54e542fb797ad986b31721e1baedf214ca413 github.com/kardianos/service 6d3a0ee7d3425d9d835debc51a0ca1ffa28f4893 github.com/kballard/go-shellquote d8ec1a69a250a17bb0e419c386eac1f3711dc142 +github.com/keybase/go-ps 668c8856d9992f97248b3177d45743d2cc1068db github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c -github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 github.com/miekg/dns 99f84ae56e75126dd77e5de4fae2ea034a468ca1 github.com/mitchellh/mapstructure d0303fe809921458f417bcf828397a65db30a7e4 github.com/multiplay/go-ts3 07477f49b8dfa3ada231afc7b7b17617d42afe8e @@ -55,7 +53,6 @@ github.com/openzipkin/zipkin-go-opentracing 1cafbdfde94fbf2b373534764e0863aa3bd0 github.com/pierrec/lz4 5c9560bfa9ace2bf86080bf40d46b34ae44604df github.com/pierrec/xxHash 5a004441f897722c627870a981d02b29924215fa github.com/pkg/errors 645ef00459ed84a119197bfb8d8205042c6df63d -github.com/pmezard/go-difflib/difflib 792786c7400a136282c1664665ae0a8db921c6c2 github.com/prometheus/client_golang c317fb74746eac4fc65fe3909195f4cf67c5562a github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6 github.com/prometheus/common dd2f054febf4a6c00f2343686efb775948a8bff4 @@ -64,13 +61,8 @@ github.com/rcrowley/go-metrics 1f30fe9094a513ce4c700b9a54458bbb0c96996c github.com/samuel/go-zookeeper 1d7be4effb13d2d908342d349d71a284a7542693 github.com/satori/go.uuid 5bf94b69c6b68ee1b541973bb8e1144db23a194b github.com/shirou/gopsutil 384a55110aa5ae052eb93ea94940548c1e305a99 -github.com/shirou/w32 3c9377fc6748f222729a8270fe2775d149a249ad -github.com/Shopify/sarama c01858abb625b73a3af51d0798e4ad42c8147093 -github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d github.com/soniah/gosnmp 5ad50dc75ab389f8a1c9f8a67d3a1cd85f67ed15 -github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5 github.com/streadway/amqp 63795daa9a446c920826655f26ba31c81c860fd6 -github.com/stretchr/objx 1a9d0bb9f541897e62256577b352fdbc1fb4fd94 github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987 github.com/vjeantet/grok d73e972b60935c7fec0b4ffbc904ed39ecaf7efe github.com/wvanbergen/kafka bc265fedb9ff5b5c5d3c0fdcef4a819b3523d3ee @@ -83,10 +75,8 @@ golang.org/x/sys 739734461d1c916b6c72a63d7efda2b27edb369f golang.org/x/text 506f9d5c962f284575e88337e7d9296d27e729d3 gopkg.in/asn1-ber.v1 4e86f4367175e39f69d9358a5f17b4dda270378d gopkg.in/fatih/pool.v2 6e328e67893eb46323ad06f0e92cb9536babbabc -gopkg.in/fsnotify.v1 a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb gopkg.in/gorethink/gorethink.v3 7ab832f7b65573104a555d84a27992ae9ea1f659 gopkg.in/ldap.v2 8168ee085ee43257585e50c6441aadf54ecb2c9f gopkg.in/mgo.v2 3f83fa5005286a7fe593b055f0d7771a7dce4655 gopkg.in/olivere/elastic.v5 3113f9b9ad37509fe5f8a0e5e91c96fdc4435e26 -gopkg.in/tomb.v1 dd632973f1e7218eb1089048e0798ec9ae7dceb8 gopkg.in/yaml.v2 4c78c975fe7c825c6d1466c42be594d1d6f3aba6 From c47eaef0317968f3aafb645f3a5668fb09df2588 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 8 Dec 2017 20:52:56 +0000 Subject: [PATCH 03/29] remove debug --- plugins/inputs/procstat/pgrep.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go index 019b6993362f6..72328045b704c 100644 --- a/plugins/inputs/procstat/pgrep.go +++ b/plugins/inputs/procstat/pgrep.go @@ -63,7 +63,6 @@ func (pg Pgrep) Pattern(pattern string) (pids []PID, err error) { // it means you don't have the permissions to see the process } if regx.MatchString(path) { - fmt.Println("PROC PATH: ", path) pids = append(pids, PID(p.Pid())) } } From a2f429bdaee1baa8b6c84a1e790cdea294df4e84 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Sat, 9 Dec 2017 19:23:31 -0700 Subject: [PATCH 04/29] working implementation using the new gopsutil --- plugins/inputs/procstat/pgrep.go | 91 ------------------------ plugins/inputs/procstat/process.go | 7 ++ plugins/inputs/procstat/procstat_test.go | 2 + 3 files changed, 9 insertions(+), 91 deletions(-) delete mode 100644 plugins/inputs/procstat/pgrep.go diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go deleted file mode 100644 index bae5161e4fe6d..0000000000000 --- a/plugins/inputs/procstat/pgrep.go +++ /dev/null @@ -1,91 +0,0 @@ -package procstat - -import ( - "fmt" - "io/ioutil" - "os/exec" - "strconv" - "strings" -) - -type PIDFinder interface { - PidFile(path string) ([]PID, error) - Pattern(pattern string) ([]PID, error) - Uid(user string) ([]PID, error) - FullPattern(path string) ([]PID, error) -} - -// Implemention of PIDGatherer that execs pgrep to find processes -type Pgrep struct { - path string -} - -func NewPgrep() (PIDFinder, error) { - path, err := exec.LookPath("pgrep") - if err != nil { - return nil, fmt.Errorf("Could not find pgrep binary: %s", err) - } - return &Pgrep{path}, nil -} - -func (pg *Pgrep) PidFile(path string) ([]PID, error) { - var pids []PID - pidString, err := ioutil.ReadFile(path) - if err != nil { - return pids, fmt.Errorf("Failed to read pidfile '%s'. Error: '%s'", - path, err) - } - pid, err := strconv.Atoi(strings.TrimSpace(string(pidString))) - if err != nil { - return pids, err - } - pids = append(pids, PID(pid)) - return pids, nil -} - -func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { - args := []string{pattern} - return find(pg.path, args) -} - -func (pg *Pgrep) Uid(user string) ([]PID, error) { - args := []string{"-u", user} - return find(pg.path, args) -} - -func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { - args := []string{"-f", pattern} - return find(pg.path, args) -} - -func find(path string, args []string) ([]PID, error) { - out, err := run(path, args) - if err != nil { - return nil, err - } - - return parseOutput(out) -} - -func run(path string, args []string) (string, error) { - out, err := exec.Command(path, args...).Output() - if err != nil { - return "", fmt.Errorf("Error running %s: %s", path, err) - } - return string(out), err -} - -func parseOutput(out string) ([]PID, error) { - pids := []PID{} - fields := strings.Fields(out) - for _, field := range fields { - pid, err := strconv.Atoi(field) - if err != nil { - return nil, err - } - if err == nil { - pids = append(pids, PID(pid)) - } - } - return pids, nil -} diff --git a/plugins/inputs/procstat/process.go b/plugins/inputs/procstat/process.go index 3470a8a94cbf5..361582c334119 100644 --- a/plugins/inputs/procstat/process.go +++ b/plugins/inputs/procstat/process.go @@ -23,6 +23,13 @@ type Process interface { RlimitUsage(bool) ([]process.RlimitStat, error) } +type PIDFinder interface { + PidFile(path string) ([]PID, error) + Pattern(pattern string) ([]PID, error) + Uid(user string) ([]PID, error) + FullPattern(path string) ([]PID, error) +} + type Proc struct { hasCPUTimes bool tags map[string]string diff --git a/plugins/inputs/procstat/procstat_test.go b/plugins/inputs/procstat/procstat_test.go index 7b9d6f0c3a4b1..4fbc769c549ee 100644 --- a/plugins/inputs/procstat/procstat_test.go +++ b/plugins/inputs/procstat/procstat_test.go @@ -1,3 +1,5 @@ +// +build !windows + package procstat import ( From 4b26b52691c6ff7086925a4af5b379e8f736b6bb Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Sat, 9 Dec 2017 19:26:57 -0700 Subject: [PATCH 05/29] windows files and build changes for reg pgrep --- plugins/inputs/procstat/pgrep.go | 86 +++++++++++++++++++ plugins/inputs/procstat/pgrep_windows.go | 49 +++++++++++ .../inputs/procstat/procstat_windows_test.go | 24 ++++++ 3 files changed, 159 insertions(+) create mode 100644 plugins/inputs/procstat/pgrep.go create mode 100644 plugins/inputs/procstat/pgrep_windows.go create mode 100644 plugins/inputs/procstat/procstat_windows_test.go diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go new file mode 100644 index 0000000000000..5cd861416504c --- /dev/null +++ b/plugins/inputs/procstat/pgrep.go @@ -0,0 +1,86 @@ +// +build !windows + +package procstat + +import ( + "fmt" + "io/ioutil" + "os/exec" + "strconv" + "strings" +) + +// Implemention of PIDGatherer that execs pgrep to find processes +type Pgrep struct { + path string +} + +func NewPgrep() (PIDFinder, error) { + path, err := exec.LookPath("pgrep") + if err != nil { + return nil, fmt.Errorf("Could not find pgrep binary: %s", err) + } + return &Pgrep{path}, nil +} + +func (pg *Pgrep) PidFile(path string) ([]PID, error) { + var pids []PID + pidString, err := ioutil.ReadFile(path) + if err != nil { + return pids, fmt.Errorf("Failed to read pidfile '%s'. Error: '%s'", + path, err) + } + pid, err := strconv.Atoi(strings.TrimSpace(string(pidString))) + if err != nil { + return pids, err + } + pids = append(pids, PID(pid)) + return pids, nil +} + +func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { + args := []string{pattern} + return find(pg.path, args) +} + +func (pg *Pgrep) Uid(user string) ([]PID, error) { + args := []string{"-u", user} + return find(pg.path, args) +} + +func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { + args := []string{"-f", pattern} + return find(pg.path, args) +} + +func find(path string, args []string) ([]PID, error) { + out, err := run(path, args) + if err != nil { + return nil, err + } + + return parseOutput(out) +} + +func run(path string, args []string) (string, error) { + out, err := exec.Command(path, args...).Output() + if err != nil { + return "", fmt.Errorf("Error running %s: %s", path, err) + } + return string(out), err +} + +func parseOutput(out string) ([]PID, error) { + pids := []PID{} + fields := strings.Fields(out) + for _, field := range fields { + pid, err := strconv.Atoi(field) + if err != nil { + return nil, err + } + if err == nil { + pids = append(pids, PID(pid)) + } + } + return pids, nil +} diff --git a/plugins/inputs/procstat/pgrep_windows.go b/plugins/inputs/procstat/pgrep_windows.go new file mode 100644 index 0000000000000..3555ac2a4abdc --- /dev/null +++ b/plugins/inputs/procstat/pgrep_windows.go @@ -0,0 +1,49 @@ +package procstat + +import ( + "errors" + + "github.com/shirou/gopsutil/process" +) + +var ErrorNotImplemented = errors.New("not implemented in windows") + +// Implemention of PIDGatherer that execs pgrep to find processes +type Pgrep struct { +} + +func NewPgrep() (PIDFinder, error) { + return &Pgrep{}, nil +} + +func (pg *Pgrep) PidFile(path string) ([]PID, error) { + return nil, ErrorNotImplemented +} + +func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { + pids := make([]PID, 0) + procs, err := process.GetWin32ProcsByName(pattern) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { + pids := make([]PID, 0) + procs, err := process.GetWin32ProcsByCmdLine(pattern) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +func (pg *Pgrep) Uid(user string) ([]PID, error) { + return nil, ErrorNotImplemented +} diff --git a/plugins/inputs/procstat/procstat_windows_test.go b/plugins/inputs/procstat/procstat_windows_test.go new file mode 100644 index 0000000000000..10a92b9c98354 --- /dev/null +++ b/plugins/inputs/procstat/procstat_windows_test.go @@ -0,0 +1,24 @@ +package procstat + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGather_RealPattern(t *testing.T) { + pg, err := NewPgrep() + require.NoError(t, err) + pids, err := pg.Pattern(`procstat`) + require.NoError(t, err) + assert.Equal(t, len(pids) > 0, true) +} + +func TestGather_RealFullPattern(t *testing.T) { + pg, err := NewPgrep() + require.NoError(t, err) + pids, err := pg.FullPattern(`procstat`) + require.NoError(t, err) + assert.Equal(t, len(pids) > 0, true) +} From 8b66be934d8bfc895396c15a2edc81edbf22915e Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Sat, 9 Dec 2017 20:00:23 -0700 Subject: [PATCH 06/29] update the make file to test the new windows tests --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index d8ccf2faf4746..f45a23a0b7680 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ test-windows: go test ./plugins/inputs/ping/... go test ./plugins/inputs/win_perf_counters/... go test ./plugins/inputs/win_services/... + go test ./plugins/inputs/procstat/... lint: go vet ./... From 54ffbd207699e2cdc822907ed77fd613492ced87 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Sat, 9 Dec 2017 20:02:11 -0700 Subject: [PATCH 07/29] update gopsutil with new wmi queries --- Godeps | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Godeps b/Godeps index f69949c29cbbc..b025cd194ab46 100644 --- a/Godeps +++ b/Godeps @@ -1,4 +1,8 @@ collectd.org 2ce144541b8903101fb8f1483cc0497a68798122 +github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 +github.com/Shopify/sarama 3b1b38866a79f06deddf0487d5c27ba0697ccd65 +github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d +github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5 github.com/aerospike/aerospike-client-go 95e1ad7791bdbca44707fedbb29be42024900d9c github.com/amir/raidman c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985 github.com/apache/thrift 4aaa92ece8503a6da9bc6701604f69acf2b99d07 @@ -18,28 +22,25 @@ github.com/eapache/go-xerial-snappy bb955e01b9346ac19dc29eb16586c90ded99a98c github.com/eapache/queue 44cc805cf13205b55f69e14bcb69867d1ae92f98 github.com/eclipse/paho.mqtt.golang d4f545eb108a2d19f9b1a735689dbfb719bc21fb github.com/go-logfmt/logfmt 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 +github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7 github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/gobwas/glob bea32b9cd2d6f55753d94a28e959b13f0244797a -github.com/go-ini/ini 9144852efba7c4daf409943ee90767da62d55438 github.com/gogo/protobuf 7b6c6391c4ff245962047fc1e2c6e08b1cdfa0e8 github.com/golang/protobuf 8ee79997227bf9b34611aee7946ae64735e6fd93 github.com/golang/snappy 7db9049039a047d955fe8c19b83c8ff5abd765c7 -github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7 github.com/google/go-cmp f94e52cad91c65a63acc1e75d4be223ea22e99bc github.com/gorilla/mux 392c28fe23e1c45ddba891b0320b3b5df220beea -github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478 github.com/hashicorp/consul 63d2fc68239b996096a1c55a0d4b400ea4c2583f github.com/influxdata/tail a395bf99fe07c233f41fba0735fa2b13b58588ea +github.com/influxdata/telegraf 8b66be934d8bfc895396c15a2edc81edbf22915e github.com/influxdata/toml 5d1d907f22ead1cd47adde17ceec5bda9cacaf8f github.com/influxdata/wlog 7c63b0a71ef8300adc255344d275e10e5c3a71ec github.com/jackc/pgx 63f58fd32edb5684b9e9f4cfaac847c6b42b3917 -github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/kardianos/osext c2c54e542fb797ad986b31721e1baedf214ca413 github.com/kardianos/service 6d3a0ee7d3425d9d835debc51a0ca1ffa28f4893 github.com/kballard/go-shellquote d8ec1a69a250a17bb0e419c386eac1f3711dc142 github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c -github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 github.com/miekg/dns 99f84ae56e75126dd77e5de4fae2ea034a468ca1 github.com/mitchellh/mapstructure d0303fe809921458f417bcf828397a65db30a7e4 github.com/multiplay/go-ts3 07477f49b8dfa3ada231afc7b7b17617d42afe8e @@ -48,14 +49,12 @@ github.com/nats-io/go-nats ea9585611a4ab58a205b9b125ebd74c389a6b898 github.com/nats-io/nats ea9585611a4ab58a205b9b125ebd74c389a6b898 github.com/nats-io/nuid 289cccf02c178dc782430d534e3c1f5b72af807f github.com/nsqio/go-nsq eee57a3ac4174c55924125bb15eeeda8cffb6e6f -github.com/opencontainers/runc 89ab7f2ccc1e45ddf6485eaa802c35dcf321dfc8 github.com/opentracing-contrib/go-observer a52f2342449246d5bcc273e65cbdcfa5f7d6c63c github.com/opentracing/opentracing-go 06f47b42c792fef2796e9681353e1d908c417827 github.com/openzipkin/zipkin-go-opentracing 1cafbdfde94fbf2b373534764e0863aa3bd0bf7b github.com/pierrec/lz4 5c9560bfa9ace2bf86080bf40d46b34ae44604df github.com/pierrec/xxHash 5a004441f897722c627870a981d02b29924215fa github.com/pkg/errors 645ef00459ed84a119197bfb8d8205042c6df63d -github.com/pmezard/go-difflib/difflib 792786c7400a136282c1664665ae0a8db921c6c2 github.com/prometheus/client_golang c317fb74746eac4fc65fe3909195f4cf67c5562a github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6 github.com/prometheus/common dd2f054febf4a6c00f2343686efb775948a8bff4 @@ -63,14 +62,10 @@ github.com/prometheus/procfs 1878d9fbb537119d24b21ca07effd591627cd160 github.com/rcrowley/go-metrics 1f30fe9094a513ce4c700b9a54458bbb0c96996c github.com/samuel/go-zookeeper 1d7be4effb13d2d908342d349d71a284a7542693 github.com/satori/go.uuid 5bf94b69c6b68ee1b541973bb8e1144db23a194b -github.com/shirou/gopsutil 384a55110aa5ae052eb93ea94940548c1e305a99 -github.com/shirou/w32 3c9377fc6748f222729a8270fe2775d149a249ad -github.com/Shopify/sarama 3b1b38866a79f06deddf0487d5c27ba0697ccd65 -github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d +github.com/shirou/gopsutil 7119e95dd33acda5f6188ebb07e56e9307c7258d +github.com/shirou/w32 bb4de0191aa41b5507caa14b0650cdbddcd9280b github.com/soniah/gosnmp 5ad50dc75ab389f8a1c9f8a67d3a1cd85f67ed15 -github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5 github.com/streadway/amqp 63795daa9a446c920826655f26ba31c81c860fd6 -github.com/stretchr/objx 1a9d0bb9f541897e62256577b352fdbc1fb4fd94 github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987 github.com/vjeantet/grok d73e972b60935c7fec0b4ffbc904ed39ecaf7efe github.com/wvanbergen/kafka bc265fedb9ff5b5c5d3c0fdcef4a819b3523d3ee @@ -83,10 +78,8 @@ golang.org/x/sys 739734461d1c916b6c72a63d7efda2b27edb369f golang.org/x/text 506f9d5c962f284575e88337e7d9296d27e729d3 gopkg.in/asn1-ber.v1 4e86f4367175e39f69d9358a5f17b4dda270378d gopkg.in/fatih/pool.v2 6e328e67893eb46323ad06f0e92cb9536babbabc -gopkg.in/fsnotify.v1 a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb gopkg.in/gorethink/gorethink.v3 7ab832f7b65573104a555d84a27992ae9ea1f659 gopkg.in/ldap.v2 8168ee085ee43257585e50c6441aadf54ecb2c9f gopkg.in/mgo.v2 3f83fa5005286a7fe593b055f0d7771a7dce4655 gopkg.in/olivere/elastic.v5 3113f9b9ad37509fe5f8a0e5e91c96fdc4435e26 -gopkg.in/tomb.v1 dd632973f1e7218eb1089048e0798ec9ae7dceb8 gopkg.in/yaml.v2 4c78c975fe7c825c6d1466c42be594d1d6f3aba6 From 0722c4ab1fbd4674ff6292a86fdb288aa5332ac2 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 12 Dec 2017 16:05:53 +0000 Subject: [PATCH 08/29] add docs --- plugins/inputs/procstat/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 00820be9a1b1f..0cddea720a47c 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -22,6 +22,16 @@ On the other hand, if an executable is used an "exe" tag will be generated. Poss * systemd_unit * cgroup +[Windows] +On windows we only support exe and pattern. Both of these are implemented using WMI queries. exe is on the Name field and pattern is on the CommandLine field. + +Example WMI Qurries: + +* exe ```WHERE CommandLine LIKE $pattern ``` +* pattern ```WHERE Name LIKE $pattern ``` + +this allows you to do fuzzy matching but only [support WMI query patterns](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). + Additionally the plugin will tag processes by their PID (pid_tag = true in the config) and their process name: * pid From aff075bd65155c7762efa3298791e22584902f97 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 12 Dec 2017 16:07:41 +0000 Subject: [PATCH 09/29] doc cleanup --- plugins/inputs/procstat/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 0cddea720a47c..2c4120d9c78d5 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -22,7 +22,7 @@ On the other hand, if an executable is used an "exe" tag will be generated. Poss * systemd_unit * cgroup -[Windows] +### Windows On windows we only support exe and pattern. Both of these are implemented using WMI queries. exe is on the Name field and pattern is on the CommandLine field. Example WMI Qurries: @@ -30,7 +30,7 @@ Example WMI Qurries: * exe ```WHERE CommandLine LIKE $pattern ``` * pattern ```WHERE Name LIKE $pattern ``` -this allows you to do fuzzy matching but only [support WMI query patterns](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). +this allows you to do fuzzy matching but only what is supported by [WMI query patterns](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). Additionally the plugin will tag processes by their PID (pid_tag = true in the config) and their process name: From e402310610c8d8366d2b33995390a2c0590d127b Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 12 Dec 2017 16:08:51 +0000 Subject: [PATCH 10/29] move things around in the doc --- plugins/inputs/procstat/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 2c4120d9c78d5..827098839e0c4 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -22,6 +22,12 @@ On the other hand, if an executable is used an "exe" tag will be generated. Poss * systemd_unit * cgroup +Additionally the plugin will tag processes by their PID (pid_tag = true in the config) and their process name: + +* pid +* process_name + + ### Windows On windows we only support exe and pattern. Both of these are implemented using WMI queries. exe is on the Name field and pattern is on the CommandLine field. @@ -32,10 +38,7 @@ Example WMI Qurries: this allows you to do fuzzy matching but only what is supported by [WMI query patterns](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). -Additionally the plugin will tag processes by their PID (pid_tag = true in the config) and their process name: -* pid -* process_name Example: From d85d89b3cb916f3325825855c92cac9941fa9a99 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 12 Dec 2017 16:14:30 +0000 Subject: [PATCH 11/29] more cleanup on the docs --- plugins/inputs/procstat/README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index 827098839e0c4..c9763b79d2b7f 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -31,16 +31,21 @@ Additionally the plugin will tag processes by their PID (pid_tag = true in the c ### Windows On windows we only support exe and pattern. Both of these are implemented using WMI queries. exe is on the Name field and pattern is on the CommandLine field. -Example WMI Qurries: - -* exe ```WHERE CommandLine LIKE $pattern ``` -* pattern ```WHERE Name LIKE $pattern ``` +Windows Support: +* exe (WMI Name) +* pattern (WMI CommandLine) this allows you to do fuzzy matching but only what is supported by [WMI query patterns](https://msdn.microsoft.com/en-us/library/aa392263(v=vs.85).aspx). +Example: +Windows fuzzy matching: +```[[inputs.procstat]] + exe = "%influx%" + process_name="influxd" + prefix = "influxd" -Example: +``` ``` [[inputs.procstat]] @@ -61,7 +66,6 @@ The above configuration would result in output like: # Measurements Note: prefix can be set by the user, per process. - Threads related measurement names: - procstat_[prefix_]num_threads value=5 From 56a02967fd70249c76a34e00c20615dbb3c767df Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 12 Dec 2017 16:15:29 +0000 Subject: [PATCH 12/29] make doc a little more clear --- plugins/inputs/procstat/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/inputs/procstat/README.md b/plugins/inputs/procstat/README.md index c9763b79d2b7f..153b893d3494e 100644 --- a/plugins/inputs/procstat/README.md +++ b/plugins/inputs/procstat/README.md @@ -47,6 +47,8 @@ Windows fuzzy matching: ``` +### Linux + ``` [[inputs.procstat]] exe = "influxd" From 452f496fd7ef15834a431466f564c1111e526f27 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 14 Dec 2017 22:22:01 -0700 Subject: [PATCH 13/29] revert godeps to old version of gopsutil and implement it directly --- Godeps | 23 +++++++---- plugins/inputs/procstat/pgrep_windows.go | 52 +++++++++++++++++++++++- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Godeps b/Godeps index b025cd194ab46..f69949c29cbbc 100644 --- a/Godeps +++ b/Godeps @@ -1,8 +1,4 @@ collectd.org 2ce144541b8903101fb8f1483cc0497a68798122 -github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 -github.com/Shopify/sarama 3b1b38866a79f06deddf0487d5c27ba0697ccd65 -github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d -github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5 github.com/aerospike/aerospike-client-go 95e1ad7791bdbca44707fedbb29be42024900d9c github.com/amir/raidman c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985 github.com/apache/thrift 4aaa92ece8503a6da9bc6701604f69acf2b99d07 @@ -22,25 +18,28 @@ github.com/eapache/go-xerial-snappy bb955e01b9346ac19dc29eb16586c90ded99a98c github.com/eapache/queue 44cc805cf13205b55f69e14bcb69867d1ae92f98 github.com/eclipse/paho.mqtt.golang d4f545eb108a2d19f9b1a735689dbfb719bc21fb github.com/go-logfmt/logfmt 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 -github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7 github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/gobwas/glob bea32b9cd2d6f55753d94a28e959b13f0244797a +github.com/go-ini/ini 9144852efba7c4daf409943ee90767da62d55438 github.com/gogo/protobuf 7b6c6391c4ff245962047fc1e2c6e08b1cdfa0e8 github.com/golang/protobuf 8ee79997227bf9b34611aee7946ae64735e6fd93 github.com/golang/snappy 7db9049039a047d955fe8c19b83c8ff5abd765c7 +github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7 github.com/google/go-cmp f94e52cad91c65a63acc1e75d4be223ea22e99bc github.com/gorilla/mux 392c28fe23e1c45ddba891b0320b3b5df220beea +github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034 github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478 github.com/hashicorp/consul 63d2fc68239b996096a1c55a0d4b400ea4c2583f github.com/influxdata/tail a395bf99fe07c233f41fba0735fa2b13b58588ea -github.com/influxdata/telegraf 8b66be934d8bfc895396c15a2edc81edbf22915e github.com/influxdata/toml 5d1d907f22ead1cd47adde17ceec5bda9cacaf8f github.com/influxdata/wlog 7c63b0a71ef8300adc255344d275e10e5c3a71ec github.com/jackc/pgx 63f58fd32edb5684b9e9f4cfaac847c6b42b3917 +github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/kardianos/osext c2c54e542fb797ad986b31721e1baedf214ca413 github.com/kardianos/service 6d3a0ee7d3425d9d835debc51a0ca1ffa28f4893 github.com/kballard/go-shellquote d8ec1a69a250a17bb0e419c386eac1f3711dc142 github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c +github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 github.com/miekg/dns 99f84ae56e75126dd77e5de4fae2ea034a468ca1 github.com/mitchellh/mapstructure d0303fe809921458f417bcf828397a65db30a7e4 github.com/multiplay/go-ts3 07477f49b8dfa3ada231afc7b7b17617d42afe8e @@ -49,12 +48,14 @@ github.com/nats-io/go-nats ea9585611a4ab58a205b9b125ebd74c389a6b898 github.com/nats-io/nats ea9585611a4ab58a205b9b125ebd74c389a6b898 github.com/nats-io/nuid 289cccf02c178dc782430d534e3c1f5b72af807f github.com/nsqio/go-nsq eee57a3ac4174c55924125bb15eeeda8cffb6e6f +github.com/opencontainers/runc 89ab7f2ccc1e45ddf6485eaa802c35dcf321dfc8 github.com/opentracing-contrib/go-observer a52f2342449246d5bcc273e65cbdcfa5f7d6c63c github.com/opentracing/opentracing-go 06f47b42c792fef2796e9681353e1d908c417827 github.com/openzipkin/zipkin-go-opentracing 1cafbdfde94fbf2b373534764e0863aa3bd0bf7b github.com/pierrec/lz4 5c9560bfa9ace2bf86080bf40d46b34ae44604df github.com/pierrec/xxHash 5a004441f897722c627870a981d02b29924215fa github.com/pkg/errors 645ef00459ed84a119197bfb8d8205042c6df63d +github.com/pmezard/go-difflib/difflib 792786c7400a136282c1664665ae0a8db921c6c2 github.com/prometheus/client_golang c317fb74746eac4fc65fe3909195f4cf67c5562a github.com/prometheus/client_model fa8ad6fec33561be4280a8f0514318c79d7f6cb6 github.com/prometheus/common dd2f054febf4a6c00f2343686efb775948a8bff4 @@ -62,10 +63,14 @@ github.com/prometheus/procfs 1878d9fbb537119d24b21ca07effd591627cd160 github.com/rcrowley/go-metrics 1f30fe9094a513ce4c700b9a54458bbb0c96996c github.com/samuel/go-zookeeper 1d7be4effb13d2d908342d349d71a284a7542693 github.com/satori/go.uuid 5bf94b69c6b68ee1b541973bb8e1144db23a194b -github.com/shirou/gopsutil 7119e95dd33acda5f6188ebb07e56e9307c7258d -github.com/shirou/w32 bb4de0191aa41b5507caa14b0650cdbddcd9280b +github.com/shirou/gopsutil 384a55110aa5ae052eb93ea94940548c1e305a99 +github.com/shirou/w32 3c9377fc6748f222729a8270fe2775d149a249ad +github.com/Shopify/sarama 3b1b38866a79f06deddf0487d5c27ba0697ccd65 +github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d github.com/soniah/gosnmp 5ad50dc75ab389f8a1c9f8a67d3a1cd85f67ed15 +github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5 github.com/streadway/amqp 63795daa9a446c920826655f26ba31c81c860fd6 +github.com/stretchr/objx 1a9d0bb9f541897e62256577b352fdbc1fb4fd94 github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987 github.com/vjeantet/grok d73e972b60935c7fec0b4ffbc904ed39ecaf7efe github.com/wvanbergen/kafka bc265fedb9ff5b5c5d3c0fdcef4a819b3523d3ee @@ -78,8 +83,10 @@ golang.org/x/sys 739734461d1c916b6c72a63d7efda2b27edb369f golang.org/x/text 506f9d5c962f284575e88337e7d9296d27e729d3 gopkg.in/asn1-ber.v1 4e86f4367175e39f69d9358a5f17b4dda270378d gopkg.in/fatih/pool.v2 6e328e67893eb46323ad06f0e92cb9536babbabc +gopkg.in/fsnotify.v1 a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb gopkg.in/gorethink/gorethink.v3 7ab832f7b65573104a555d84a27992ae9ea1f659 gopkg.in/ldap.v2 8168ee085ee43257585e50c6441aadf54ecb2c9f gopkg.in/mgo.v2 3f83fa5005286a7fe593b055f0d7771a7dce4655 gopkg.in/olivere/elastic.v5 3113f9b9ad37509fe5f8a0e5e91c96fdc4435e26 +gopkg.in/tomb.v1 dd632973f1e7218eb1089048e0798ec9ae7dceb8 gopkg.in/yaml.v2 4c78c975fe7c825c6d1466c42be594d1d6f3aba6 diff --git a/plugins/inputs/procstat/pgrep_windows.go b/plugins/inputs/procstat/pgrep_windows.go index 3555ac2a4abdc..6aa844d6a15cf 100644 --- a/plugins/inputs/procstat/pgrep_windows.go +++ b/plugins/inputs/procstat/pgrep_windows.go @@ -1,13 +1,20 @@ package procstat import ( + "context" "errors" + "fmt" + "time" + "github.com/StackExchange/wmi" "github.com/shirou/gopsutil/process" ) var ErrorNotImplemented = errors.New("not implemented in windows") +//Timeout is the timeout used when making wmi calls +var Timeout = 5 * time.Second + // Implemention of PIDGatherer that execs pgrep to find processes type Pgrep struct { } @@ -22,7 +29,7 @@ func (pg *Pgrep) PidFile(path string) ([]PID, error) { func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { pids := make([]PID, 0) - procs, err := process.GetWin32ProcsByName(pattern) + procs, err := GetWin32ProcsByName(pattern, Timeout) if err != nil { return pids, err } @@ -34,7 +41,7 @@ func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { pids := make([]PID, 0) - procs, err := process.GetWin32ProcsByCmdLine(pattern) + procs, err := GetWin32ProcsByCmdLine(pattern, Timeout) if err != nil { return pids, err } @@ -47,3 +54,44 @@ func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { func (pg *Pgrep) Uid(user string) ([]PID, error) { return nil, ErrorNotImplemented } + +func GetWin32ProcsByCmdLine(cmdLine string, timeout time.Duration) ([]process.Win32_Process, error) { + var dst []process.Win32_Process + query := fmt.Sprint("WHERE CommandLine LIKE \"%", cmdLine, "%\"") + q := wmi.CreateQuery(&dst, query) + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + err := WMIQueryWithContext(ctx, q, &dst) + if err != nil { + return []process.Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) + } + return dst, nil +} + +func GetWin32ProcsByName(name string, timeout time.Duration) ([]process.Win32_Process, error) { + var dst []process.Win32_Process + query := fmt.Sprint("WHERE Name LIKE \"%", name, "%\"") + q := wmi.CreateQuery(&dst, query) + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + err := WMIQueryWithContext(ctx, q, &dst) + if err != nil { + return []process.Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) + } + return dst, nil +} + +// WMIQueryWithContext - wraps wmi.Query with a timed-out context to avoid hanging +func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, connectServerArgs ...interface{}) error { + errChan := make(chan error, 1) + go func() { + errChan <- wmi.Query(query, dst, connectServerArgs...) + }() + + select { + case <-ctx.Done(): + return ctx.Err() + case err := <-errChan: + return err + } +} From 93fc937c68ede995ea33a468ea4415395ae0c766 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 14 Dec 2017 22:37:15 -0700 Subject: [PATCH 14/29] remove extra dep --- Godeps | 1 - 1 file changed, 1 deletion(-) diff --git a/Godeps b/Godeps index ffb3d05be5f05..f69949c29cbbc 100644 --- a/Godeps +++ b/Godeps @@ -38,7 +38,6 @@ github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/kardianos/osext c2c54e542fb797ad986b31721e1baedf214ca413 github.com/kardianos/service 6d3a0ee7d3425d9d835debc51a0ca1ffa28f4893 github.com/kballard/go-shellquote d8ec1a69a250a17bb0e419c386eac1f3711dc142 -github.com/keybase/go-ps 668c8856d9992f97248b3177d45743d2cc1068db github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c github.com/Microsoft/go-winio ce2922f643c8fd76b46cadc7f404a06282678b34 github.com/miekg/dns 99f84ae56e75126dd77e5de4fae2ea034a468ca1 From e2f374c105f5d98d0fe15c3b1071fe74ca34854c Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Wed, 20 Dec 2017 14:06:14 -0700 Subject: [PATCH 15/29] revert change to pgrep --- plugins/inputs/procstat/pgrep.go | 36 +++++++------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go index 8ec2ef146c67f..5cd861416504c 100644 --- a/plugins/inputs/procstat/pgrep.go +++ b/plugins/inputs/procstat/pgrep.go @@ -4,10 +4,8 @@ package procstat import ( "fmt" - GOPS "github.com/keybase/go-ps" "io/ioutil" "os/exec" - "regexp" "strconv" "strings" ) @@ -40,32 +38,9 @@ func (pg *Pgrep) PidFile(path string) ([]PID, error) { return pids, nil } -func (pg Pgrep) Pattern(pattern string) (pids []PID, err error) { - pids = make([]PID, 0, 0) - procs, err := GOPS.Processes() - if err != nil { - return pids, err - } - - regx, err := regexp.Compile(pattern) - if err != nil { - return pids, err - } - for _, p := range procs { - path, err := p.Path() - if err != nil { - // ignore errors, when this fails - // it means you don't have the permissions to see the process - } - if regx.MatchString(path) { - pids = append(pids, PID(p.Pid())) - } - } - return pids, nil -} - -func (pg Pgrep) FullPattern(pattern string) ([]PID, error) { - return pg.Pattern(pattern) +func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { + args := []string{pattern} + return find(pg.path, args) } func (pg *Pgrep) Uid(user string) ([]PID, error) { @@ -73,6 +48,11 @@ func (pg *Pgrep) Uid(user string) ([]PID, error) { return find(pg.path, args) } +func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { + args := []string{"-f", pattern} + return find(pg.path, args) +} + func find(path string, args []string) ([]PID, error) { out, err := run(path, args) if err != nil { From 37c641611e658a39a710205d3bcd34550430a880 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 22 Dec 2017 15:45:07 -0700 Subject: [PATCH 16/29] windows version of nativeFinder is working --- plugins/inputs/procstat/nativeFinder.go | 66 +++++++++++++ plugins/inputs/procstat/nativeFinder_unix.go | 31 ++++++ .../inputs/procstat/nativeFinder_windows.go | 84 ++++++++++++++++ .../procstat/nativeFinder_windows_test.go | 40 ++++++++ plugins/inputs/procstat/pgrep.go | 2 - plugins/inputs/procstat/pgrep_windows.go | 97 ------------------- .../inputs/procstat/procstat_windows_test.go | 24 ----- 7 files changed, 221 insertions(+), 123 deletions(-) create mode 100644 plugins/inputs/procstat/nativeFinder.go create mode 100644 plugins/inputs/procstat/nativeFinder_unix.go create mode 100644 plugins/inputs/procstat/nativeFinder_windows.go create mode 100644 plugins/inputs/procstat/nativeFinder_windows_test.go delete mode 100644 plugins/inputs/procstat/pgrep_windows.go delete mode 100644 plugins/inputs/procstat/procstat_windows_test.go diff --git a/plugins/inputs/procstat/nativeFinder.go b/plugins/inputs/procstat/nativeFinder.go new file mode 100644 index 0000000000000..f767d048e67ed --- /dev/null +++ b/plugins/inputs/procstat/nativeFinder.go @@ -0,0 +1,66 @@ +package procstat + +import ( + "fmt" + "io/ioutil" + "strconv" + "strings" + + "github.com/shirou/gopsutil/process" +) + +//NativeFinder uses gopsutil to find processes +type NativeFinder struct { +} + +//NewNativeFinder ... +func NewNativeFinder() (PIDFinder, error) { + return &NativeFinder{}, nil +} + +//Uid will return all pids for the given user +func (pg *NativeFinder) Uid(user string) ([]PID, error) { + pids, err := getPidsByUser(user) + if err != nil { + return pids, err + } + return pids, nil +} + +//PidFile returns the pid from the pid file given. +func (pg *NativeFinder) PidFile(path string) ([]PID, error) { + var pids []PID + pidString, err := ioutil.ReadFile(path) + if err != nil { + return pids, fmt.Errorf("Failed to read pidfile '%s'. Error: '%s'", + path, err) + } + pid, err := strconv.Atoi(strings.TrimSpace(string(pidString))) + if err != nil { + return pids, err + } + pids = append(pids, PID(pid)) + return pids, nil + +} + +//getPidsByUser ... +func getPidsByUser(username string) ([]PID, error) { + var dst []PID + procs, err := process.Processes() + if err != nil { + return dst, err + } + for _, p := range procs { + user, err := p.Username() + if err != nil { + //skip, this can happen if we don't have permissions or + //the pid no longer exists + } + fmt.Println(user, ":", username) + if user == username { + dst = append(dst, PID(p.Pid)) + } + } + return dst, nil +} diff --git a/plugins/inputs/procstat/nativeFinder_unix.go b/plugins/inputs/procstat/nativeFinder_unix.go new file mode 100644 index 0000000000000..2f48d79947863 --- /dev/null +++ b/plugins/inputs/procstat/nativeFinder_unix.go @@ -0,0 +1,31 @@ +// +build !windows + +package procstat + +func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { + var pids []pid + procs, err := GetWin32ProcsByName(pattern, Timeout) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { + var pids []pid + procs, err := GetWin32ProcsByCmdLine(pattern, Timeout) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +func (pg *NativeFinder) Uid(user string) ([]PID, error) { + return nil, ErrorNotImplemented +} diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/nativeFinder_windows.go new file mode 100644 index 0000000000000..1c090a99f9d9f --- /dev/null +++ b/plugins/inputs/procstat/nativeFinder_windows.go @@ -0,0 +1,84 @@ +// +build windows + +package procstat + +import ( + "context" + "fmt" + "time" + + "github.com/StackExchange/wmi" + "github.com/shirou/gopsutil/process" +) + +//Timeout is the timeout used when making wmi calls +var Timeout = 5 * time.Second + +func init() { + wmi.DefaultClient.AllowMissingFields = true +} + +type queryType string + +const ( + like = queryType("LIKE") + equals = queryType("=") + notEqual = queryType("!=") +) + +//Pattern matches the process name on windows and will find a pattern using a WMI like query +func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { + var pids []PID + procs, err := getWin32ProcsByVariable("Name", like, pattern, Timeout) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +//FullPattern matches the cmdLine on windows and will find a pattern using a WMI like query +func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { + var pids []PID + procs, err := getWin32ProcsByVariable("CommandLine", like, pattern, Timeout) + if err != nil { + return pids, err + } + for _, p := range procs { + pids = append(pids, PID(p.ProcessID)) + } + return pids, nil +} + +//GetWin32ProcsByVariable allows you to query any variable with a like query +func getWin32ProcsByVariable(variable string, qType queryType, value string, timeout time.Duration) ([]process.Win32_Process, error) { + var dst []process.Win32_Process + var query string + query = fmt.Sprint("WHERE ", variable, " ", qType, " \"", value, "\"") + fmt.Println("Query: ", query) + q := wmi.CreateQuery(&dst, query) + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + err := WMIQueryWithContext(ctx, q, &dst) + if err != nil { + return []process.Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) + } + return dst, nil +} + +// WMIQueryWithContext - wraps wmi.Query with a timed-out context to avoid hanging +func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, connectServerArgs ...interface{}) error { + errChan := make(chan error, 1) + go func() { + errChan <- wmi.Query(query, dst, connectServerArgs...) + }() + + select { + case <-ctx.Done(): + return ctx.Err() + case err := <-errChan: + return err + } +} diff --git a/plugins/inputs/procstat/nativeFinder_windows_test.go b/plugins/inputs/procstat/nativeFinder_windows_test.go new file mode 100644 index 0000000000000..4c03cdd7de2fe --- /dev/null +++ b/plugins/inputs/procstat/nativeFinder_windows_test.go @@ -0,0 +1,40 @@ +package procstat + +import ( + "fmt" + "testing" + + "os/user" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGather_RealPattern(t *testing.T) { + pg, err := NewNativeFinder() + require.NoError(t, err) + pids, err := pg.Pattern(`procstat.test.exe`) + require.NoError(t, err) + fmt.Println(pids) + assert.Equal(t, len(pids) > 0, true) +} + +func TestGather_RealFullPattern(t *testing.T) { + pg, err := NewNativeFinder() + require.NoError(t, err) + pids, err := pg.FullPattern(`%procstat%`) + require.NoError(t, err) + fmt.Println(pids) + assert.Equal(t, len(pids) > 0, true) +} + +func TestGather_RealUser(t *testing.T) { + user, err := user.Current() + require.NoError(t, err) + pg, err := NewNativeFinder() + require.NoError(t, err) + pids, err := pg.Uid(fmt.Sprint(user.Username)) + require.NoError(t, err) + fmt.Println(pids) + assert.Equal(t, len(pids) > 0, true) +} diff --git a/plugins/inputs/procstat/pgrep.go b/plugins/inputs/procstat/pgrep.go index 5cd861416504c..cf0754e6dca32 100644 --- a/plugins/inputs/procstat/pgrep.go +++ b/plugins/inputs/procstat/pgrep.go @@ -1,5 +1,3 @@ -// +build !windows - package procstat import ( diff --git a/plugins/inputs/procstat/pgrep_windows.go b/plugins/inputs/procstat/pgrep_windows.go deleted file mode 100644 index 6aa844d6a15cf..0000000000000 --- a/plugins/inputs/procstat/pgrep_windows.go +++ /dev/null @@ -1,97 +0,0 @@ -package procstat - -import ( - "context" - "errors" - "fmt" - "time" - - "github.com/StackExchange/wmi" - "github.com/shirou/gopsutil/process" -) - -var ErrorNotImplemented = errors.New("not implemented in windows") - -//Timeout is the timeout used when making wmi calls -var Timeout = 5 * time.Second - -// Implemention of PIDGatherer that execs pgrep to find processes -type Pgrep struct { -} - -func NewPgrep() (PIDFinder, error) { - return &Pgrep{}, nil -} - -func (pg *Pgrep) PidFile(path string) ([]PID, error) { - return nil, ErrorNotImplemented -} - -func (pg *Pgrep) Pattern(pattern string) ([]PID, error) { - pids := make([]PID, 0) - procs, err := GetWin32ProcsByName(pattern, Timeout) - if err != nil { - return pids, err - } - for _, p := range procs { - pids = append(pids, PID(p.ProcessID)) - } - return pids, nil -} - -func (pg *Pgrep) FullPattern(pattern string) ([]PID, error) { - pids := make([]PID, 0) - procs, err := GetWin32ProcsByCmdLine(pattern, Timeout) - if err != nil { - return pids, err - } - for _, p := range procs { - pids = append(pids, PID(p.ProcessID)) - } - return pids, nil -} - -func (pg *Pgrep) Uid(user string) ([]PID, error) { - return nil, ErrorNotImplemented -} - -func GetWin32ProcsByCmdLine(cmdLine string, timeout time.Duration) ([]process.Win32_Process, error) { - var dst []process.Win32_Process - query := fmt.Sprint("WHERE CommandLine LIKE \"%", cmdLine, "%\"") - q := wmi.CreateQuery(&dst, query) - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - err := WMIQueryWithContext(ctx, q, &dst) - if err != nil { - return []process.Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) - } - return dst, nil -} - -func GetWin32ProcsByName(name string, timeout time.Duration) ([]process.Win32_Process, error) { - var dst []process.Win32_Process - query := fmt.Sprint("WHERE Name LIKE \"%", name, "%\"") - q := wmi.CreateQuery(&dst, query) - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - err := WMIQueryWithContext(ctx, q, &dst) - if err != nil { - return []process.Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err) - } - return dst, nil -} - -// WMIQueryWithContext - wraps wmi.Query with a timed-out context to avoid hanging -func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, connectServerArgs ...interface{}) error { - errChan := make(chan error, 1) - go func() { - errChan <- wmi.Query(query, dst, connectServerArgs...) - }() - - select { - case <-ctx.Done(): - return ctx.Err() - case err := <-errChan: - return err - } -} diff --git a/plugins/inputs/procstat/procstat_windows_test.go b/plugins/inputs/procstat/procstat_windows_test.go deleted file mode 100644 index 10a92b9c98354..0000000000000 --- a/plugins/inputs/procstat/procstat_windows_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package procstat - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestGather_RealPattern(t *testing.T) { - pg, err := NewPgrep() - require.NoError(t, err) - pids, err := pg.Pattern(`procstat`) - require.NoError(t, err) - assert.Equal(t, len(pids) > 0, true) -} - -func TestGather_RealFullPattern(t *testing.T) { - pg, err := NewPgrep() - require.NoError(t, err) - pids, err := pg.FullPattern(`procstat`) - require.NoError(t, err) - assert.Equal(t, len(pids) > 0, true) -} From e97d339aea066ef609823ec4a4d4a4d1699ec90f Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 22 Dec 2017 15:51:44 -0700 Subject: [PATCH 17/29] begin unix native finder --- plugins/inputs/procstat/nativeFinder_unix.go | 50 +++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/plugins/inputs/procstat/nativeFinder_unix.go b/plugins/inputs/procstat/nativeFinder_unix.go index 2f48d79947863..232568c11596d 100644 --- a/plugins/inputs/procstat/nativeFinder_unix.go +++ b/plugins/inputs/procstat/nativeFinder_unix.go @@ -2,30 +2,56 @@ package procstat +import ( + "regexp" + + "github.com/shirou/gopsutil/process" +) + func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { - var pids []pid - procs, err := GetWin32ProcsByName(pattern, Timeout) + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() if err != nil { return pids, err } for _, p := range procs { - pids = append(pids, PID(p.ProcessID)) + name, err := p.Exe() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(name) { + pids = append(pids, PID(p.Pid)) + } } - return pids, nil + return pids, err } func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { - var pids []pid - procs, err := GetWin32ProcsByCmdLine(pattern, Timeout) + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() if err != nil { return pids, err } for _, p := range procs { - pids = append(pids, PID(p.ProcessID)) + cmd, err := p.Cmdline() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(cmd) { + pids = append(pids, PID(p.Pid)) + } } - return pids, nil -} - -func (pg *NativeFinder) Uid(user string) ([]PID, error) { - return nil, ErrorNotImplemented + return pids, err } From ed23fe3a76586959cfc058b9c4149a53426969d2 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 22 Dec 2017 15:52:53 -0700 Subject: [PATCH 18/29] update comments --- plugins/inputs/procstat/nativeFinder_unix.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/inputs/procstat/nativeFinder_unix.go b/plugins/inputs/procstat/nativeFinder_unix.go index 232568c11596d..533b7333a9fad 100644 --- a/plugins/inputs/procstat/nativeFinder_unix.go +++ b/plugins/inputs/procstat/nativeFinder_unix.go @@ -8,6 +8,7 @@ import ( "github.com/shirou/gopsutil/process" ) +//Pattern matches on the process name func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { var pids []PID regxPattern, err := regexp.Compile(pattern) @@ -32,6 +33,7 @@ func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { return pids, err } +//FullPattern matches on the command line when the proccess was executed func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { var pids []PID regxPattern, err := regexp.Compile(pattern) From 8f008d3d46902a87d008893caf5c55d276b375b0 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Fri, 22 Dec 2017 16:58:32 -0700 Subject: [PATCH 19/29] fully working end to end --- plugins/inputs/procstat/nativeFinder.go | 1 - .../inputs/procstat/nativeFinder_windows.go | 1 - .../procstat/nativeFinder_windows_test.go | 4 +-- plugins/inputs/procstat/procstat.go | 28 +++++++++++++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/plugins/inputs/procstat/nativeFinder.go b/plugins/inputs/procstat/nativeFinder.go index f767d048e67ed..3ef286db10f61 100644 --- a/plugins/inputs/procstat/nativeFinder.go +++ b/plugins/inputs/procstat/nativeFinder.go @@ -57,7 +57,6 @@ func getPidsByUser(username string) ([]PID, error) { //skip, this can happen if we don't have permissions or //the pid no longer exists } - fmt.Println(user, ":", username) if user == username { dst = append(dst, PID(p.Pid)) } diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/nativeFinder_windows.go index 1c090a99f9d9f..ec1ff1586a31f 100644 --- a/plugins/inputs/procstat/nativeFinder_windows.go +++ b/plugins/inputs/procstat/nativeFinder_windows.go @@ -57,7 +57,6 @@ func getWin32ProcsByVariable(variable string, qType queryType, value string, tim var dst []process.Win32_Process var query string query = fmt.Sprint("WHERE ", variable, " ", qType, " \"", value, "\"") - fmt.Println("Query: ", query) q := wmi.CreateQuery(&dst, query) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() diff --git a/plugins/inputs/procstat/nativeFinder_windows_test.go b/plugins/inputs/procstat/nativeFinder_windows_test.go index 4c03cdd7de2fe..ec710dc62c96b 100644 --- a/plugins/inputs/procstat/nativeFinder_windows_test.go +++ b/plugins/inputs/procstat/nativeFinder_windows_test.go @@ -13,7 +13,7 @@ import ( func TestGather_RealPattern(t *testing.T) { pg, err := NewNativeFinder() require.NoError(t, err) - pids, err := pg.Pattern(`procstat.test.exe`) + pids, err := pg.Pattern(`%procstat%`) require.NoError(t, err) fmt.Println(pids) assert.Equal(t, len(pids) > 0, true) @@ -33,7 +33,7 @@ func TestGather_RealUser(t *testing.T) { require.NoError(t, err) pg, err := NewNativeFinder() require.NoError(t, err) - pids, err := pg.Uid(fmt.Sprint(user.Username)) + pids, err := pg.Uid(user.Username) require.NoError(t, err) fmt.Println(pids) assert.Equal(t, len(pids) > 0, true) diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index 3bd92f3b5e81e..e74c91bead966 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -22,6 +22,7 @@ var ( type PID int32 type Procstat struct { + PidFinder string `toml:"pid_finder"` PidFile string `toml:"pid_file"` Exe string Pattern string @@ -32,13 +33,19 @@ type Procstat struct { CGroup string `toml:"cgroup"` PidTag bool - pidFinder PIDFinder + finder PIDFinder + createPIDFinder func() (PIDFinder, error) procs map[PID]Process createProcess func(PID) (Process, error) } var sampleConfig = ` + ## pidFinder can be pgrep or native + ## pgrep tries to exec pgrep + ## native will work on all platforms, unix systems will use regexp. + ## Windows will use WMI calls with like queries + pid_finder = native ## Must specify one of: pid_file, exe, or pattern ## PID file to monitor process pid_file = "/var/run/nginx.pid" @@ -74,7 +81,17 @@ func (_ *Procstat) Description() string { func (p *Procstat) Gather(acc telegraf.Accumulator) error { if p.createPIDFinder == nil { - p.createPIDFinder = defaultPIDFinder + fmt.Println("PIDFINDER: ", p.PidFinder) + switch p.PidFinder { + case "native": + fmt.Println("pid finder is now native") + p.createPIDFinder = NewNativeFinder + case "pgrep": + p.createPIDFinder = NewPgrep + default: + p.createPIDFinder = defaultPIDFinder + } + } if p.createProcess == nil { p.createProcess = defaultProcess @@ -252,14 +269,15 @@ func (p *Procstat) updateProcesses(prevInfo map[PID]Process) (map[PID]Process, e // Create and return PIDGatherer lazily func (p *Procstat) getPIDFinder() (PIDFinder, error) { - if p.pidFinder == nil { + + if p.finder == nil { f, err := p.createPIDFinder() if err != nil { return nil, err } - p.pidFinder = f + p.finder = f } - return p.pidFinder, nil + return p.finder, nil } // Get matching PIDs and their initial tags From aab50e77eeff37e709a9fdab551e62e3a9d0cfaf Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 26 Dec 2017 16:48:34 -0700 Subject: [PATCH 20/29] use native Name function instead, much better performance and less resource intesive --- .../inputs/procstat/nativeFinder_windows.go | 34 ++++++++++++++++--- .../procstat/nativeFinder_windows_test.go | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/nativeFinder_windows.go index ec1ff1586a31f..554432926d670 100644 --- a/plugins/inputs/procstat/nativeFinder_windows.go +++ b/plugins/inputs/procstat/nativeFinder_windows.go @@ -5,6 +5,7 @@ package procstat import ( "context" "fmt" + "regexp" "time" "github.com/StackExchange/wmi" @@ -26,17 +27,42 @@ const ( notEqual = queryType("!=") ) -//Pattern matches the process name on windows and will find a pattern using a WMI like query +// //Pattern matches the process name on windows and will find a pattern using a WMI like query +// func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { +// var pids []PID +// procs, err := getWin32ProcsByVariable("Name", like, pattern, Timeout) +// if err != nil { +// return pids, err +// } +// for _, p := range procs { +// pids = append(pids, PID(p.ProcessID)) +// } +// return pids, nil +// } + +//Pattern matches on the process name func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { var pids []PID - procs, err := getWin32ProcsByVariable("Name", like, pattern, Timeout) + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() if err != nil { return pids, err } for _, p := range procs { - pids = append(pids, PID(p.ProcessID)) + name, err := p.Name() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(name) { + pids = append(pids, PID(p.Pid)) + } } - return pids, nil + return pids, err } //FullPattern matches the cmdLine on windows and will find a pattern using a WMI like query diff --git a/plugins/inputs/procstat/nativeFinder_windows_test.go b/plugins/inputs/procstat/nativeFinder_windows_test.go index ec710dc62c96b..2f51a3f92851a 100644 --- a/plugins/inputs/procstat/nativeFinder_windows_test.go +++ b/plugins/inputs/procstat/nativeFinder_windows_test.go @@ -13,7 +13,7 @@ import ( func TestGather_RealPattern(t *testing.T) { pg, err := NewNativeFinder() require.NoError(t, err) - pids, err := pg.Pattern(`%procstat%`) + pids, err := pg.Pattern(`procstat`) require.NoError(t, err) fmt.Println(pids) assert.Equal(t, len(pids) > 0, true) From 78d45444929887a35aac8371c5bdf6d99f173cd0 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 11 Jan 2018 20:23:37 -0700 Subject: [PATCH 21/29] address comments --- plugins/inputs/procstat/nativeFinder_unix.go | 59 ------------------- .../inputs/procstat/nativeFinder_windows.go | 22 +------ plugins/inputs/procstat/procstat.go | 4 +- plugins/inputs/procstat/procstat_test.go | 7 ++- 4 files changed, 8 insertions(+), 84 deletions(-) delete mode 100644 plugins/inputs/procstat/nativeFinder_unix.go diff --git a/plugins/inputs/procstat/nativeFinder_unix.go b/plugins/inputs/procstat/nativeFinder_unix.go deleted file mode 100644 index 533b7333a9fad..0000000000000 --- a/plugins/inputs/procstat/nativeFinder_unix.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build !windows - -package procstat - -import ( - "regexp" - - "github.com/shirou/gopsutil/process" -) - -//Pattern matches on the process name -func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { - var pids []PID - regxPattern, err := regexp.Compile(pattern) - if err != nil { - return pids, err - } - procs, err := process.Processes() - if err != nil { - return pids, err - } - for _, p := range procs { - name, err := p.Exe() - if err != nil { - //skip, this can be caused by the pid no longer existing - //or you having no permissions to access it - continue - } - if regxPattern.MatchString(name) { - pids = append(pids, PID(p.Pid)) - } - } - return pids, err -} - -//FullPattern matches on the command line when the proccess was executed -func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { - var pids []PID - regxPattern, err := regexp.Compile(pattern) - if err != nil { - return pids, err - } - procs, err := process.Processes() - if err != nil { - return pids, err - } - for _, p := range procs { - cmd, err := p.Cmdline() - if err != nil { - //skip, this can be caused by the pid no longer existing - //or you having no permissions to access it - continue - } - if regxPattern.MatchString(cmd) { - pids = append(pids, PID(p.Pid)) - } - } - return pids, err -} diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/nativeFinder_windows.go index 554432926d670..9b98829b634b1 100644 --- a/plugins/inputs/procstat/nativeFinder_windows.go +++ b/plugins/inputs/procstat/nativeFinder_windows.go @@ -1,5 +1,3 @@ -// +build windows - package procstat import ( @@ -15,10 +13,6 @@ import ( //Timeout is the timeout used when making wmi calls var Timeout = 5 * time.Second -func init() { - wmi.DefaultClient.AllowMissingFields = true -} - type queryType string const ( @@ -27,19 +21,6 @@ const ( notEqual = queryType("!=") ) -// //Pattern matches the process name on windows and will find a pattern using a WMI like query -// func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { -// var pids []PID -// procs, err := getWin32ProcsByVariable("Name", like, pattern, Timeout) -// if err != nil { -// return pids, err -// } -// for _, p := range procs { -// pids = append(pids, PID(p.ProcessID)) -// } -// return pids, nil -// } - //Pattern matches on the process name func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { var pids []PID @@ -82,7 +63,8 @@ func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { func getWin32ProcsByVariable(variable string, qType queryType, value string, timeout time.Duration) ([]process.Win32_Process, error) { var dst []process.Win32_Process var query string - query = fmt.Sprint("WHERE ", variable, " ", qType, " \"", value, "\"") + // should look like "WHERE CommandLine LIKE "procstat" + query = fmt.Sprintf("WHERE %s %s \"%s\"", variable, qType, value) q := wmi.CreateQuery(&dst, query) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() diff --git a/plugins/inputs/procstat/procstat.go b/plugins/inputs/procstat/procstat.go index e74c91bead966..6b58953f0b5b8 100644 --- a/plugins/inputs/procstat/procstat.go +++ b/plugins/inputs/procstat/procstat.go @@ -45,7 +45,7 @@ var sampleConfig = ` ## pgrep tries to exec pgrep ## native will work on all platforms, unix systems will use regexp. ## Windows will use WMI calls with like queries - pid_finder = native + pid_finder = "native" ## Must specify one of: pid_file, exe, or pattern ## PID file to monitor process pid_file = "/var/run/nginx.pid" @@ -81,10 +81,8 @@ func (_ *Procstat) Description() string { func (p *Procstat) Gather(acc telegraf.Accumulator) error { if p.createPIDFinder == nil { - fmt.Println("PIDFINDER: ", p.PidFinder) switch p.PidFinder { case "native": - fmt.Println("pid finder is now native") p.createPIDFinder = NewNativeFinder case "pgrep": p.createPIDFinder = NewPgrep diff --git a/plugins/inputs/procstat/procstat_test.go b/plugins/inputs/procstat/procstat_test.go index 4fbc769c549ee..0fb427d629092 100644 --- a/plugins/inputs/procstat/procstat_test.go +++ b/plugins/inputs/procstat/procstat_test.go @@ -1,5 +1,3 @@ -// +build !windows - package procstat import ( @@ -8,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "testing" "time" @@ -351,6 +350,10 @@ func TestGather_systemdUnitPIDs(t *testing.T) { } func TestGather_cgroupPIDs(t *testing.T) { + //no cgroups in windows + if runtime.GOOS == "windows" { + return + } td, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(td) From 50fd95afd6974aaa3ad98c13041fa29b83fe75f5 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 11 Jan 2018 20:24:51 -0700 Subject: [PATCH 22/29] add continue --- plugins/inputs/procstat/nativeFinder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/inputs/procstat/nativeFinder.go b/plugins/inputs/procstat/nativeFinder.go index 3ef286db10f61..1a90834dc2626 100644 --- a/plugins/inputs/procstat/nativeFinder.go +++ b/plugins/inputs/procstat/nativeFinder.go @@ -56,6 +56,7 @@ func getPidsByUser(username string) ([]PID, error) { if err != nil { //skip, this can happen if we don't have permissions or //the pid no longer exists + continue } if user == username { dst = append(dst, PID(p.Pid)) From 690ef25415907c11662a793568be74f18c0101e7 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 11 Jan 2018 20:27:08 -0700 Subject: [PATCH 23/29] change cgroup test to skip on windows --- plugins/inputs/procstat/procstat_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/procstat/procstat_test.go b/plugins/inputs/procstat/procstat_test.go index 0fb427d629092..dbc3f37d8d217 100644 --- a/plugins/inputs/procstat/procstat_test.go +++ b/plugins/inputs/procstat/procstat_test.go @@ -352,7 +352,7 @@ func TestGather_systemdUnitPIDs(t *testing.T) { func TestGather_cgroupPIDs(t *testing.T) { //no cgroups in windows if runtime.GOOS == "windows" { - return + t.SkipNow() } td, err := ioutil.TempDir("", "") require.NoError(t, err) From 0ecb6700218ffc33bf4d1b46f7de3f200a76bdcf Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 11 Jan 2018 20:41:19 -0700 Subject: [PATCH 24/29] move to single quotes --- plugins/inputs/procstat/nativeFinder_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/nativeFinder_windows.go index 9b98829b634b1..a9d364a2f0a07 100644 --- a/plugins/inputs/procstat/nativeFinder_windows.go +++ b/plugins/inputs/procstat/nativeFinder_windows.go @@ -64,7 +64,7 @@ func getWin32ProcsByVariable(variable string, qType queryType, value string, tim var dst []process.Win32_Process var query string // should look like "WHERE CommandLine LIKE "procstat" - query = fmt.Sprintf("WHERE %s %s \"%s\"", variable, qType, value) + query = fmt.Sprintf("WHERE %s %s '%s'", variable, qType, value) q := wmi.CreateQuery(&dst, query) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() From f115e18b8bfe2dc28cbbbae31979f87336385d23 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Thu, 11 Jan 2018 21:00:10 -0700 Subject: [PATCH 25/29] add missing file --- .../procstat/nativeFinder_notwindows.go | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 plugins/inputs/procstat/nativeFinder_notwindows.go diff --git a/plugins/inputs/procstat/nativeFinder_notwindows.go b/plugins/inputs/procstat/nativeFinder_notwindows.go new file mode 100644 index 0000000000000..533b7333a9fad --- /dev/null +++ b/plugins/inputs/procstat/nativeFinder_notwindows.go @@ -0,0 +1,59 @@ +// +build !windows + +package procstat + +import ( + "regexp" + + "github.com/shirou/gopsutil/process" +) + +//Pattern matches on the process name +func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() + if err != nil { + return pids, err + } + for _, p := range procs { + name, err := p.Exe() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(name) { + pids = append(pids, PID(p.Pid)) + } + } + return pids, err +} + +//FullPattern matches on the command line when the proccess was executed +func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() + if err != nil { + return pids, err + } + for _, p := range procs { + cmd, err := p.Cmdline() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(cmd) { + pids = append(pids, PID(p.Pid)) + } + } + return pids, err +} From 5a4c56efbc32db24a961f2349e4e4d598df15eee Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 30 Jan 2018 14:37:39 -0700 Subject: [PATCH 26/29] address comments, rename files and general cleanup --- .../{nativeFinder.go => native_finder.go} | 39 +++++++------------ ...windows.go => native_finder_notwindows.go} | 0 ...er_windows.go => native_finder_windows.go} | 2 +- ..._test.go => native_finder_windows_test.go} | 0 plugins/inputs/procstat/procstat_test.go | 2 +- 5 files changed, 17 insertions(+), 26 deletions(-) rename plugins/inputs/procstat/{nativeFinder.go => native_finder.go} (83%) rename plugins/inputs/procstat/{nativeFinder_notwindows.go => native_finder_notwindows.go} (100%) rename plugins/inputs/procstat/{nativeFinder_windows.go => native_finder_windows.go} (97%) rename plugins/inputs/procstat/{nativeFinder_windows_test.go => native_finder_windows_test.go} (100%) diff --git a/plugins/inputs/procstat/nativeFinder.go b/plugins/inputs/procstat/native_finder.go similarity index 83% rename from plugins/inputs/procstat/nativeFinder.go rename to plugins/inputs/procstat/native_finder.go index 1a90834dc2626..583e56d063ef1 100644 --- a/plugins/inputs/procstat/nativeFinder.go +++ b/plugins/inputs/procstat/native_finder.go @@ -20,11 +20,23 @@ func NewNativeFinder() (PIDFinder, error) { //Uid will return all pids for the given user func (pg *NativeFinder) Uid(user string) ([]PID, error) { - pids, err := getPidsByUser(user) + var dst []PID + procs, err := process.Processes() if err != nil { - return pids, err + return dst, err } - return pids, nil + for _, p := range procs { + username, err := p.Username() + if err != nil { + //skip, this can happen if we don't have permissions or + //the pid no longer exists + continue + } + if username == user { + dst = append(dst, PID(p.Pid)) + } + } + return dst, nil } //PidFile returns the pid from the pid file given. @@ -43,24 +55,3 @@ func (pg *NativeFinder) PidFile(path string) ([]PID, error) { return pids, nil } - -//getPidsByUser ... -func getPidsByUser(username string) ([]PID, error) { - var dst []PID - procs, err := process.Processes() - if err != nil { - return dst, err - } - for _, p := range procs { - user, err := p.Username() - if err != nil { - //skip, this can happen if we don't have permissions or - //the pid no longer exists - continue - } - if user == username { - dst = append(dst, PID(p.Pid)) - } - } - return dst, nil -} diff --git a/plugins/inputs/procstat/nativeFinder_notwindows.go b/plugins/inputs/procstat/native_finder_notwindows.go similarity index 100% rename from plugins/inputs/procstat/nativeFinder_notwindows.go rename to plugins/inputs/procstat/native_finder_notwindows.go diff --git a/plugins/inputs/procstat/nativeFinder_windows.go b/plugins/inputs/procstat/native_finder_windows.go similarity index 97% rename from plugins/inputs/procstat/nativeFinder_windows.go rename to plugins/inputs/procstat/native_finder_windows.go index a9d364a2f0a07..f9c1013ca4c64 100644 --- a/plugins/inputs/procstat/nativeFinder_windows.go +++ b/plugins/inputs/procstat/native_finder_windows.go @@ -64,7 +64,7 @@ func getWin32ProcsByVariable(variable string, qType queryType, value string, tim var dst []process.Win32_Process var query string // should look like "WHERE CommandLine LIKE "procstat" - query = fmt.Sprintf("WHERE %s %s '%s'", variable, qType, value) + query = fmt.Sprintf("WHERE %s %s %q", variable, qType, value) q := wmi.CreateQuery(&dst, query) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() diff --git a/plugins/inputs/procstat/nativeFinder_windows_test.go b/plugins/inputs/procstat/native_finder_windows_test.go similarity index 100% rename from plugins/inputs/procstat/nativeFinder_windows_test.go rename to plugins/inputs/procstat/native_finder_windows_test.go diff --git a/plugins/inputs/procstat/procstat_test.go b/plugins/inputs/procstat/procstat_test.go index dbc3f37d8d217..d77391fc2053e 100644 --- a/plugins/inputs/procstat/procstat_test.go +++ b/plugins/inputs/procstat/procstat_test.go @@ -352,7 +352,7 @@ func TestGather_systemdUnitPIDs(t *testing.T) { func TestGather_cgroupPIDs(t *testing.T) { //no cgroups in windows if runtime.GOOS == "windows" { - t.SkipNow() + t.Skip("no cgroups in windows") } td, err := ioutil.TempDir("", "") require.NoError(t, err) From 80c07ae65e022e606bc7dc5b047141e96f392928 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 30 Jan 2018 14:43:07 -0700 Subject: [PATCH 27/29] update name for not_windows --- .../procstat/native_finder_notwindows.go | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 plugins/inputs/procstat/native_finder_notwindows.go diff --git a/plugins/inputs/procstat/native_finder_notwindows.go b/plugins/inputs/procstat/native_finder_notwindows.go deleted file mode 100644 index 533b7333a9fad..0000000000000 --- a/plugins/inputs/procstat/native_finder_notwindows.go +++ /dev/null @@ -1,59 +0,0 @@ -// +build !windows - -package procstat - -import ( - "regexp" - - "github.com/shirou/gopsutil/process" -) - -//Pattern matches on the process name -func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { - var pids []PID - regxPattern, err := regexp.Compile(pattern) - if err != nil { - return pids, err - } - procs, err := process.Processes() - if err != nil { - return pids, err - } - for _, p := range procs { - name, err := p.Exe() - if err != nil { - //skip, this can be caused by the pid no longer existing - //or you having no permissions to access it - continue - } - if regxPattern.MatchString(name) { - pids = append(pids, PID(p.Pid)) - } - } - return pids, err -} - -//FullPattern matches on the command line when the proccess was executed -func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { - var pids []PID - regxPattern, err := regexp.Compile(pattern) - if err != nil { - return pids, err - } - procs, err := process.Processes() - if err != nil { - return pids, err - } - for _, p := range procs { - cmd, err := p.Cmdline() - if err != nil { - //skip, this can be caused by the pid no longer existing - //or you having no permissions to access it - continue - } - if regxPattern.MatchString(cmd) { - pids = append(pids, PID(p.Pid)) - } - } - return pids, err -} From 20470f81ae898eee8d9b7582af71fcbf4ebe72cf Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 30 Jan 2018 14:46:07 -0700 Subject: [PATCH 28/29] add missing file --- .../procstat/native_finder_not_windows.go | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 plugins/inputs/procstat/native_finder_not_windows.go diff --git a/plugins/inputs/procstat/native_finder_not_windows.go b/plugins/inputs/procstat/native_finder_not_windows.go new file mode 100644 index 0000000000000..533b7333a9fad --- /dev/null +++ b/plugins/inputs/procstat/native_finder_not_windows.go @@ -0,0 +1,59 @@ +// +build !windows + +package procstat + +import ( + "regexp" + + "github.com/shirou/gopsutil/process" +) + +//Pattern matches on the process name +func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) { + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() + if err != nil { + return pids, err + } + for _, p := range procs { + name, err := p.Exe() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(name) { + pids = append(pids, PID(p.Pid)) + } + } + return pids, err +} + +//FullPattern matches on the command line when the proccess was executed +func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) { + var pids []PID + regxPattern, err := regexp.Compile(pattern) + if err != nil { + return pids, err + } + procs, err := process.Processes() + if err != nil { + return pids, err + } + for _, p := range procs { + cmd, err := p.Cmdline() + if err != nil { + //skip, this can be caused by the pid no longer existing + //or you having no permissions to access it + continue + } + if regxPattern.MatchString(cmd) { + pids = append(pids, PID(p.Pid)) + } + } + return pids, err +} From d75e3db29e733b76525b42bb09fdedb8b698c1a6 Mon Sep 17 00:00:00 2001 From: Ben Aldrich Date: Tue, 30 Jan 2018 15:11:02 -0700 Subject: [PATCH 29/29] rename again to see if that fixes the test --- .../{native_finder_not_windows.go => native_finder_notwindows.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/inputs/procstat/{native_finder_not_windows.go => native_finder_notwindows.go} (100%) diff --git a/plugins/inputs/procstat/native_finder_not_windows.go b/plugins/inputs/procstat/native_finder_notwindows.go similarity index 100% rename from plugins/inputs/procstat/native_finder_not_windows.go rename to plugins/inputs/procstat/native_finder_notwindows.go