forked from cellscape/rsyslog_exporter
-
Notifications
You must be signed in to change notification settings - Fork 14
/
point.go
61 lines (49 loc) · 1.03 KB
/
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
60
61
package main
import (
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
)
type pointType int
const (
counter pointType = iota
gauge
)
var (
ErrIncompatiblePointType = errors.New("incompatible point type")
ErrUnknownPointType = errors.New("unknown point type")
)
type point struct {
Name string
Description string
Type pointType
Value int64
LabelName string
LabelValue string
}
func (p *point) promDescription() *prometheus.Desc {
return prometheus.NewDesc(
prometheus.BuildFQName("", "rsyslog", p.Name),
p.Description,
[]string{p.promLabelName()},
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)
}