-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathpoint.go
63 lines (53 loc) · 1.08 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
62
63
package main
import (
"errors"
"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
}
func (p *point) add(newPoint *point) error {
switch newPoint.Type {
case gauge:
if p.Type != gauge {
return ErrIncompatiblePointType
}
p.Value = newPoint.Value
case counter:
if p.Type != counter {
return ErrIncompatiblePointType
}
p.Value = p.Value + newPoint.Value
default:
return ErrUnknownPointType
}
return nil
}
func (p *point) promDescription() *prometheus.Desc {
return prometheus.NewDesc(
prometheus.BuildFQName("", "rsyslog", p.Name),
p.Description,
nil, 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)
}