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

Commit

Permalink
Add main PID to print
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Pichard <valentin.pichard@dimelo.com>
  • Loading branch information
Valentin Pichard committed Feb 8, 2019
1 parent bc18eaf commit ed25734
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions helper/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type pumaStatus struct {
BootedWorkers int `json:"booted_workers"`
OldWorkers int `json:"old_workers"`
Phase int `json:"phase"`
MainPid int `json:"main_pid"`
WorkerStatus []struct {
Booted bool `json:"booted"`
Index int `json:"index"`
Expand Down Expand Up @@ -36,6 +37,7 @@ type pumaStatusApplication struct {
Worker []pumaStatusWorker `json:"worker"`
TotalMaxThreads int `json:"total_max_threads"`
TotalCurrentThreads int `json:"total_current_threads"`
MainPid int `json:"main_pid"`
}

type pumaStatusWorker struct {
Expand Down
6 changes: 3 additions & 3 deletions helper/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func (ps pumaStatusFinalOutput) printStatusApps() error {
fmt.Printf(" About: %s\n", key.Description)
}
fmt.Printf(" App root: %s\n", key.RootPath)
fmt.Printf(" Booted workers: %d\n", key.BootedWorkers)
fmt.Printf(" Booted workers: %d | PID: %d\n", key.BootedWorkers, key.MainPid)
fmt.Printf(" Current phase: %d | Old workers: %d | Active threads: %s\n\n", key.AppCurrentPhase, key.OldWorkers, asciiThreadLoad(key.TotalCurrentThreads, key.TotalMaxThreads))
} else {
if key.OldWorkers > 0 {
fmt.Printf("-> %s (%s) Phase: %d | Workers: %d (Old: %d) | Active threads: %s\n\n", key.Name, key.RootPath, key.AppCurrentPhase, key.BootedWorkers, key.OldWorkers, asciiThreadLoad(key.TotalCurrentThreads, key.TotalMaxThreads))
fmt.Printf("-> %s %d (%s) Phase: %d | Workers: %d (Old: %d) | Active threads: %s\n\n", key.Name, key.MainPid, key.RootPath, key.AppCurrentPhase, key.BootedWorkers, key.OldWorkers, asciiThreadLoad(key.TotalCurrentThreads, key.TotalMaxThreads))
} else {
fmt.Printf("-> %s (%s) Phase: %d | Workers: %d | Active threads: %s\n\n", key.Name, key.RootPath, key.AppCurrentPhase, key.BootedWorkers, asciiThreadLoad(key.TotalCurrentThreads, key.TotalMaxThreads))
fmt.Printf("-> %s %d (%s) Phase: %d | Workers: %d | Active threads: %s\n\n", key.Name, key.MainPid, key.RootPath, key.AppCurrentPhase, key.BootedWorkers, asciiThreadLoad(key.TotalCurrentThreads, key.TotalMaxThreads))
}
}

Expand Down
1 change: 1 addition & 0 deletions helper/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func retrieveStatusData() (*pumaStatusFinalOutput, error) {
AppCurrentPhase: ps.Phase,
TotalCurrentThreads: tcthreads,
TotalMaxThreads: tmthreads,
MainPid: ps.MainPid,
}

apps = append(apps, app)
Expand Down
9 changes: 6 additions & 3 deletions helper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ type pumaStateFile struct {

// readPumaStats get and unmarshal JSON using puma unix socket
func readPumaStats(pspath string) (*pumaStatus, error) {
var ps pumaStatus
var psf pumaStateFile

data, err := ioutil.ReadFile(pspath)
if err != nil {
return nil, err
}

var psf pumaStateFile

if err := yaml.Unmarshal(data, &psf); err != nil {
return nil, err
}
Expand All @@ -60,6 +59,10 @@ func readPumaStats(pspath string) (*pumaStatus, error) {
//fmt.Println(pcpath, pspath)
//output, err := exec.Command("cat", "/go/src/github.com/dimelo/puma-helper/output.txt").Output()

ps := pumaStatus{
MainPid: psf.Pid,
}

if err := json.Unmarshal(body, &ps); err != nil {
return nil, err
}
Expand Down

0 comments on commit ed25734

Please sign in to comment.