diff options
author | Valery Piashchynski <[email protected]> | 2020-12-22 23:02:25 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-22 23:02:25 +0300 |
commit | fd1e98bc6339abfa66523bf9d2208d00df8ee4bc (patch) | |
tree | b679441276717e687a5b460ebeba7ad0eee69be9 /tools/process.go | |
parent | 40b6c3169931a3fef62b649db19ff01dc685b7d4 (diff) |
events listeners refactor, CLI initial commit
Diffstat (limited to 'tools/process.go')
-rw-r--r-- | tools/process.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/process.go b/tools/process.go new file mode 100644 index 00000000..d92755d1 --- /dev/null +++ b/tools/process.go @@ -0,0 +1,44 @@ +package tools + +import ( + "github.com/shirou/gopsutil/process" + "github.com/spiral/errors" + "github.com/spiral/roadrunner/v2/interfaces/worker" +) + +// ProcessState provides information about specific worker. +type ProcessState struct { + // Pid contains process id. + Pid int `json:"pid"` + + // Status of the worker. + Status string `json:"status"` + + // Number of worker executions. + NumJobs int64 `json:"numExecs"` + + // Created is unix nano timestamp of worker creation time. + Created int64 `json:"created"` + + // MemoryUsage holds the information about worker memory usage in bytes. + // Values might vary for different operating systems and based on RSS. + MemoryUsage uint64 `json:"memoryUsage"` +} + +// WorkerProcessState creates new worker state definition. +func WorkerProcessState(w worker.BaseProcess) (ProcessState, error) { + const op = errors.Op("worker_process state") + p, _ := process.NewProcess(int32(w.Pid())) + i, err := p.MemoryInfo() + if err != nil { + return ProcessState{}, errors.E(op, err) + } + + return ProcessState{ + Pid: int(w.Pid()), + Status: w.State().String(), + NumJobs: w.State().NumExecs(), + Created: w.Created().UnixNano(), + MemoryUsage: i.RSS, + }, nil +} |