Skip to content

Commit

Permalink
Cleaning up before statsD client add
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevenson Jean-Pierre committed May 24, 2015
1 parent c0199f2 commit 2f30a24
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"sort"
"time"
"log"
)

type passengerStatus struct {
Expand Down Expand Up @@ -65,6 +66,17 @@ func retrievePassengerStats() (io.Reader, error) {
return bytes.NewReader(out), nil
}

func parsePassengerXML(xmlData *io.Reader) (passengerStatus, error){
var ParsedPassengerXML passengerStatus
dec := xml.NewDecoder(*xmlData)
dec.CharsetReader = charset.NewReader
err := dec.Decode(&ParsedPassengerXML)
if err != nil {
return passengerStatus{}, err
}
return ParsedPassengerXML, nil
}

func chartProcessed(passengerDetails *passengerStatus) {
fmt.Println("|=====Processed====|")
var processed []int
Expand Down Expand Up @@ -94,10 +106,12 @@ func chartMemory(passengerDetails *passengerStatus) {
}

func chartPendingRequest(passengerDetails *passengerStatus) {
fmt.Println("|=====Queue Depth====|")
fmt.Println("Queue Depth", passengerDetails.QueuedCount)
}

func chartPoolUse(passengerDetails *passengerStatus) {
fmt.Println("|=====Pool Usage====|")
fmt.Println("Used Pool", passengerDetails.ProcessCount)
fmt.Println("Max Pool", passengerDetails.PoolMax)
}
Expand All @@ -120,19 +134,15 @@ func chartProcessUptime(passengerDetails *passengerStatus) {
func main() {
xmlData, err := retrievePassengerStats()
if err != nil {
fmt.Println("Error getting passenger data:", err)
return
}
var StatusInfo passengerStatus
dec := xml.NewDecoder(xmlData)
dec.CharsetReader = charset.NewReader
err = dec.Decode(&StatusInfo)
if err != nil {
fmt.Println(err)
log.Fatal("Error getting passenger data:", err)
}
chartProcessed(&StatusInfo)
chartMemory(&StatusInfo)
chartPendingRequest(&StatusInfo)
chartPoolUse(&StatusInfo)
chartProcessUptime(&StatusInfo)
PassengerStatusData, err := parsePassengerXML(&xmlData)
if err != nil {
log.Fatal("Error parsing passenger data:", err)
}
chartProcessed(&PassengerStatusData)
chartMemory(&PassengerStatusData)
chartPendingRequest(&PassengerStatusData)
chartPoolUse(&PassengerStatusData)
chartProcessUptime(&PassengerStatusData)
}

0 comments on commit 2f30a24

Please sign in to comment.