-
Notifications
You must be signed in to change notification settings - Fork 0
/
gauge_test.go
47 lines (42 loc) · 972 Bytes
/
gauge_test.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
42
43
44
45
46
47
package metrics_exporter
import (
"encoding/json"
"fmt"
"strings"
"testing"
"github.com/prometheus/common/expfmt"
)
var gjsonStr string = `{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"__name__": "go_goroutines",
"instance": "localhost:8000",
"job": "demo-app-metrics"
},
"value": [
1684735712.333,
"11"
]
}
]
}
}`
func TestGauge(t *testing.T) {
var prometheusQueryAPIResponse PrometheusQueryAPIResponse
json.Unmarshal([]byte(gjsonStr), &prometheusQueryAPIResponse)
gm := NewCountersMetrics("go_goroutines", "example Help", "gauge")
for _, result := range prometheusQueryAPIResponse.Data.Result {
gm.ParseMetricMap(result.Metric, result.Value[1].(string))
}
reader := strings.NewReader(gm.Print())
fmt.Println(gm.Print())
parser := expfmt.TextParser{}
_, err := parser.TextToMetricFamilies(reader)
if err != nil {
t.Errorf("Error happened" + err.Error())
}
}