Skip to content
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

Add NSpid to proc status #557

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions proc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type ProcStatus struct {

// Thread group ID.
TGID int
// List of Pid namespace.
NSpids []uint64

// Peak virtual memory size.
VmPeak uint64 // nolint:revive
Expand Down Expand Up @@ -127,6 +129,8 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
copy(s.UIDs[:], strings.Split(vString, "\t"))
case "Gid":
copy(s.GIDs[:], strings.Split(vString, "\t"))
case "NSpid":
s.NSpids = calcNSPidsList(vString)
case "VmPeak":
s.VmPeak = vUintBytes
case "VmSize":
Expand Down Expand Up @@ -200,3 +204,18 @@ func calcCpusAllowedList(cpuString string) []uint64 {
sort.Slice(g, func(i, j int) bool { return g[i] < g[j] })
return g
}

func calcNSPidsList(nspidsString string) []uint64 {
s := strings.Split(nspidsString, " ")
var nspids []uint64

for _, nspid := range s {
nspid, _ := strconv.ParseUint(nspid, 10, 64)
if nspid == 0 {
continue
}
nspids = append(nspids, nspid)
}

return nspids
}
1 change: 1 addition & 0 deletions proc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestProcStatus(t *testing.T) {
}{
{name: "Pid", want: 26231, have: s.PID},
{name: "Tgid", want: 26231, have: s.TGID},
{name: "NSpid", want: 1, have: int(s.NSpids[0])},
{name: "VmPeak", want: 58472 * 1024, have: int(s.VmPeak)},
{name: "VmSize", want: 58440 * 1024, have: int(s.VmSize)},
{name: "VmLck", want: 0 * 1024, have: int(s.VmLck)},
Expand Down