forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.go
41 lines (35 loc) · 1.44 KB
/
decoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
//MetricMap maps name to float64 metric
type MetricMap map[string]float64
//StatsInfo describes one statistic (queue or exchange): its name, vhost it belongs to, and all associated metrics.
type StatsInfo struct {
labels map[string]string
metrics MetricMap
}
// RabbitReply is an inteface responsible for extracting usable
// information from RabbitMQ HTTP API replies, independent of the
// actual transfer format used.
type RabbitReply interface {
// MakeMap makes a flat map from string to float values from a
// RabbitMQ reply. Processing happens recursively and nesting
// is represented by '.'-separated keys. Entries are added
// only for values that can be reasonably converted to float
// (numbers and booleans). Failure to parse should result in
// an empty result map.
MakeMap() MetricMap
// MakeStatsInfo parses a list of details about some named
// RabbitMQ objects (i.e. list of queues, exchanges, etc.).
// Failure to parse should result in an empty result list.
MakeStatsInfo([]string) []StatsInfo
// GetString returns the string value for the given key
// If the key cannot be found the second return is false
GetString(key string) (string, bool)
}
// MakeReply instantiates the apropriate reply parser for a given
// reply and the content-type header
func MakeReply(contentType string, body []byte) (RabbitReply, error) {
if contentType == "application/bert" {
return makeBERTReply(body)
}
return makeJSONReply(body)
}