Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Add global uptime process
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Pichard <[email protected]>
  • Loading branch information
Valentin Pichard committed Feb 8, 2019
1 parent fe6b0de commit cd9977b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions helper/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ type pumaStatusWorker struct {
Memory float64 `json:"memory"`
TotalTimeExec int `json:"total_time_exec"`
CurrentPhase int `json:"current_phase"`
Uptime int64 `json:"uptime"`
}
4 changes: 2 additions & 2 deletions helper/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func printStatusWorkers(ps []pumaStatusWorker, currentPhase int) error {
lcheckin = Brown(timeElapsed(key.LastCheckin))
}

fmt.Printf("* %d [%d] CPU: %s Mem: %s Phase: %s Runtime: %s Threads: %s (Last checkin: %s)\n", key.ID, key.Pid, colorCPU(key.CPUPercent), colorMemory(key.Memory), phase, timeElapsed(time.Now().Add(time.Duration(-int64(key.TotalTimeExec))*time.Second).Format(time.RFC3339)), asciiThreadLoad(key.CurrentThreads, key.MaxThreads), lcheckin)
fmt.Printf("* %d [%d] CPU: %s Mem: %s Phase: %s Uptime: %s Threads: %s (Last checkin: %s)\n", key.ID, key.Pid, colorCPU(key.CPUPercent), colorMemory(key.Memory), phase, timeElapsed(timeElapsed(time.Unix(key.Uptime, 0).Format(time.RFC3339))), asciiThreadLoad(key.CurrentThreads, key.MaxThreads), lcheckin)
continue
}

Expand All @@ -77,7 +77,7 @@ func printStatusWorkers(ps []pumaStatusWorker, currentPhase int) error {
}

fmt.Printf("* %s ~ PID %d\t\tWorker ID %d\tCPU: %s%%\tMem: %s MiB\tPhase: %s\n", bootbtn, key.Pid, key.ID, colorCPU(key.CPUPercent), colorMemory(key.Memory), phase)
fmt.Printf(" Active threads: %s\tLast checkin: %s\tTotal exec time: %s\n", asciiThreadLoad(key.CurrentThreads, key.MaxThreads), timeElapsed(key.LastCheckin), timeElapsed(time.Now().Add(time.Duration(-int64(key.TotalTimeExec))*time.Second).Format(time.RFC3339)))
fmt.Printf(" Active threads: %s\tLast checkin: %s\tTotal CPU time: %s\tUptime: %s\n", asciiThreadLoad(key.CurrentThreads, key.MaxThreads), timeElapsed(key.LastCheckin), timeElapsed(time.Now().Add(time.Duration(-int64(key.TotalTimeExec))*time.Second).Format(time.RFC3339)), timeElapsed(time.Unix(key.Uptime, 0).Format(time.RFC3339)))
}
return nil
}
Expand Down
9 changes: 8 additions & 1 deletion helper/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ func retrieveStatusData() (*pumaStatusFinalOutput, error) {
return nil, err
}

ttime, err := getTotalTimeFromPID(pid)
ttime, err := getTotalExecTimeFromPID(pid)
if err != nil {
return nil, err
}

// Assuming this timestamp is in milliseconds
utime, err := getTotalUptimeFromPID(pid)
if err != nil {
return nil, err
}
Expand All @@ -86,6 +92,7 @@ func retrieveStatusData() (*pumaStatusFinalOutput, error) {
Memory: mem,
TotalTimeExec: int(ttime),
CurrentPhase: v.Phase,
Uptime: utime / 1000,
}

workers = append(workers, worker)
Expand Down
14 changes: 13 additions & 1 deletion helper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func readPumaStats(pcpath, pspath string) (pumaStatus, error) {
return ps, nil
}

func getTotalTimeFromPID(pid int32) (float64, error) {
func getTotalExecTimeFromPID(pid int32) (float64, error) {
p, err := proc.NewProcess(pid)
if err != nil {
return 0.0, err
Expand All @@ -46,6 +46,18 @@ func getTotalTimeFromPID(pid int32) (float64, error) {
return t.Total(), nil
}

func getTotalUptimeFromPID(pid int32) (int64, error) {
p, err := proc.NewProcess(pid)
if err != nil {
return 0, err
}
t, err := p.CreateTime()
if err != nil {
return 0, err
}
return t, nil
}

func getCPUFromPID(pid int32) (float64, error) {
p, err := proc.NewProcess(pid)
if err != nil {
Expand Down

0 comments on commit cd9977b

Please sign in to comment.