forked from prometheus-community/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.go
59 lines (48 loc) · 1004 Bytes
/
point.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
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
)
type pointType int
const (
counter pointType = iota
gauge
)
type point struct {
Name string
Description string
Type pointType
Value int64
LabelName string
LabelValue string
}
func (p *point) promDescription() *prometheus.Desc {
variableLabels := []string{}
if p.promLabelName() != "" {
variableLabels = []string{p.promLabelName()}
}
return prometheus.NewDesc(
prometheus.BuildFQName("", "rsyslog", p.Name),
p.Description,
variableLabels,
nil,
)
}
func (p *point) promType() prometheus.ValueType {
if p.Type == counter {
return prometheus.CounterValue
}
return prometheus.GaugeValue
}
func (p *point) promValue() float64 {
return float64(p.Value)
}
func (p *point) promLabelValue() string {
return p.LabelValue
}
func (p *point) promLabelName() string {
return p.LabelName
}
func (p *point) key() string {
return fmt.Sprintf("%s.%s", p.Name, p.LabelValue)
}