From a645ca57a9d83844ae7f3702f96f58671608d8cc Mon Sep 17 00:00:00 2001 From: Mike Roberts Date: Tue, 19 Jan 2016 15:52:45 -0600 Subject: [PATCH 1/2] using PR elastic/gosigar#13 to add process user_id to topbeat --- topbeat/beat/sigar.go | 4 +++- topbeat/beat/topbeat.go | 15 ++++++++------- topbeat/main.go | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/topbeat/beat/sigar.go b/topbeat/beat/sigar.go index eedc4f71b628..6b23abf3460c 100644 --- a/topbeat/beat/sigar.go +++ b/topbeat/beat/sigar.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/elastic/gosigar" + "github.com/eonarheim/gosigar" ) type SystemLoad struct { @@ -64,6 +64,7 @@ type Process struct { Ppid int `json:"ppid"` Name string `json:"name"` State string `json:"state"` + UserId string `json:"user_id"` CmdLine string `json:"cmdline"` Mem *ProcMemStat `json:"mem"` Cpu *ProcCpuTime `json:"cpu"` @@ -276,6 +277,7 @@ func GetProcess(pid int) (*Process, error) { Pid: pid, Ppid: state.Ppid, Name: state.Name, + UserId: state.UserId, State: getProcState(byte(state.State)), CmdLine: cmdLine, Mem: &ProcMemStat{ diff --git a/topbeat/beat/topbeat.go b/topbeat/beat/topbeat.go index e61e927c07db..803932a5bc1c 100644 --- a/topbeat/beat/topbeat.go +++ b/topbeat/beat/topbeat.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "github.com/elastic/gosigar" + "github.com/eonarheim/gosigar" "github.com/elastic/beats/libbeat/beat" "github.com/elastic/beats/libbeat/cfgfile" @@ -208,12 +208,13 @@ func (t *Topbeat) exportProcStats() error { newProcs[process.Pid] = process proc := common.MapStr{ - "pid": process.Pid, - "ppid": process.Ppid, - "name": process.Name, - "state": process.State, - "mem": process.Mem, - "cpu": process.Cpu, + "pid": process.Pid, + "ppid": process.Ppid, + "name": process.Name, + "state": process.State, + "user_id": process.UserId, + "mem": process.Mem, + "cpu": process.Cpu, } if process.CmdLine != "" { diff --git a/topbeat/main.go b/topbeat/main.go index 7c6555e71f65..5377ce1b871e 100644 --- a/topbeat/main.go +++ b/topbeat/main.go @@ -1,7 +1,7 @@ package main import ( - topbeat "github.com/elastic/beats/topbeat/beat" + topbeat "github.com/dr-toboggan/beats/topbeat/beat" "github.com/elastic/beats/libbeat/beat" ) From ce706edd4ab0bfd12fb22295af0b3384317e4f96 Mon Sep 17 00:00:00 2001 From: dr-toboggan Date: Thu, 21 Jan 2016 15:10:47 -0600 Subject: [PATCH 2/2] Adding username to process fields recorded by topbeats. --- topbeat/beat/sigar.go | 2 ++ topbeat/beat/sigar_test.go | 1 + topbeat/beat/topbeat.go | 1 + 3 files changed, 4 insertions(+) diff --git a/topbeat/beat/sigar.go b/topbeat/beat/sigar.go index eedc4f71b628..9c1762bf18e4 100644 --- a/topbeat/beat/sigar.go +++ b/topbeat/beat/sigar.go @@ -64,6 +64,7 @@ type Process struct { Ppid int `json:"ppid"` Name string `json:"name"` State string `json:"state"` + Username string `json:"username"` CmdLine string `json:"cmdline"` Mem *ProcMemStat `json:"mem"` Cpu *ProcCpuTime `json:"cpu"` @@ -277,6 +278,7 @@ func GetProcess(pid int) (*Process, error) { Ppid: state.Ppid, Name: state.Name, State: getProcState(byte(state.State)), + Username: state.Username, CmdLine: cmdLine, Mem: &ProcMemStat{ Size: mem.Size, diff --git a/topbeat/beat/sigar_test.go b/topbeat/beat/sigar_test.go index 0f51e8c8ca51..348b50df58e3 100644 --- a/topbeat/beat/sigar_test.go +++ b/topbeat/beat/sigar_test.go @@ -93,6 +93,7 @@ func TestGetProcess(t *testing.T) { assert.True(t, (process.Pid > 0)) assert.True(t, (process.Ppid >= 0)) assert.True(t, (len(process.Name) > 0)) + assert.True(t, (len(process.Username) > 0)) assert.NotEqual(t, "unknown", process.State) // Memory Checks diff --git a/topbeat/beat/topbeat.go b/topbeat/beat/topbeat.go index e61e927c07db..b08b25f6d39a 100644 --- a/topbeat/beat/topbeat.go +++ b/topbeat/beat/topbeat.go @@ -212,6 +212,7 @@ func (t *Topbeat) exportProcStats() error { "ppid": process.Ppid, "name": process.Name, "state": process.State, + "username": process.Username, "mem": process.Mem, "cpu": process.Cpu, }