2020-02-11 10:53:25 +08:00
|
|
|
package staros
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-17 09:56:23 +08:00
|
|
|
const (
|
|
|
|
|
KB = 1024
|
|
|
|
|
MB = KB << 10
|
|
|
|
|
GB = MB << 10
|
|
|
|
|
TB = GB << 10
|
|
|
|
|
PB = TB << 10
|
|
|
|
|
)
|
2021-09-01 11:01:51 +08:00
|
|
|
const (
|
|
|
|
|
TCP_UNKNOWN = iota
|
|
|
|
|
TCP_ESTABLISHED
|
|
|
|
|
TCP_SYN_SENT
|
|
|
|
|
TCP_SYN_RECV
|
|
|
|
|
TCP_FIN_WAIT1
|
|
|
|
|
TCP_FIN_WAIT2
|
|
|
|
|
TCP_TIME_WAIT
|
|
|
|
|
TCP_CLOSE
|
|
|
|
|
TCP_CLOSE_WAIT
|
2026-06-09 18:10:19 +08:00
|
|
|
TCP_LAST_ACK
|
2021-09-01 11:01:51 +08:00
|
|
|
TCP_LISTEN
|
|
|
|
|
TCP_CLOSING
|
|
|
|
|
)
|
|
|
|
|
|
2026-06-09 18:10:19 +08:00
|
|
|
const TCP_LAST_ACL = TCP_LAST_ACK
|
|
|
|
|
|
|
|
|
|
var TCP_STATE = []string{"TCP_UNKNOWN", "TCP_ESTABLISHED", "TCP_SYN_SENT", "TCP_SYN_RECV", "TCP_FIN_WAIT1", "TCP_FIN_WAIT2", "TCP_TIME_WAIT", "TCP_CLOSE", "TCP_CLOSE_WAIT", "TCP_LAST_ACK", "TCP_LISTEN", "TCP_CLOSING"}
|
2020-07-17 09:56:23 +08:00
|
|
|
|
|
|
|
|
type NetAdapter struct {
|
|
|
|
|
Name string
|
|
|
|
|
RecvBytes uint64
|
|
|
|
|
SendBytes uint64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type NetSpeed struct {
|
2023-02-03 13:53:42 +08:00
|
|
|
Name string
|
|
|
|
|
RecvSpeeds float64
|
|
|
|
|
SendSpeeds float64
|
|
|
|
|
RecvBytes uint64
|
|
|
|
|
SendBytes uint64
|
2020-07-17 09:56:23 +08:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 10:53:25 +08:00
|
|
|
// Process 定义一个进程的信息
|
|
|
|
|
type Process struct {
|
|
|
|
|
PPid int64
|
|
|
|
|
Pid int64
|
|
|
|
|
Name string
|
|
|
|
|
ExecPath string
|
|
|
|
|
LocalPath string
|
2020-07-17 09:56:23 +08:00
|
|
|
Path string
|
2020-02-11 10:53:25 +08:00
|
|
|
Args []string
|
2020-08-21 11:17:48 +08:00
|
|
|
Env []string
|
2020-02-11 10:53:25 +08:00
|
|
|
RUID int
|
|
|
|
|
EUID int
|
|
|
|
|
RGID int
|
|
|
|
|
EGID int
|
|
|
|
|
TPid int64
|
|
|
|
|
Uptime time.Time
|
2020-08-21 11:17:48 +08:00
|
|
|
VmPeak int64
|
|
|
|
|
VmSize int64
|
|
|
|
|
VmLck int64
|
|
|
|
|
VmHWM int64
|
|
|
|
|
VmRSS int64
|
|
|
|
|
VmData int64
|
2021-06-04 10:44:53 +08:00
|
|
|
netConn []NetConn
|
|
|
|
|
netErr error
|
|
|
|
|
Err error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p Process) GetNetConns() ([]NetConn, error) {
|
|
|
|
|
return p.netConn, p.netErr
|
2020-02-11 10:53:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MemStatus struct {
|
|
|
|
|
All uint64
|
|
|
|
|
Used uint64
|
|
|
|
|
Free uint64
|
|
|
|
|
Shared uint64
|
|
|
|
|
BuffCache uint64
|
|
|
|
|
Available uint64
|
|
|
|
|
SwapAll uint64
|
|
|
|
|
SwapUsed uint64
|
|
|
|
|
SwapFree uint64
|
|
|
|
|
VirtualAll uint64
|
|
|
|
|
VirtualUsed uint64
|
|
|
|
|
VirtualAvail uint64
|
|
|
|
|
AvailExtended uint64
|
|
|
|
|
}
|
2020-06-08 14:52:16 +08:00
|
|
|
|
|
|
|
|
type DiskStatus struct {
|
|
|
|
|
All uint64
|
|
|
|
|
Used uint64
|
|
|
|
|
Free uint64
|
|
|
|
|
Available uint64
|
|
|
|
|
}
|
2021-06-04 10:44:53 +08:00
|
|
|
|
|
|
|
|
type NetConn struct {
|
2021-09-01 11:01:51 +08:00
|
|
|
LocalAddr string
|
|
|
|
|
LocalPort int
|
|
|
|
|
Typed string
|
|
|
|
|
RemoteAddr string
|
|
|
|
|
RemotePort int
|
|
|
|
|
Socket string
|
|
|
|
|
Inode string
|
|
|
|
|
Status string
|
|
|
|
|
TX_Queue int64
|
|
|
|
|
RX_Queue int64
|
|
|
|
|
TimerActive string
|
|
|
|
|
TimerJiffies int64
|
|
|
|
|
RtoTimer int64
|
|
|
|
|
Pid int64
|
|
|
|
|
Uid int64
|
|
|
|
|
Process *Process
|
2021-06-04 10:44:53 +08:00
|
|
|
}
|