@@ -4,25 +4,48 @@ package isis
4
4
5
5
import (
6
6
"strconv"
7
+ "strings"
7
8
8
- "github.com/czerwonk/junos_exporter/ pkg/collector "
9
+ "github.com/pkg/errors "
9
10
"github.com/prometheus/client_golang/prometheus"
11
+
12
+ "github.com/czerwonk/junos_exporter/pkg/collector"
10
13
)
11
14
12
15
const prefix string = "junos_isis_"
13
16
14
17
var (
15
- upCount * prometheus.Desc
16
- totalCount * prometheus.Desc
17
- adjState * prometheus.Desc
18
+ upCountDesc * prometheus.Desc
19
+ totalCountDesc * prometheus.Desc
20
+ adjStateDesc * prometheus.Desc
21
+ adjCountDesc * prometheus.Desc
22
+ adjPriorityDesc * prometheus.Desc
23
+ adjMetricDesc * prometheus.Desc
24
+ adjHelloTimerDesc * prometheus.Desc
25
+ adjHoldTimerDesc * prometheus.Desc
26
+ lspIntervalDesc * prometheus.Desc
27
+ csnpIntervalDesc * prometheus.Desc
28
+ helloPaddingDesc * prometheus.Desc
29
+ maxHelloSizeDesc * prometheus.Desc
18
30
)
19
31
20
32
func init () {
21
33
l := []string {"target" }
22
- upCount = prometheus .NewDesc (prefix + "up_count" , "Number of ISIS Adjacencies in state up" , l , nil )
23
- totalCount = prometheus .NewDesc (prefix + "total_count" , "Number of ISIS Adjacencies" , l , nil )
24
- l = append (l , "interface_name" , "sysem_name" , "level" )
25
- adjState = prometheus .NewDesc (prefix + "adjacency_state" , "The ISIS Adjacency state (0 = DOWN, 1 = UP, 2 = NEW, 3 = ONE-WAY, 4 =INITIALIZING , 5 = REJECTED)" , l , nil )
34
+ upCountDesc = prometheus .NewDesc (prefix + "up_count" , "Number of ISIS Adjacencies in state up" , l , nil )
35
+ totalCountDesc = prometheus .NewDesc (prefix + "total_count" , "Number of ISIS Adjacencies" , l , nil )
36
+ l = append (l , "interface_name" )
37
+ lspIntervalDesc = prometheus .NewDesc (prefix + "lsp_interval_ms" , "The ISIS LSP interval" , l , nil )
38
+ csnpIntervalDesc = prometheus .NewDesc (prefix + "csnp_interval_seconds" , "The ISIS CSNP interval" , l , nil )
39
+ helloPaddingDesc = prometheus .NewDesc (prefix + "hello_padding" , "The ISIS hello padding (0 = UNKNOWN, 1 = ADAPTIVE, 2 = DISABLE, 3 = LOOSE, 4 = STRICT)" , l , nil )
40
+ maxHelloSizeDesc = prometheus .NewDesc (prefix + "max_hello_size_bytes" , "The ISIS max hello size" , l , nil )
41
+ l = append (l , "system_name" , "level" )
42
+ adjStateDesc = prometheus .NewDesc (prefix + "adjacency_state" , "The ISIS Adjacency state (0 = DOWN, 1 = UP, 2 = NEW, 3 = ONE-WAY, 4 =INITIALIZING , 5 = REJECTED)" , l , nil )
43
+ interfaceMetricsLabels := []string {"target" , "interface_name" , "level" }
44
+ adjCountDesc = prometheus .NewDesc (prefix + "adjacency_count" , "The number of ISIS adjacencies for an interface" , interfaceMetricsLabels , nil )
45
+ adjPriorityDesc = prometheus .NewDesc (prefix + "adjacency_priority" , "The ISIS adjacency priority" , interfaceMetricsLabels , nil )
46
+ adjMetricDesc = prometheus .NewDesc (prefix + "adjacency_metric" , "The ISIS adjacency metric" , interfaceMetricsLabels , nil )
47
+ adjHelloTimerDesc = prometheus .NewDesc (prefix + "adjacency_hello_timer_seconds" , "The ISIS adjacency hello timer" , interfaceMetricsLabels , nil )
48
+ adjHoldTimerDesc = prometheus .NewDesc (prefix + "adjacency_hold_timer_seconds" , "The ISIS adjacency hold timer" , interfaceMetricsLabels , nil )
26
49
}
27
50
28
51
type isisCollector struct {
@@ -40,8 +63,17 @@ func (*isisCollector) Name() string {
40
63
41
64
// Describe describes the metrics
42
65
func (* isisCollector ) Describe (ch chan <- * prometheus.Desc ) {
43
- ch <- upCount
44
- ch <- totalCount
66
+ ch <- upCountDesc
67
+ ch <- totalCountDesc
68
+ ch <- adjCountDesc
69
+ ch <- adjPriorityDesc
70
+ ch <- adjMetricDesc
71
+ ch <- adjHelloTimerDesc
72
+ ch <- adjHoldTimerDesc
73
+ ch <- lspIntervalDesc
74
+ ch <- csnpIntervalDesc
75
+ ch <- helloPaddingDesc
76
+ ch <- maxHelloSizeDesc
45
77
}
46
78
47
79
// Collect collects metrics from JunOS
@@ -51,8 +83,8 @@ func (c *isisCollector) Collect(client collector.Client, ch chan<- prometheus.Me
51
83
return err
52
84
}
53
85
54
- ch <- prometheus .MustNewConstMetric (upCount , prometheus .GaugeValue , adjancies .Up , labelValues ... )
55
- ch <- prometheus .MustNewConstMetric (totalCount , prometheus .GaugeValue , adjancies .Total , labelValues ... )
86
+ ch <- prometheus .MustNewConstMetric (upCountDesc , prometheus .GaugeValue , adjancies .Up , labelValues ... )
87
+ ch <- prometheus .MustNewConstMetric (totalCountDesc , prometheus .GaugeValue , adjancies .Total , labelValues ... )
56
88
57
89
if adjancies .Adjacencies != nil {
58
90
for _ , adj := range adjancies .Adjacencies {
@@ -73,10 +105,16 @@ func (c *isisCollector) Collect(client collector.Client, ch chan<- prometheus.Me
73
105
state = 5.0
74
106
}
75
107
76
- ch <- prometheus .MustNewConstMetric (adjState , prometheus .GaugeValue , state , localLabelvalues ... )
108
+ ch <- prometheus .MustNewConstMetric (adjStateDesc , prometheus .GaugeValue , state , localLabelvalues ... )
77
109
}
78
110
}
79
111
112
+ var ifas interfaces
113
+ err = client .RunCommandAndParse ("show isis interface extensive" , & ifas )
114
+ if err != nil {
115
+ return errors .Wrap (err , "failed to run command 'show isis interface extensive'" )
116
+ }
117
+ c .isisInterfaces (ifas , ch , labelValues )
80
118
return nil
81
119
}
82
120
@@ -99,3 +137,40 @@ func (c *isisCollector) isisAdjancies(client collector.Client) (*adjacencies, er
99
137
100
138
return & adjacencies {Up : float64 (up ), Total : float64 (total ), Adjacencies : x .Information .Adjacencies }, nil
101
139
}
140
+
141
+ func (c * isisCollector ) isisInterfaces (interfaces interfaces , ch chan <- prometheus.Metric , labelValues []string ) {
142
+ for _ , i := range interfaces .IsisInterfaceInformation .IsisInterface {
143
+ if strings .ToLower (i .InterfaceLevelData .Passive ) == "passive" {
144
+ continue
145
+ }
146
+ labels := append (labelValues ,
147
+ i .InterfaceName ,
148
+ i .InterfaceLevelData .Level )
149
+ ch <- prometheus .MustNewConstMetric (adjCountDesc , prometheus .CounterValue , i .InterfaceLevelData .AdjacencyCount , labels ... )
150
+ ch <- prometheus .MustNewConstMetric (adjPriorityDesc , prometheus .GaugeValue , i .InterfaceLevelData .InterfacePriority , labels ... )
151
+ ch <- prometheus .MustNewConstMetric (adjMetricDesc , prometheus .GaugeValue , i .InterfaceLevelData .Metric , labels ... )
152
+ ch <- prometheus .MustNewConstMetric (adjHelloTimerDesc , prometheus .GaugeValue , i .InterfaceLevelData .HelloTime , labels ... )
153
+ ch <- prometheus .MustNewConstMetric (adjHoldTimerDesc , prometheus .GaugeValue , i .InterfaceLevelData .HoldTime , labels ... )
154
+ additionaLabels := append (labelValues , i .InterfaceName )
155
+ helloPadding := getHelloPadding (i .HelloPadding )
156
+ ch <- prometheus .MustNewConstMetric (lspIntervalDesc , prometheus .GaugeValue , i .LSPInterval , additionaLabels ... )
157
+ ch <- prometheus .MustNewConstMetric (csnpIntervalDesc , prometheus .GaugeValue , i .CSNPInterval , additionaLabels ... )
158
+ ch <- prometheus .MustNewConstMetric (helloPaddingDesc , prometheus .GaugeValue , helloPadding , additionaLabels ... )
159
+ ch <- prometheus .MustNewConstMetric (maxHelloSizeDesc , prometheus .GaugeValue , i .MaxHelloSize , additionaLabels ... )
160
+ }
161
+ }
162
+
163
+ func getHelloPadding (h string ) float64 {
164
+ switch strings .ToLower (h ) {
165
+ case "adaptive" :
166
+ return 1.0
167
+ case "disable" :
168
+ return 2.0
169
+ case "loose" :
170
+ return 3.0
171
+ case "strict" :
172
+ return 4.0
173
+ default :
174
+ return 0.0
175
+ }
176
+ }
0 commit comments