Skip to content

Commit

Permalink
hande build with lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
Row committed Jun 15, 2016
1 parent 661154a commit dc902bf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions rabbitClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package main
import (
"encoding/json"
"net/http"
"io"

log "github.com/Sirupsen/logrus"
)

func getMetrics(config rabbitExporterConfig, endpoint string) io.ReadCloser {
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 @@ -21,21 +20,24 @@ func getMetrics(config rabbitExporterConfig, endpoint string) io.ReadCloser {
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 resp.Body
build(json.NewDecoder(resp.Body))
resp.Body.Close()
}

func getQueueMap(config rabbitExporterConfig) map[string]MetricMap {
metric := getMetrics(config, "queues")
qm := MakeQueueMap(json.NewDecoder(metric))
metric.Close()
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(json.NewDecoder(metric))
metric.Close()
var overview MetricMap
loadMetrics(config, "overview", func(d *json.Decoder) {
overview = MakeMap(d)
})
return overview
}

0 comments on commit dc902bf

Please sign in to comment.