forked from prometheus-community/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dyn_stat.go
38 lines (32 loc) · 824 Bytes
/
dyn_stat.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
package main
import (
"encoding/json"
"fmt"
)
type dynStat struct {
Name string `json:"name"`
Origin string `json:"origin"`
Values map[string]int64 `json:"values"`
}
func newDynStatFromJSON(b []byte) (*dynStat, error) {
var pstat dynStat
err := json.Unmarshal(b, &pstat)
if err != nil {
return nil, fmt.Errorf("error decoding values stat `%v`: %v", string(b), err)
}
return &pstat, nil
}
func (i *dynStat) toPoints() []*point {
points := make([]*point, 0, len(i.Values))
for name, value := range i.Values {
points = append(points, &point{
Name: fmt.Sprintf("dynstat_%s", i.Name),
Type: counter,
Value: value,
Description: fmt.Sprintf("dynamic statistic bucket %s", i.Name),
LabelName: "counter",
LabelValue: name,
})
}
return points
}