Skip to content

Commit

Permalink
Merge branch 'Row-clean-up-connections'
Browse files Browse the repository at this point in the history
  • Loading branch information
kbudde committed Jun 23, 2016
2 parents 1a34538 + dc902bf commit c2841f3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rabbitClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
log "github.com/Sirupsen/logrus"
)

func getMetrics(config rabbitExporterConfig, endpoint string) *json.Decoder {
func loadMetrics(config rabbitExporterConfig, endpoint string, build func(d *json.Decoder)) {
client := &http.Client{}
req, err := http.NewRequest("GET", config.RabbitURL+"/api/"+endpoint, nil)
req.SetBasicAuth(config.RabbitUsername, config.RabbitPassword)
Expand All @@ -20,19 +20,24 @@ func getMetrics(config rabbitExporterConfig, endpoint string) *json.Decoder {
status = resp.StatusCode
}
log.WithFields(log.Fields{"error": err, "host": config.RabbitURL, "statusCode": status}).Error("Error while retrieving data from rabbitHost")
return nil
return
}
return json.NewDecoder(resp.Body)
build(json.NewDecoder(resp.Body))
resp.Body.Close()
}

func getQueueMap(config rabbitExporterConfig) map[string]MetricMap {
metric := getMetrics(config, "queues")
qm := MakeQueueMap(metric)
var qm map[string]MetricMap
loadMetrics(config, "queues", func(d *json.Decoder) {
qm = MakeQueueMap(d)
})
return qm
}

func getOverviewMap(config rabbitExporterConfig) MetricMap {
metric := getMetrics(config, "overview")
overview := MakeMap(metric)
var overview MetricMap
loadMetrics(config, "overview", func(d *json.Decoder) {
overview = MakeMap(d)
})
return overview
}

0 comments on commit c2841f3

Please sign in to comment.