forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ifstate.go
133 lines (112 loc) · 3.85 KB
/
ifstate.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2019 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/prom"
)
type ifstate struct {
Desc *prometheus.Desc
issued, duration, out prometheus.CounterVec
}
func newIfstate() ifstate {
sub := "ifstate"
return ifstate{
Desc: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, sub, "state"),
"Interface state, 0==inactive/expired/revoked, 1==active",
IfstateLabels{}.Labels(),
prometheus.Labels{},
),
issued: *prom.NewCounterVecWithLabels(Namespace, sub,
"issued_revocations_total",
"Total number of issued revocations.", IssuedLabels{}),
duration: *prom.NewCounterVecWithLabels(Namespace, sub,
"revocations_duration_seconds_total",
"Duration in seconds of issued revocations.", DurationLabels{}),
out: *prom.NewCounterVecWithLabels(Namespace, sub,
"sent_revocations_total",
"Total number of sent revocations.", SentLabels{}),
}
}
// IfstateMetric returns a prometheus metric
func (e ifstate) IfstateMetric(l IfstateLabels, v float64) prometheus.Metric {
return prometheus.MustNewConstMetric(e.Desc, prometheus.GaugeValue, v,
l.Values()...)
}
// Issued return the issued counter
func (e *ifstate) Issued(l IssuedLabels) prometheus.Counter {
return e.issued.WithLabelValues(l.Values()...)
}
// Duration return the duration counter
func (e *ifstate) Duration(l DurationLabels) prometheus.Counter {
return e.duration.WithLabelValues(l.Values()...)
}
// Sent return the duration counter
func (e *ifstate) Sent(l SentLabels) prometheus.Counter {
return e.out.WithLabelValues(l.Values()...)
}
// SentLabels define the labels attached to sent revocation counter.
type SentLabels struct {
Dst string
}
// Labels returns the list of labels.
func (l SentLabels) Labels() []string {
return []string{"dst"}
}
// Values returns the label values in the order defined by Labels.
func (l SentLabels) Values() []string {
return []string{l.Dst}
}
// IfstateLabels define the labels attached to interface state.
type IfstateLabels struct {
IfID common.IFIDType
NeighIA addr.IA
}
// Labels returns the list of labels.
func (l IfstateLabels) Labels() []string {
return []string{"if_id", prom.LabelNeighIA}
}
// Values returns the label values in the order defined by Labels.
func (l IfstateLabels) Values() []string {
return []string{l.IfID.String(), l.NeighIA.String()}
}
// IssuedLabels define the labels attached to revocation metrics.
type IssuedLabels struct {
IfID common.IFIDType
NeighIA addr.IA
State string
}
// Labels returns the list of labels.
func (l IssuedLabels) Labels() []string {
return []string{"if_id", prom.LabelNeighIA, "state"}
}
// Values returns the label values in the order defined by Labels.
func (l IssuedLabels) Values() []string {
return []string{l.IfID.String(), l.NeighIA.String(), l.State}
}
// DurationLabels define the labels attached to duration metric.
type DurationLabels struct {
IfID common.IFIDType
NeighIA addr.IA
}
// Labels returns the list of labels.
func (l DurationLabels) Labels() []string {
return []string{"if_id", prom.LabelNeighIA}
}
// Values returns the label values in the order defined by Labels.
func (l DurationLabels) Values() []string {
return []string{l.IfID.String(), l.NeighIA.String()}
}