Skip to content

Commit d272878

Browse files
surprise30Vincent Vilenchik
and
Vincent Vilenchik
authored
Additional metrics for ISIS (#266)
* added a feature for macsec * small refactoring of some functions * added support for fec mode to interfaces plugin * small edits * small edits * small edits + chamged the mtu metric name * removed unnecessary string clean-up * small fixes as per pull request * tiny editing * Net 818 (#3) * adding number of isis adanceis per interface. Saving progress * finished * saving * saving * fixed some issues from pull request * fixes from merge request * added small fixes from pull review * added four new metrics for isis * added additional ISIS metrics * sorted imports * applied fixes from MR * small edit * small re-org * small re-org --------- Co-authored-by: Vincent Vilenchik <vincent.vilenchik@deepl.com> --------- Co-authored-by: Vincent Vilenchik <vincent.vilenchik@deepl.com>
1 parent 34e8b36 commit d272878

File tree

2 files changed

+120
-13
lines changed

2 files changed

+120
-13
lines changed

pkg/features/isis/collector.go

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,48 @@ package isis
44

55
import (
66
"strconv"
7+
"strings"
78

8-
"github.com/czerwonk/junos_exporter/pkg/collector"
9+
"github.com/pkg/errors"
910
"github.com/prometheus/client_golang/prometheus"
11+
12+
"github.com/czerwonk/junos_exporter/pkg/collector"
1013
)
1114

1215
const prefix string = "junos_isis_"
1316

1417
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
1830
)
1931

2032
func init() {
2133
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)
2649
}
2750

2851
type isisCollector struct {
@@ -40,8 +63,17 @@ func (*isisCollector) Name() string {
4063

4164
// Describe describes the metrics
4265
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
4577
}
4678

4779
// Collect collects metrics from JunOS
@@ -51,8 +83,8 @@ func (c *isisCollector) Collect(client collector.Client, ch chan<- prometheus.Me
5183
return err
5284
}
5385

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...)
5688

5789
if adjancies.Adjacencies != nil {
5890
for _, adj := range adjancies.Adjacencies {
@@ -73,10 +105,16 @@ func (c *isisCollector) Collect(client collector.Client, ch chan<- prometheus.Me
73105
state = 5.0
74106
}
75107

76-
ch <- prometheus.MustNewConstMetric(adjState, prometheus.GaugeValue, state, localLabelvalues...)
108+
ch <- prometheus.MustNewConstMetric(adjStateDesc, prometheus.GaugeValue, state, localLabelvalues...)
77109
}
78110
}
79111

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)
80118
return nil
81119
}
82120

@@ -99,3 +137,40 @@ func (c *isisCollector) isisAdjancies(client collector.Client) (*adjacencies, er
99137

100138
return &adjacencies{Up: float64(up), Total: float64(total), Adjacencies: x.Information.Adjacencies}, nil
101139
}
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+
}

pkg/features/isis/rpc.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
package isis
44

5+
import "encoding/xml"
6+
57
type result struct {
68
Information struct {
79
Adjacencies []adjacency `xml:"isis-adjacency"`
@@ -16,3 +18,33 @@ type adjacency struct {
1618
Holdtime int64 `xml:"holdtime"`
1719
SNPA string `xml:"snpa"`
1820
}
21+
22+
type interfaces struct {
23+
XMLName xml.Name `xml:"rpc-reply"`
24+
Text string `xml:",chardata"`
25+
Junos string `xml:"junos,attr"`
26+
IsisInterfaceInformation struct {
27+
Text string `xml:",chardata"`
28+
Xmlns string `xml:"xmlns,attr"`
29+
IsisInterface []struct {
30+
InterfaceName string `xml:"interface-name"`
31+
LSPInterval float64 `xml:"lsp-interval"`
32+
CSNPInterval float64 `xml:"csnp-interval"`
33+
HelloPadding string `xml:"hello-padding"`
34+
MaxHelloSize float64 `xml:"max-hello-size"`
35+
InterfaceLevelData struct {
36+
Level string `xml:"level"`
37+
AdjacencyCount float64 `xml:"adjacency-count"`
38+
InterfacePriority float64 `xml:"interface-priority"`
39+
Metric float64 `xml:"metric"`
40+
HelloTime float64 `xml:"hello-time"`
41+
HoldTime float64 `xml:"holdtime"`
42+
Passive string `xml:"passive"`
43+
} `xml:"interface-level-data"`
44+
} `xml:"isis-interface"`
45+
} `xml:"isis-interface-information"`
46+
Cli struct {
47+
Text string `xml:",chardata"`
48+
Banner string `xml:"banner"`
49+
} `xml:"cli"`
50+
}

0 commit comments

Comments
 (0)