2024-05-13 12:41:33 +00:00
|
|
|
package oneuptime_infrastructure_agent
|
2024-05-11 00:37:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/shirou/gopsutil/v3/process"
|
2024-05-13 12:41:33 +00:00
|
|
|
"log/slog"
|
2024-05-11 00:37:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// getServerProcesses retrieves the list of server processes
|
|
|
|
func getServerProcesses() []*ServerProcess {
|
|
|
|
var serverProcesses []*ServerProcess
|
|
|
|
|
|
|
|
// Fetch all processes
|
|
|
|
processList, err := process.Processes()
|
|
|
|
if err != nil {
|
|
|
|
slog.Error("Failed to fetch process list", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over all processes and collect details
|
|
|
|
for _, p := range processList {
|
|
|
|
name, err := p.Name()
|
|
|
|
if err != nil {
|
|
|
|
continue // skip processes where details cannot be retrieved
|
|
|
|
}
|
|
|
|
cmdline, err := p.Cmdline()
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
serverProcesses = append(serverProcesses, &ServerProcess{
|
|
|
|
Pid: p.Pid,
|
|
|
|
Name: name,
|
|
|
|
Command: cmdline,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return serverProcesses
|
|
|
|
}
|