add Uids field to net_linux

pull/265/head
Jean Kahrs 9 years ago
parent 14eb7acb23
commit cba0992ab3

@ -39,13 +39,14 @@ type Addr struct {
} }
type ConnectionStat struct { type ConnectionStat struct {
Fd uint32 `json:"fd"` Fd uint32 `json:"fd"`
Family uint32 `json:"family"` Family uint32 `json:"family"`
Type uint32 `json:"type"` Type uint32 `json:"type"`
Laddr Addr `json:"localaddr"` Laddr Addr `json:"localaddr"`
Raddr Addr `json:"remoteaddr"` Raddr Addr `json:"remoteaddr"`
Status string `json:"status"` Status string `json:"status"`
Pid int32 `json:"pid"` Uids []int32 `json:"uids"`
Pid int32 `json:"pid"`
} }
// System wide stats about different network protocols // System wide stats about different network protocols

@ -14,6 +14,7 @@ import (
"syscall" "syscall"
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/process"
) )
// NetIOCounters returnes network I/O statistics for every network // NetIOCounters returnes network I/O statistics for every network
@ -281,6 +282,7 @@ type connTmp struct {
laddr Addr laddr Addr
raddr Addr raddr Addr
status string status string
uids []int32
pid int32 pid int32
boundPid int32 boundPid int32
path string path string
@ -338,6 +340,7 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
Type: c.sockType, Type: c.sockType,
Laddr: c.laddr, Laddr: c.laddr,
Raddr: c.raddr, Raddr: c.raddr,
Uids: c.uids,
Status: c.status, Status: c.status,
Pid: c.pid, Pid: c.pid,
} }
@ -346,6 +349,11 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
} else { } else {
conn.Pid = c.pid conn.Pid = c.pid
} }
// fetch process owner Real, effective, saved set, and filesystem UIDs
proc := process.Process{Pid: conn.Pid}
conn.Uids, _ = proc.Uids()
// check duplicate using JSON format // check duplicate using JSON format
json := conn.String() json := conn.String()
_, exists := dupCheckMap[json] _, exists := dupCheckMap[json]

Loading…
Cancel
Save