-
Notifications
You must be signed in to change notification settings - Fork 6
/
field.go
76 lines (55 loc) · 1.3 KB
/
field.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
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import "strconv"
type metricValueFunc func(string) (float64, error)
func fromNumeric(value string) (float64, error) {
return strconv.ParseFloat(value, 64)
}
type fieldFlag uint
const (
// Whether the field should be included as a label on an info metric.
asInfoLabel fieldFlag = 1 << iota
// Include the raw field value as a label on the metric.
asRawLabel
)
type field interface {
Name() string
MetricName() string
Help() string
}
// textField is an LVM report field whose value can not be made numeric, e.g.
// a device name or path.
type textField struct {
fieldName string
desc string
flags fieldFlag
metricName string
}
var _ field = (*textField)(nil)
func (f *textField) Name() string {
return f.fieldName
}
func (f *textField) MetricName() string {
return f.metricName
}
func (f *textField) Help() string {
return f.desc
}
// numericField is an LVM report field whose value is numeric or can be
// converted to a number.
type numericField struct {
fieldName string
desc string
flags fieldFlag
metricName string
metricValue metricValueFunc
}
var _ field = (*numericField)(nil)
func (f *numericField) Name() string {
return f.fieldName
}
func (f *numericField) MetricName() string {
return f.metricName
}
func (f *numericField) Help() string {
return f.desc
}