forked from dean2021/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goss.go
49 lines (42 loc) · 1.28 KB
/
goss.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2020 Dean.
// Authors: Dean <[email protected]>
// Date: 2020/9/25 10:25 上午
package goss
import (
"syscall"
)
var netConnectionKindMap = map[string][]uint8{
"all": {syscall.IPPROTO_TCP, syscall.IPPROTO_UDP},
"tcp": {syscall.IPPROTO_TCP},
"udp": {syscall.IPPROTO_UDP},
}
var netProtocolKindMap = map[uint8]string{
syscall.IPPROTO_TCP: "tcp",
syscall.IPPROTO_UDP: "udp",
}
// AddrPort are <addr>:<port>
type AddrPort struct {
Addr string `json:"addr"`
Port string `json:"port"`
}
// Stat represents a socket statistics.
type Stat struct {
Proto string `json:"proto"`
RecvQ uint32 `json:"recvq"`
SendQ uint32 `json:"sendq"`
Local *AddrPort `json:"local"`
Foreign *AddrPort `json:"foreign"`
State string `json:"state"`
Inode uint32 `json:"inode"`
Process *UserEnt `json:"process"`
}
// UserEnt represents a detail of network socket.
// see https://github.com/shemminger/iproute2/blob/afa588490b7e87c5adfb05d5163074e20b6ff14a/misc/ss.c#L509.
type UserEnt struct {
Inode uint32 `json:"inode"` // inode number
FD int `json:"fd"` // file discryptor
Pid int `json:"pid"` // process id
PName string `json:"p_name"` // process name
PPid int `json:"p_pid"` // parent process id
PGid int `json:"p_gid"` // process group id
}