Skip to content

Merge pull request 773 (adding username to topbeat) #845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 26, 2016
32 changes: 17 additions & 15 deletions topbeat/beat/sigar.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ type SwapStat struct {
}

type Process struct {
Pid int `json:"pid"`
Ppid int `json:"ppid"`
Name string `json:"name"`
State string `json:"state"`
CmdLine string `json:"cmdline"`
Mem sigar.ProcMem
Cpu sigar.ProcTime
ctime time.Time
Pid int `json:"pid"`
Ppid int `json:"ppid"`
Name string `json:"name"`
Username string `json:"username"`
State string `json:"state"`
CmdLine string `json:"cmdline"`
Mem sigar.ProcMem
Cpu sigar.ProcTime
ctime time.Time
}

type FileSystemStat struct {
Expand Down Expand Up @@ -174,13 +175,14 @@ func GetProcess(pid int) (*Process, error) {
cmdLine := strings.Join(args.List, " ")

proc := Process{
Pid: pid,
Ppid: state.Ppid,
Name: state.Name,
State: getProcState(byte(state.State)),
CmdLine: cmdLine,
Mem: mem,
Cpu: cpu,
Pid: pid,
Ppid: state.Ppid,
Name: state.Name,
State: getProcState(byte(state.State)),
Username: state.Username,
CmdLine: cmdLine,
Mem: mem,
Cpu: cpu,
}
proc.ctime = time.Now()

Expand Down
1 change: 1 addition & 0 deletions topbeat/beat/sigar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions topbeat/beat/topbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ func (t *Topbeat) exportProcStats() error {
newProcs[process.Pid] = process

proc := common.MapStr{
"pid": process.Pid,
"ppid": process.Ppid,
"name": process.Name,
"state": process.State,
"pid": process.Pid,
"ppid": process.Ppid,
"name": process.Name,
"state": process.State,
"username": process.Username,
"mem": common.MapStr{
"size": process.Mem.Size,
"rss": process.Mem.Resident,
Expand Down
15 changes: 14 additions & 1 deletion topbeat/tests/system/test_procs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from topbeat import BaseTest

import getpass
import re

import os

"""
Contains tests for per process statistics.
Expand Down Expand Up @@ -31,6 +32,7 @@ def test_procs(self):
assert re.match("(?i).*topbeat.test(.exe)? -e -c", output["proc.cmdline"])
assert isinstance(output["proc.state"], basestring)
assert isinstance(output["proc.cpu.start_time"], basestring)
self.check_username(output["proc.username"])

for key in [
"proc.pid",
Expand All @@ -49,3 +51,14 @@ def test_procs(self):
"proc.mem.rss_p",
]:
assert type(output[key]) in [int, float]

def check_username(self, observed, expected = None):
if expected == None:
expected = getpass.getuser()

if os.name == 'nt':
parts = observed.split("\\", 2)
assert len(parts) == 2, "Expected proc.username to be of form DOMAIN\username, but was %s" % observed
observed = parts[1]

assert expected == observed, "proc.username = %s, but expected %s" % (observed, expected)
68 changes: 68 additions & 0 deletions vendor/github.com/elastic/gosigar/.appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion vendor/github.com/elastic/gosigar/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/elastic/gosigar/sigar_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading