more abstraction and simple dashboard for processes
All checks were successful
Build Process Supervisor / build (amd64, .exe, windows) (push) Successful in 2m24s
Build Process Supervisor / build (amd64, , linux) (push) Successful in 2m36s
Build Process Supervisor / build (arm, 6, , linux) (push) Successful in 2m19s
Build Process Supervisor / build (arm64, , linux) (push) Successful in 2m14s
All checks were successful
Build Process Supervisor / build (amd64, .exe, windows) (push) Successful in 2m24s
Build Process Supervisor / build (amd64, , linux) (push) Successful in 2m36s
Build Process Supervisor / build (arm, 6, , linux) (push) Successful in 2m19s
Build Process Supervisor / build (arm64, , linux) (push) Successful in 2m14s
This commit is contained in:
58
htop/models/process.go
Normal file
58
htop/models/process.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ps "github.com/shirou/gopsutil/v3/process"
|
||||
)
|
||||
|
||||
type Process struct {
|
||||
PID string
|
||||
User string
|
||||
Cmd string
|
||||
CPU float64
|
||||
Memory uint64
|
||||
}
|
||||
|
||||
func GetProcesses() ([]Process, error) {
|
||||
processes, err := ps.Processes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []Process
|
||||
for _, p := range processes {
|
||||
pid := p.Pid
|
||||
|
||||
name, err := p.Name()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
user, err := p.Username()
|
||||
if err != nil {
|
||||
user = "unknown"
|
||||
}
|
||||
|
||||
cpu, err := p.CPUPercent()
|
||||
if err != nil {
|
||||
cpu = 0
|
||||
}
|
||||
|
||||
memInfo, err := p.MemoryInfo()
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, Process{
|
||||
PID: fmt.Sprintf("%d", pid),
|
||||
User: user,
|
||||
Cmd: name,
|
||||
CPU: cpu,
|
||||
Memory: memInfo.RSS,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
Reference in New Issue
Block a user