From a1a2effa27580b904aa41714e31110c7074eb04d Mon Sep 17 00:00:00 2001 From: Tynan Young Date: Fri, 13 Sep 2024 15:50:10 +1000 Subject: [PATCH] Update dependencies and implement structured logging --- collector/bgp.go | 65 ++++---- collector/collector.go | 25 ++-- collector/environment.go | 28 ++-- collector/fpc.go | 9 +- collector/interface.go | 307 +++++++++++++++++++------------------- collector/ipsec.go | 56 +++---- collector/optics.go | 95 ++++++------ collector/ospf.go | 87 +++++------ collector/power.go | 47 +++--- collector/route_engine.go | 81 +++++----- go.mod | 45 +++--- go.sum | 237 ++++++++++------------------- junos_exporter.go | 174 +++++++++++---------- 13 files changed, 624 insertions(+), 632 deletions(-) diff --git a/collector/bgp.go b/collector/bgp.go index 41baa9c..d3c0e5f 100644 --- a/collector/bgp.go +++ b/collector/bgp.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -55,11 +56,13 @@ var ( ) // BGPCollector collects BGP metrics, implemented as per the Collector interface. -type BGPCollector struct{} +type BGPCollector struct { + logger log.Logger +} // NewBGPCollector returns a new BGPCollector -func NewBGPCollector() *BGPCollector { - return &BGPCollector{} +func NewBGPCollector(logger log.Logger) *BGPCollector { + return &BGPCollector{logger: logger} } // Name of the collector. @@ -138,12 +141,13 @@ func (c *BGPCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, f bgpPeerInterfaces, routeInstances, routeInstanceNames, + c.logger, ); err != nil { totalBGPErrors++ errors = append(errors, err) } - if err := processBGPNeighborNetconfReply(replyNeighbor, ch); err != nil { + if err := processBGPNeighborNetconfReply(replyNeighbor, ch, c.logger); err != nil { totalBGPErrors++ errors = append(errors, err) } @@ -186,7 +190,7 @@ func getBgpPeerInterface(reply *netconf.RPCReply) (map[string]string, error) { return peerToInterface, nil } -func processBGPNeighborNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) error { +func processBGPNeighborNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, logger log.Logger) error { var netconfReply bgpNeighborRPCReply if err := xml.Unmarshal([]byte(reply.RawReply), &netconfReply); err != nil { return fmt.Errorf("could not unmarshal netconf reply xml: %s", err) @@ -214,7 +218,7 @@ func processBGPNeighborNetconfReply(reply *netconf.RPCReply, ch chan<- prometheu strings.TrimSpace(peerData.PeerCfgRti.Text), strings.TrimSpace(peerData.NlriTypePeer), } - newGauge(ch, bgpDesc["PeerRIBAdvertisedPrefixCount"], peerData.BGPRIB.AdvertisedPrefixCount, peerLabels...) + newGauge(logger, ch, bgpDesc["PeerRIBAdvertisedPrefixCount"], peerData.BGPRIB.AdvertisedPrefixCount, peerLabels...) } } return nil @@ -229,6 +233,7 @@ func processBGPNetconfReply( bgpPeerInterfaces map[string]string, routeInstances map[string]string, routeInstanceNames map[string]string, + logger log.Logger, ) error { var netconfReply bgpNeighborRPCReply @@ -250,27 +255,27 @@ func processBGPNetconfReply( return fmt.Errorf("could not unmarshal netconf reply xml: %s", err) } ribLabels := []string{routeInstanceBGP} - newGauge(ch, bgpDesc["GroupCount"], netconfReplyInstance.BgpInformation.GroupCount, ribLabels...) - newGauge(ch, bgpDesc["PeerCount"], netconfReplyInstance.BgpInformation.PeerCount, ribLabels...) - newGauge(ch, bgpDesc["DownPeerCount"], netconfReplyInstance.BgpInformation.DownPeerCount, ribLabels...) + newGauge(logger, ch, bgpDesc["GroupCount"], netconfReplyInstance.BgpInformation.GroupCount, ribLabels...) + newGauge(logger, ch, bgpDesc["PeerCount"], netconfReplyInstance.BgpInformation.PeerCount, ribLabels...) + newGauge(logger, ch, bgpDesc["DownPeerCount"], netconfReplyInstance.BgpInformation.DownPeerCount, ribLabels...) for routeInstance := range routeInstances { if routeInstanceBGP == routeInstances[routeInstance] { for _, ribData := range netconfReplyInstance.BgpInformation.BgpRib { if ribData.Name == routeInstance { if val, ok := routeInstanceCheck[routeInstanceBGP]; !ok { routeInstanceCheck[routeInstanceBGP] = val - newGauge(ch, bgpDesc["RIBTotalPrefixCount"], ribData.TotalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBHistoryPrefixCount"], ribData.HistoryPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBDampedPrefixCount"], ribData.DampedPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBTotalExternalPrefixCount"], ribData.TotalExternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBActiveExternalPrefixCount"], ribData.ActiveExternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBAcceptedExternalPrefixCount"], ribData.AcceptedExternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBSuppressedExternalPrefixCount"], ribData.SuppressedExternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBTotalInternalPrefixCount"], ribData.TotalInternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBActiveInternalPrefixCount"], ribData.ActiveInternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBAcceptedInternalPrefixCount"], ribData.AcceptedInternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBSuppressedInternalPrefixCount"], ribData.SuppressedInternalPrefixCount, ribLabels...) - newGauge(ch, bgpDesc["RIBPendingPrefixCount"], ribData.PendingPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBTotalPrefixCount"], ribData.TotalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBHistoryPrefixCount"], ribData.HistoryPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBDampedPrefixCount"], ribData.DampedPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBTotalExternalPrefixCount"], ribData.TotalExternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBActiveExternalPrefixCount"], ribData.ActiveExternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBAcceptedExternalPrefixCount"], ribData.AcceptedExternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBSuppressedExternalPrefixCount"], ribData.SuppressedExternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBTotalInternalPrefixCount"], ribData.TotalInternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBActiveInternalPrefixCount"], ribData.ActiveInternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBAcceptedInternalPrefixCount"], ribData.AcceptedInternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBSuppressedInternalPrefixCount"], ribData.SuppressedInternalPrefixCount, ribLabels...) + newGauge(logger, ch, bgpDesc["RIBPendingPrefixCount"], ribData.PendingPrefixCount, ribLabels...) } } } @@ -327,15 +332,15 @@ func processBGPNetconfReply( ch <- prometheus.MustNewConstMetric(bgpDesc["PeerPeerState"], prometheus.GaugeValue, 0.0, peerRIBLabels...) } - newCounter(ch, bgpDesc["PeerInputMessages"], peerData.InputMessages.Text, peerRIBLabels...) - newCounter(ch, bgpDesc["PeerOutputMessages"], peerData.OutputMessages.Text, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerRouteQueueCount"], peerData.RouteQueueCount.Text, peerRIBLabels...) - newCounter(ch, bgpDesc["PeerFlapCount"], peerData.FlapCount.Text, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerElapsedTime"], peerData.ElapsedTime.Seconds, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerRIBActivePrefixCount"], peerData.BGPRIB.ActivePrefixCount, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerRIBReceivedPrefixCount"], peerData.BGPRIB.ReceivedPrefixCount, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerRIBAcceptedPrefixCount"], peerData.BGPRIB.AcceptedPrefixCount, peerRIBLabels...) - newGauge(ch, bgpDesc["PeerRIBSuppressedPrefixCount"], peerData.BGPRIB.SuppressedPrefixCount, peerRIBLabels...) + newCounter(logger, ch, bgpDesc["PeerInputMessages"], peerData.InputMessages.Text, peerRIBLabels...) + newCounter(logger, ch, bgpDesc["PeerOutputMessages"], peerData.OutputMessages.Text, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerRouteQueueCount"], peerData.RouteQueueCount.Text, peerRIBLabels...) + newCounter(logger, ch, bgpDesc["PeerFlapCount"], peerData.FlapCount.Text, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerElapsedTime"], peerData.ElapsedTime.Seconds, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerRIBActivePrefixCount"], peerData.BGPRIB.ActivePrefixCount, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerRIBReceivedPrefixCount"], peerData.BGPRIB.ReceivedPrefixCount, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerRIBAcceptedPrefixCount"], peerData.BGPRIB.AcceptedPrefixCount, peerRIBLabels...) + newGauge(logger, ch, bgpDesc["PeerRIBSuppressedPrefixCount"], peerData.BGPRIB.SuppressedPrefixCount, peerRIBLabels...) } for peerType, count := range peerTypes { diff --git a/collector/collector.go b/collector/collector.go index b5ac75b..353d465 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -7,7 +7,8 @@ import ( "sync" "time" - "github.com/prometheus/common/log" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/crypto/ssh" @@ -48,13 +49,15 @@ type Config struct { type Exporter struct { Collectors []Collector config Config + logger log.Logger } // NewExporter returns a new Exporter. -func NewExporter(collectors []Collector, config Config) (*Exporter, error) { +func NewExporter(collectors []Collector, config Config, logger log.Logger) (*Exporter, error) { return &Exporter{ Collectors: collectors, config: config, + logger: logger, }, nil } @@ -66,12 +69,12 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { wg := &sync.WaitGroup{} for _, collector := range e.Collectors { wg.Add(1) - go e.runCollector(ch, collector, wg) + go e.runCollector(ch, collector, wg, e.logger) } wg.Wait() } -func (e *Exporter) runCollector(ch chan<- prometheus.Metric, collector Collector, wg *sync.WaitGroup) { +func (e *Exporter) runCollector(ch chan<- prometheus.Metric, collector Collector, wg *sync.WaitGroup, logger log.Logger) { defer wg.Done() collectorName := collector.Name() @@ -84,7 +87,7 @@ func (e *Exporter) runCollector(ch chan<- prometheus.Metric, collector Collector if len(errors) > 0 { ch <- prometheus.MustNewConstMetric(junosDesc["CollectorUp"], prometheus.GaugeValue, 0, collector.Name()) for _, err := range errors { - log.Errorf("collector %q scrape failed: %s", collectorName, err) + level.Error(logger).Log("msg", "collector scrape failed", "collector", collectorName, "err", err) } } else { ch <- prometheus.MustNewConstMetric(junosDesc["CollectorUp"], prometheus.GaugeValue, 1, collectorName) @@ -106,32 +109,32 @@ func colPromDesc(subsystem string, metricName string, metricDescription string, return prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, metricName), metricDescription, labels, nil) } -func newGauge(ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { +func newGauge(logger log.Logger, ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { if metric != "" { i, err := strconv.ParseFloat(strings.TrimSpace(metric), 64) if err != nil { - log.Errorf("could not convert metric to float64: %s", err) + level.Error(logger).Log("msg", "could not convert metric to float64", "err", err) } ch <- prometheus.MustNewConstMetric(descName, prometheus.GaugeValue, i, labels...) } } -func newCounter(ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { +func newCounter(logger log.Logger, ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { if metric != "" { i, err := strconv.ParseFloat(strings.TrimSpace(metric), 64) if err != nil { - log.Errorf("could not convert metric to float64: %s", err) + level.Error(logger).Log("msg", "could not convert metric to float64", "err", err) } ch <- prometheus.MustNewConstMetric(descName, prometheus.CounterValue, i, labels...) } } -func newGaugeMB(ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { +func newGaugeMB(logger log.Logger, ch chan<- prometheus.Metric, descName *prometheus.Desc, metric string, labels ...string) { if metric != "" { re := regexp.MustCompile("[0-9]+") i, err := strconv.ParseFloat(strings.TrimSpace(re.FindString(metric)), 64) if err != nil { - log.Errorf("could not convert metric to float64: %s", err) + level.Error(logger).Log("msg", "could not convert metric to float64", "err", err) } ch <- prometheus.MustNewConstMetric(descName, prometheus.GaugeValue, i*1000000, labels...) diff --git a/collector/environment.go b/collector/environment.go index db4c573..128c00d 100644 --- a/collector/environment.go +++ b/collector/environment.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -29,11 +30,13 @@ var ( ) // EnvCollector collects environment metrics, implemented as per the Collector interface. -type EnvCollector struct{} +type EnvCollector struct { + logger log.Logger +} // NewEnvCollector returns a new EnvCollector. -func NewEnvCollector() *EnvCollector { - return &EnvCollector{} +func NewEnvCollector(logger log.Logger) *EnvCollector { + return &EnvCollector{logger: logger} } // Name of the collector. @@ -68,7 +71,7 @@ func (c *EnvCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, f return errors, totalEnvErrors } - if err := processEnvNetconfReply(replyEnv, replyEnvTempThreshold, ch); err != nil { + if err := processEnvNetconfReply(replyEnv, replyEnvTempThreshold, ch, c.logger); err != nil { totalEnvErrors++ errors = append(errors, err) } @@ -80,6 +83,7 @@ func processEnvNetconfReply( replyEnv *netconf.RPCReply, replyEnvTempThreshold *netconf.RPCReply, ch chan<- prometheus.Metric, + logger log.Logger, ) error { var netconfEnvReply envRPCReply var netconfEnvTempThresholdReply envTempThresholdRPCReply @@ -95,7 +99,7 @@ func processEnvNetconfReply( envStatus = 1.0 } ch <- prometheus.MustNewConstMetric(envDesc["Status"], prometheus.GaugeValue, envStatus, labels...) - newGauge(ch, envDesc["Temp"], envData.Temperature.Temp, labels...) + newGauge(logger, ch, envDesc["Temp"], envData.Temperature.Temp, labels...) } // ** unmarshal show chassis temperature-thresholds END ** // @@ -107,13 +111,13 @@ func processEnvNetconfReply( for _, envTempThresholdData := range netconfEnvTempThresholdReply.EnvTempThresholdInformation.EnvTempThreshold { labels := []string{strings.TrimSpace(envTempThresholdData.Name.Text)} - newGauge(ch, envDesc["FanNormalSpeed"], envTempThresholdData.FanNormalSpeed.Text, labels...) - newGauge(ch, envDesc["FanHighSpeed"], envTempThresholdData.FanHighSpeed.Text, labels...) - newGauge(ch, envDesc["BadFanYellowAlarm"], envTempThresholdData.BadFanYellowAlarm.Text, labels...) - newGauge(ch, envDesc["BadFanRedAlarm"], envTempThresholdData.BadFanRedAlarm.Text, labels...) - newGauge(ch, envDesc["YellowAlarm"], envTempThresholdData.YellowAlarm.Text, labels...) - newGauge(ch, envDesc["RedAlarm"], envTempThresholdData.RedAlarm.Text, labels...) - newGauge(ch, envDesc["FireShutdown"], envTempThresholdData.FireShutdown.Text, labels...) + newGauge(logger, ch, envDesc["FanNormalSpeed"], envTempThresholdData.FanNormalSpeed.Text, labels...) + newGauge(logger, ch, envDesc["FanHighSpeed"], envTempThresholdData.FanHighSpeed.Text, labels...) + newGauge(logger, ch, envDesc["BadFanYellowAlarm"], envTempThresholdData.BadFanYellowAlarm.Text, labels...) + newGauge(logger, ch, envDesc["BadFanRedAlarm"], envTempThresholdData.BadFanRedAlarm.Text, labels...) + newGauge(logger, ch, envDesc["YellowAlarm"], envTempThresholdData.YellowAlarm.Text, labels...) + newGauge(logger, ch, envDesc["RedAlarm"], envTempThresholdData.RedAlarm.Text, labels...) + newGauge(logger, ch, envDesc["FireShutdown"], envTempThresholdData.FireShutdown.Text, labels...) } // ** unmarshal show chassis temperature-thresholds END ** // diff --git a/collector/fpc.go b/collector/fpc.go index 519bf88..80576f3 100644 --- a/collector/fpc.go +++ b/collector/fpc.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -30,11 +31,13 @@ var ( ) // FPCCollector collects environment metrics, implemented as per the Collector interface. -type FPCCollector struct{} +type FPCCollector struct { + logger log.Logger +} // NewFPCCollector returns a new FPCCollector. -func NewFPCCollector() *FPCCollector { - return &FPCCollector{} +func NewFPCCollector(logger log.Logger) *FPCCollector { + return &FPCCollector{logger: logger} } // Name of the collector. diff --git a/collector/interface.go b/collector/interface.go index 8117cf9..1b9a911 100644 --- a/collector/interface.go +++ b/collector/interface.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -164,11 +165,13 @@ func getInterfaceDesc(ifaceDescrKeys, ifaceMetricKeys []string) map[string]*prom } // InterfaceCollector collects Iface metrics, implemented as per the Collector iface. -type InterfaceCollector struct{} +type InterfaceCollector struct { + logger log.Logger +} // NewInterfaceCollector returns a new InterfaceCollector. -func NewInterfaceCollector() *InterfaceCollector { - return &InterfaceCollector{} +func NewInterfaceCollector(logger log.Logger) *InterfaceCollector { + return &InterfaceCollector{logger: logger} } // Name of the collector. @@ -194,7 +197,7 @@ func (c *InterfaceCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]er errors = append(errors, fmt.Errorf("could not execute netconf RPC call: %s", err)) return errors, totalIfaceErrors } - if err := processIfaceNetconfReply(reply, ch, conf.IfaceDescrKeys, conf.IfaceMetricKeys); err != nil { + if err := processIfaceNetconfReply(reply, ch, conf.IfaceDescrKeys, conf.IfaceMetricKeys, c.logger); err != nil { totalIfaceErrors++ errors = append(errors, err) } @@ -210,7 +213,7 @@ func (c *BoolIfPresent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err return nil } -func processIfaceNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, ifaceDescrKeys, ifaceMetricKeys []string) error { +func processIfaceNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, ifaceDescrKeys, ifaceMetricKeys []string, logger log.Logger) error { var netconfReply ifaceRPCReply r := strings.NewReader(reply.RawReply) d := xml.NewDecoder(r) @@ -269,47 +272,47 @@ func processIfaceNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metr ifaceDescrLabels = append(ifaceDescrLabels, allIfaceDescrKeys[configuredKey].(string)) } } - newCounter(ch, ifaceDesc["InterfaceDescription"], "1", ifaceDescrLabels...) + newCounter(logger, ch, ifaceDesc["InterfaceDescription"], "1", ifaceDescrLabels...) } for _, configuredKey := range ifaceMetricKeys { if allIfaceDescrKeys[configuredKey] != nil { - newCounter(ch, ifaceDesc[configuredKey], strings.TrimSpace(allIfaceDescrKeys[configuredKey].(string)), strings.TrimSpace(ifaceData.Name.Text)) + newCounter(logger, ch, ifaceDesc[configuredKey], strings.TrimSpace(allIfaceDescrKeys[configuredKey].(string)), strings.TrimSpace(ifaceData.Name.Text)) } } - newCounter(ch, ifaceDesc["InterfaceFlapped"], ifaceData.InterfaceFlapped.Seconds, ifaceLabels...) - newCounter(ch, ifaceDesc["InputBytes"], ifaceData.TrafficStatistics.InputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputBytes"], ifaceData.TrafficStatistics.OutputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputPackets"], ifaceData.TrafficStatistics.InputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputPackets"], ifaceData.TrafficStatistics.OutputPackets.Text, ifaceLabels...) - newGauge(ch, ifaceDesc["InputBps"], ifaceData.TrafficStatistics.InputBps.Text, ifaceLabels...) - newGauge(ch, ifaceDesc["OutputBps"], ifaceData.TrafficStatistics.OutputBps.Text, ifaceLabels...) - newGauge(ch, ifaceDesc["InputPps"], ifaceData.TrafficStatistics.InputPps.Text, ifaceLabels...) - newGauge(ch, ifaceDesc["OutputPps"], ifaceData.TrafficStatistics.OutputPps.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["V6InputBytes"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.InputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["V6OutputBytes"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.OutputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["V6InputPackets"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.InputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["V6OutputPackets"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.OutputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputErrors"], ifaceData.InputErrorList.InputErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputDrops"], ifaceData.InputErrorList.InputDrops.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FramingErrors"], ifaceData.InputErrorList.FramingErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputRunts"], ifaceData.InputErrorList.InputRunts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputGiants"], ifaceData.InputErrorList.InputGiants.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputDiscards"], ifaceData.InputErrorList.InputDiscards.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputResourceErrors"], ifaceData.InputErrorList.InputResourceErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputL3Incompletes"], ifaceData.InputErrorList.InputL3Incompletes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputL2ChannelErrors"], ifaceData.InputErrorList.InputL2ChannelErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputL2MismatchTimeouts"], ifaceData.InputErrorList.InputL2MismatchTimeouts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputFifoErrors"], ifaceData.InputErrorList.InputFifoErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["CarrierTransitions"], ifaceData.OutputErrorList.CarrierTransitions.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputErrors"], ifaceData.OutputErrorList.OutputErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputDrops"], ifaceData.OutputErrorList.OutputDrops.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MtuErrors"], ifaceData.OutputErrorList.MtuErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputResourceErrors"], ifaceData.OutputErrorList.OutputResourceErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputCollisions"], ifaceData.OutputErrorList.OutputCollisions.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["AgedPackets"], ifaceData.OutputErrorList.AgedPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["HsLinkCrcErrors"], ifaceData.OutputErrorList.HsLinkCrcErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputFifoErrors"], ifaceData.OutputErrorList.OutputFifoErrors.Text, ifaceLabels...) - newGauge(ch, ifaceDesc["SnmpIndex"], ifaceData.SnmpIndex.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InterfaceFlapped"], ifaceData.InterfaceFlapped.Seconds, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputBytes"], ifaceData.TrafficStatistics.InputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputBytes"], ifaceData.TrafficStatistics.OutputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputPackets"], ifaceData.TrafficStatistics.InputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputPackets"], ifaceData.TrafficStatistics.OutputPackets.Text, ifaceLabels...) + newGauge(logger, ch, ifaceDesc["InputBps"], ifaceData.TrafficStatistics.InputBps.Text, ifaceLabels...) + newGauge(logger, ch, ifaceDesc["OutputBps"], ifaceData.TrafficStatistics.OutputBps.Text, ifaceLabels...) + newGauge(logger, ch, ifaceDesc["InputPps"], ifaceData.TrafficStatistics.InputPps.Text, ifaceLabels...) + newGauge(logger, ch, ifaceDesc["OutputPps"], ifaceData.TrafficStatistics.OutputPps.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["V6InputBytes"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.InputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["V6OutputBytes"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.OutputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["V6InputPackets"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.InputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["V6OutputPackets"], ifaceData.TrafficStatistics.Ipv6TransitStatistics.OutputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputErrors"], ifaceData.InputErrorList.InputErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputDrops"], ifaceData.InputErrorList.InputDrops.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FramingErrors"], ifaceData.InputErrorList.FramingErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputRunts"], ifaceData.InputErrorList.InputRunts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputGiants"], ifaceData.InputErrorList.InputGiants.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputDiscards"], ifaceData.InputErrorList.InputDiscards.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputResourceErrors"], ifaceData.InputErrorList.InputResourceErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputL3Incompletes"], ifaceData.InputErrorList.InputL3Incompletes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputL2ChannelErrors"], ifaceData.InputErrorList.InputL2ChannelErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputL2MismatchTimeouts"], ifaceData.InputErrorList.InputL2MismatchTimeouts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputFifoErrors"], ifaceData.InputErrorList.InputFifoErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["CarrierTransitions"], ifaceData.OutputErrorList.CarrierTransitions.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputErrors"], ifaceData.OutputErrorList.OutputErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputDrops"], ifaceData.OutputErrorList.OutputDrops.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MtuErrors"], ifaceData.OutputErrorList.MtuErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputResourceErrors"], ifaceData.OutputErrorList.OutputResourceErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputCollisions"], ifaceData.OutputErrorList.OutputCollisions.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["AgedPackets"], ifaceData.OutputErrorList.AgedPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["HsLinkCrcErrors"], ifaceData.OutputErrorList.HsLinkCrcErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputFifoErrors"], ifaceData.OutputErrorList.OutputFifoErrors.Text, ifaceLabels...) + newGauge(logger, ch, ifaceDesc["SnmpIndex"], ifaceData.SnmpIndex.Text, ifaceLabels...) for _, logIface := range ifaceData.LogicalInterfaces { logIfaceLabels := []string{strings.TrimSpace(logIface.Name.Text)} var allIfaceDescrKeys map[string]interface{} @@ -331,100 +334,100 @@ func processIfaceNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metr ifaceDescrLabels = append(ifaceDescrLabels, allIfaceDescrKeys[configuredKey].(string)) } } - newCounter(ch, ifaceDesc["InterfaceDescription"], "1", ifaceDescrLabels...) + newCounter(logger, ch, ifaceDesc["InterfaceDescription"], "1", ifaceDescrLabels...) } for _, configuredKey := range ifaceMetricKeys { if allIfaceDescrKeys[configuredKey] != nil { - newCounter(ch, ifaceDesc[configuredKey], strings.TrimSpace(allIfaceDescrKeys[configuredKey].(string)), strings.TrimSpace(logIface.Name.Text)) + newCounter(logger, ch, ifaceDesc[configuredKey], strings.TrimSpace(allIfaceDescrKeys[configuredKey].(string)), strings.TrimSpace(logIface.Name.Text)) } } trafficStatsSource := logIface.TransitTrafficStatistics if logIface.LAGTrafficStatistics.LagBundle.InputBps.Text != "" { trafficStatsSource = logIface.LAGTrafficStatistics.LagBundle } - newCounter(ch, ifaceDesc["InputBytes"], trafficStatsSource.InputBytes.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["OutputBytes"], trafficStatsSource.OutputBytes.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["InputPackets"], trafficStatsSource.InputPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["OutputPackets"], trafficStatsSource.OutputPackets.Text, logIfaceLabels...) - newGauge(ch, ifaceDesc["InputBps"], trafficStatsSource.InputBps.Text, logIfaceLabels...) - newGauge(ch, ifaceDesc["OutputBps"], trafficStatsSource.OutputBps.Text, logIfaceLabels...) - newGauge(ch, ifaceDesc["InputPps"], trafficStatsSource.InputPps.Text, logIfaceLabels...) - newGauge(ch, ifaceDesc["OutputPps"], trafficStatsSource.OutputPps.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["V6InputBytes"], trafficStatsSource.Ipv6TransitStatistics.InputBytes.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["V6OutputBytes"], trafficStatsSource.Ipv6TransitStatistics.OutputBytes.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["V6InputPackets"], trafficStatsSource.Ipv6TransitStatistics.InputPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["V6OutputPackets"], trafficStatsSource.Ipv6TransitStatistics.OutputPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorAddressSpoofing"], logIface.SecurityErrorFlowStatistics.FlowErrorAddressSpoofing.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorAuthenticationFailed"], logIface.SecurityErrorFlowStatistics.FlowErrorAuthenticationFailed.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorIncomingNat"], logIface.SecurityErrorFlowStatistics.FlowErrorIncomingNat.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorInvalidZone"], logIface.SecurityErrorFlowStatistics.FlowErrorInvalidZone.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorMultipleAuth"], logIface.SecurityErrorFlowStatistics.FlowErrorMultipleAuth.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorMultipleIncomingNat"], logIface.SecurityErrorFlowStatistics.FlowErrorMultipleIncomingNat.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoGateParent"], logIface.SecurityErrorFlowStatistics.FlowErrorNoGateParent.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoInterestSelfPacket"], logIface.SecurityErrorFlowStatistics.FlowErrorNoInterestSelfPacket.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoMinorSession"], logIface.SecurityErrorFlowStatistics.FlowErrorNoMinorSession.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoMoreSession"], logIface.SecurityErrorFlowStatistics.FlowErrorNoMoreSession.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoNatGate"], logIface.SecurityErrorFlowStatistics.FlowErrorNoNatGate.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoRoutePresent"], logIface.SecurityErrorFlowStatistics.FlowErrorNoRoutePresent.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoSaForSpi"], logIface.SecurityErrorFlowStatistics.FlowErrorNoSaForSpi.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoTunnel"], logIface.SecurityErrorFlowStatistics.FlowErrorNoTunnel.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNoSessionGate"], logIface.SecurityErrorFlowStatistics.FlowErrorNoSessionGate.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorNullZone"], logIface.SecurityErrorFlowStatistics.FlowErrorNullZone.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorPolicyDenied"], logIface.SecurityErrorFlowStatistics.FlowErrorPolicyDenied.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorSecurityAssociationMissing"], logIface.SecurityErrorFlowStatistics.FlowErrorSecurityAssociationMissing.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorSeqOutsideWindow"], logIface.SecurityErrorFlowStatistics.FlowErrorSeqOutsideWindow.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorSynProtection"], logIface.SecurityErrorFlowStatistics.FlowErrorSynProtection.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowErrorUserAuthentication"], logIface.SecurityErrorFlowStatistics.FlowErrorUserAuthentication.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputSelfPackets"], logIface.SecurityInputFlowStatistics.FlowInputSelfPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputIcmpPackets"], logIface.SecurityInputFlowStatistics.FlowInputIcmpPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputVpnPackets"], logIface.SecurityInputFlowStatistics.FlowInputVpnPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputMulticastPackets"], logIface.SecurityInputFlowStatistics.FlowInputMulticastPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputPolicyBytes"], logIface.SecurityInputFlowStatistics.FlowInputPolicyBytes.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowInputConnections"], logIface.SecurityInputFlowStatistics.FlowInputConnections.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowOutputMulticastPackets"], logIface.SecurityOutputFlowStatistics.FlowOutputMulticastPackets.Text, logIfaceLabels...) - newCounter(ch, ifaceDesc["FlowOutputPolicyBytes"], logIface.SecurityOutputFlowStatistics.FlowOutputPolicyBytes.Text, logIfaceLabels...) - newGauge(ch, ifaceDesc["SnmpIndex"], logIface.SnmpIndex.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["InputBytes"], trafficStatsSource.InputBytes.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputBytes"], trafficStatsSource.OutputBytes.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["InputPackets"], trafficStatsSource.InputPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputPackets"], trafficStatsSource.OutputPackets.Text, logIfaceLabels...) + newGauge(logger, ch, ifaceDesc["InputBps"], trafficStatsSource.InputBps.Text, logIfaceLabels...) + newGauge(logger, ch, ifaceDesc["OutputBps"], trafficStatsSource.OutputBps.Text, logIfaceLabels...) + newGauge(logger, ch, ifaceDesc["InputPps"], trafficStatsSource.InputPps.Text, logIfaceLabels...) + newGauge(logger, ch, ifaceDesc["OutputPps"], trafficStatsSource.OutputPps.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["V6InputBytes"], trafficStatsSource.Ipv6TransitStatistics.InputBytes.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["V6OutputBytes"], trafficStatsSource.Ipv6TransitStatistics.OutputBytes.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["V6InputPackets"], trafficStatsSource.Ipv6TransitStatistics.InputPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["V6OutputPackets"], trafficStatsSource.Ipv6TransitStatistics.OutputPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorAddressSpoofing"], logIface.SecurityErrorFlowStatistics.FlowErrorAddressSpoofing.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorAuthenticationFailed"], logIface.SecurityErrorFlowStatistics.FlowErrorAuthenticationFailed.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorIncomingNat"], logIface.SecurityErrorFlowStatistics.FlowErrorIncomingNat.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorInvalidZone"], logIface.SecurityErrorFlowStatistics.FlowErrorInvalidZone.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorMultipleAuth"], logIface.SecurityErrorFlowStatistics.FlowErrorMultipleAuth.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorMultipleIncomingNat"], logIface.SecurityErrorFlowStatistics.FlowErrorMultipleIncomingNat.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoGateParent"], logIface.SecurityErrorFlowStatistics.FlowErrorNoGateParent.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoInterestSelfPacket"], logIface.SecurityErrorFlowStatistics.FlowErrorNoInterestSelfPacket.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoMinorSession"], logIface.SecurityErrorFlowStatistics.FlowErrorNoMinorSession.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoMoreSession"], logIface.SecurityErrorFlowStatistics.FlowErrorNoMoreSession.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoNatGate"], logIface.SecurityErrorFlowStatistics.FlowErrorNoNatGate.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoRoutePresent"], logIface.SecurityErrorFlowStatistics.FlowErrorNoRoutePresent.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoSaForSpi"], logIface.SecurityErrorFlowStatistics.FlowErrorNoSaForSpi.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoTunnel"], logIface.SecurityErrorFlowStatistics.FlowErrorNoTunnel.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNoSessionGate"], logIface.SecurityErrorFlowStatistics.FlowErrorNoSessionGate.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorNullZone"], logIface.SecurityErrorFlowStatistics.FlowErrorNullZone.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorPolicyDenied"], logIface.SecurityErrorFlowStatistics.FlowErrorPolicyDenied.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorSecurityAssociationMissing"], logIface.SecurityErrorFlowStatistics.FlowErrorSecurityAssociationMissing.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorSeqOutsideWindow"], logIface.SecurityErrorFlowStatistics.FlowErrorSeqOutsideWindow.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorSynProtection"], logIface.SecurityErrorFlowStatistics.FlowErrorSynProtection.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowErrorUserAuthentication"], logIface.SecurityErrorFlowStatistics.FlowErrorUserAuthentication.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputSelfPackets"], logIface.SecurityInputFlowStatistics.FlowInputSelfPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputIcmpPackets"], logIface.SecurityInputFlowStatistics.FlowInputIcmpPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputVpnPackets"], logIface.SecurityInputFlowStatistics.FlowInputVpnPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputMulticastPackets"], logIface.SecurityInputFlowStatistics.FlowInputMulticastPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputPolicyBytes"], logIface.SecurityInputFlowStatistics.FlowInputPolicyBytes.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowInputConnections"], logIface.SecurityInputFlowStatistics.FlowInputConnections.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowOutputMulticastPackets"], logIface.SecurityOutputFlowStatistics.FlowOutputMulticastPackets.Text, logIfaceLabels...) + newCounter(logger, ch, ifaceDesc["FlowOutputPolicyBytes"], logIface.SecurityOutputFlowStatistics.FlowOutputPolicyBytes.Text, logIfaceLabels...) + newGauge(logger, ch, ifaceDesc["SnmpIndex"], logIface.SnmpIndex.Text, logIfaceLabels...) } - newCounter(ch, ifaceDesc["StpInputBytesDropped"], ifaceData.StpTrafficStatistics.StpInputBytesDropped.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["StpOutputBytesDropped"], ifaceData.StpTrafficStatistics.StpOutputBytesDropped.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["StpInputPacketsDropped"], ifaceData.StpTrafficStatistics.StpInputPacketsDropped.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["StpOutputPacketsDropped"], ifaceData.StpTrafficStatistics.StpOutputPacketsDropped.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["BitErrorSeconds"], ifaceData.EthernetPcsStatistics.BitErrorSeconds.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["ErroredBlocksSeconds"], ifaceData.EthernetPcsStatistics.ErroredBlocksSeconds.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputBytes"], ifaceData.EthernetMacStatistics.InputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputBytes"], ifaceData.EthernetMacStatistics.OutputBytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputPackets"], ifaceData.EthernetMacStatistics.InputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputPackets"], ifaceData.EthernetMacStatistics.OutputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputUnicasts"], ifaceData.EthernetMacStatistics.InputUnicasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputUnicasts"], ifaceData.EthernetMacStatistics.OutputUnicasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputBroadcasts"], ifaceData.EthernetMacStatistics.InputBroadcasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputBroadcasts"], ifaceData.EthernetMacStatistics.OutputBroadcasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputMulticasts"], ifaceData.EthernetMacStatistics.InputMulticasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputMulticasts"], ifaceData.EthernetMacStatistics.OutputMulticasts.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputCrcErrors"], ifaceData.EthernetMacStatistics.InputCrcErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputCrcErrors"], ifaceData.EthernetMacStatistics.OutputCrcErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputFifoErrors"], ifaceData.EthernetMacStatistics.InputFifoErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputFifoErrors"], ifaceData.EthernetMacStatistics.OutputFifoErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputMacControlFrames"], ifaceData.EthernetMacStatistics.InputMacControlFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputMacControlFrames"], ifaceData.EthernetMacStatistics.OutputMacControlFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputMacPauseFrames"], ifaceData.EthernetMacStatistics.InputMacPauseFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputMacPauseFrames"], ifaceData.EthernetMacStatistics.OutputMacPauseFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputOversizedFrames"], ifaceData.EthernetMacStatistics.InputOversizedFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputJabberFrames"], ifaceData.EthernetMacStatistics.InputJabberFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputFragmentFrames"], ifaceData.EthernetMacStatistics.InputFragmentFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputVlanTaggedFrames"], ifaceData.EthernetMacStatistics.InputVlanTaggedFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputCodeViolations"], ifaceData.EthernetMacStatistics.InputCodeViolations.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACInputTotalErrors"], ifaceData.EthernetMacStatistics.InputTotalErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MACOutputTotalErrors"], ifaceData.EthernetMacStatistics.OutputTotalErrors.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterInputPackets"], ifaceData.EthernetFilterStatistics.InputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterInputRejectCount"], ifaceData.EthernetFilterStatistics.InputRejectCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterInputRejectDestinationAddressCount"], ifaceData.EthernetFilterStatistics.InputRejectDestinationAddressCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterInputRejectSourceAddressCount"], ifaceData.EthernetFilterStatistics.InputRejectSourceAddressCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterOutputPackets"], ifaceData.EthernetFilterStatistics.OutputPackets.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterOutputPacketPadCount"], ifaceData.EthernetFilterStatistics.OutputPacketPadCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterOutputPacketErrorCount"], ifaceData.EthernetFilterStatistics.OutputPacketErrorCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterCamDestinationFilterCount"], ifaceData.EthernetFilterStatistics.CamDestinationFilterCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FilterCamSourceFilterCount"], ifaceData.EthernetFilterStatistics.CamSourceFilterCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["StpInputBytesDropped"], ifaceData.StpTrafficStatistics.StpInputBytesDropped.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["StpOutputBytesDropped"], ifaceData.StpTrafficStatistics.StpOutputBytesDropped.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["StpInputPacketsDropped"], ifaceData.StpTrafficStatistics.StpInputPacketsDropped.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["StpOutputPacketsDropped"], ifaceData.StpTrafficStatistics.StpOutputPacketsDropped.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["BitErrorSeconds"], ifaceData.EthernetPcsStatistics.BitErrorSeconds.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["ErroredBlocksSeconds"], ifaceData.EthernetPcsStatistics.ErroredBlocksSeconds.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputBytes"], ifaceData.EthernetMacStatistics.InputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputBytes"], ifaceData.EthernetMacStatistics.OutputBytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputPackets"], ifaceData.EthernetMacStatistics.InputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputPackets"], ifaceData.EthernetMacStatistics.OutputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputUnicasts"], ifaceData.EthernetMacStatistics.InputUnicasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputUnicasts"], ifaceData.EthernetMacStatistics.OutputUnicasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputBroadcasts"], ifaceData.EthernetMacStatistics.InputBroadcasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputBroadcasts"], ifaceData.EthernetMacStatistics.OutputBroadcasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputMulticasts"], ifaceData.EthernetMacStatistics.InputMulticasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputMulticasts"], ifaceData.EthernetMacStatistics.OutputMulticasts.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputCrcErrors"], ifaceData.EthernetMacStatistics.InputCrcErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputCrcErrors"], ifaceData.EthernetMacStatistics.OutputCrcErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputFifoErrors"], ifaceData.EthernetMacStatistics.InputFifoErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputFifoErrors"], ifaceData.EthernetMacStatistics.OutputFifoErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputMacControlFrames"], ifaceData.EthernetMacStatistics.InputMacControlFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputMacControlFrames"], ifaceData.EthernetMacStatistics.OutputMacControlFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputMacPauseFrames"], ifaceData.EthernetMacStatistics.InputMacPauseFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputMacPauseFrames"], ifaceData.EthernetMacStatistics.OutputMacPauseFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputOversizedFrames"], ifaceData.EthernetMacStatistics.InputOversizedFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputJabberFrames"], ifaceData.EthernetMacStatistics.InputJabberFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputFragmentFrames"], ifaceData.EthernetMacStatistics.InputFragmentFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputVlanTaggedFrames"], ifaceData.EthernetMacStatistics.InputVlanTaggedFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputCodeViolations"], ifaceData.EthernetMacStatistics.InputCodeViolations.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACInputTotalErrors"], ifaceData.EthernetMacStatistics.InputTotalErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MACOutputTotalErrors"], ifaceData.EthernetMacStatistics.OutputTotalErrors.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterInputPackets"], ifaceData.EthernetFilterStatistics.InputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterInputRejectCount"], ifaceData.EthernetFilterStatistics.InputRejectCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterInputRejectDestinationAddressCount"], ifaceData.EthernetFilterStatistics.InputRejectDestinationAddressCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterInputRejectSourceAddressCount"], ifaceData.EthernetFilterStatistics.InputRejectSourceAddressCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterOutputPackets"], ifaceData.EthernetFilterStatistics.OutputPackets.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterOutputPacketPadCount"], ifaceData.EthernetFilterStatistics.OutputPacketPadCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterOutputPacketErrorCount"], ifaceData.EthernetFilterStatistics.OutputPacketErrorCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterCamDestinationFilterCount"], ifaceData.EthernetFilterStatistics.CamDestinationFilterCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FilterCamSourceFilterCount"], ifaceData.EthernetFilterStatistics.CamSourceFilterCount.Text, ifaceLabels...) // Some devices can have duplicate traffic class names. existingTrafficClasses := make(map[string]int) for _, preclStats := range ifaceData.PreclStatistics.PreclInformation.PreclPerClassStatistics { @@ -436,34 +439,34 @@ func processIfaceNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metr existingTrafficClasses[trafficClass] = 0 } preclLabels := append(ifaceLabels, trafficClass) - newCounter(ch, ifaceDesc["PreclRxPackets"], preclStats.PreclRxPackets.Text, preclLabels...) - newCounter(ch, ifaceDesc["PreclTxPackets"], preclStats.PreclTxPackets.Text, preclLabels...) - newCounter(ch, ifaceDesc["PreclDroppedPackets"], preclStats.PreclDroppedPackets.Text, preclLabels...) + newCounter(logger, ch, ifaceDesc["PreclRxPackets"], preclStats.PreclRxPackets.Text, preclLabels...) + newCounter(logger, ch, ifaceDesc["PreclTxPackets"], preclStats.PreclTxPackets.Text, preclLabels...) + newCounter(logger, ch, ifaceDesc["PreclDroppedPackets"], preclStats.PreclDroppedPackets.Text, preclLabels...) } - newCounter(ch, ifaceDesc["FecCcwCount"], ifaceData.EthernetFecStatistics.FecCcwCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FecNccwCount"], ifaceData.EthernetFecStatistics.FecNccwCount.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FecCcwErrorRate"], ifaceData.EthernetFecStatistics.FecCcwErrorRate.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FecNccwErrorRate"], ifaceData.EthernetFecStatistics.FecNccwErrorRate.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecTxScProtected"], ifaceData.MacsecStatistics.MacsecTxScProtected.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecTxScEncrypted"], ifaceData.MacsecStatistics.MacsecTxScEncrypted.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecTxScProtectedbytes"], ifaceData.MacsecStatistics.MacsecTxScProtectedbytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecTxScEncryptedbytes"], ifaceData.MacsecStatistics.MacsecTxScEncryptedbytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecRxScOk"], ifaceData.MacsecStatistics.MacsecRxScOk.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecRxScValidatedbytes"], ifaceData.MacsecStatistics.MacsecRxScValidatedbytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["MacsecRxScDecryptedbytes"], ifaceData.MacsecStatistics.MacsecRxScDecryptedbytes.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OversizedFrames"], ifaceData.MultilinkInterfaceErrors.OversizedFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputErrorFrames"], ifaceData.MultilinkInterfaceErrors.InputErrorFrames.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["InputDisabledBundle"], ifaceData.MultilinkInterfaceErrors.InputDisabledBundle.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutputDisabledBundle"], ifaceData.MultilinkInterfaceErrors.OutputDisabledBundle.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["QueuingDrops"], ifaceData.MultilinkInterfaceErrors.QueuingDrops.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["PacketBufferOverflow"], ifaceData.MultilinkInterfaceErrors.PacketBufferOverflow.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FragmentBufferOverflow"], ifaceData.MultilinkInterfaceErrors.FragmentBufferOverflow.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["FragmentTimeout"], ifaceData.MultilinkInterfaceErrors.FragmentTimeout.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["SequenceNumberMissing"], ifaceData.MultilinkInterfaceErrors.SequenceNumberMissing.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutOfOrderSequenceNumber"], ifaceData.MultilinkInterfaceErrors.OutOfOrderSequenceNumber.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["OutOfRangeSequenceNumber"], ifaceData.MultilinkInterfaceErrors.OutOfRangeSequenceNumber.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["DataMemoryError"], ifaceData.MultilinkInterfaceErrors.DataMemoryError.Text, ifaceLabels...) - newCounter(ch, ifaceDesc["ControlMemoryError"], ifaceData.MultilinkInterfaceErrors.ControlMemoryError.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FecCcwCount"], ifaceData.EthernetFecStatistics.FecCcwCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FecNccwCount"], ifaceData.EthernetFecStatistics.FecNccwCount.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FecCcwErrorRate"], ifaceData.EthernetFecStatistics.FecCcwErrorRate.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FecNccwErrorRate"], ifaceData.EthernetFecStatistics.FecNccwErrorRate.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecTxScProtected"], ifaceData.MacsecStatistics.MacsecTxScProtected.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecTxScEncrypted"], ifaceData.MacsecStatistics.MacsecTxScEncrypted.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecTxScProtectedbytes"], ifaceData.MacsecStatistics.MacsecTxScProtectedbytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecTxScEncryptedbytes"], ifaceData.MacsecStatistics.MacsecTxScEncryptedbytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecRxScOk"], ifaceData.MacsecStatistics.MacsecRxScOk.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecRxScValidatedbytes"], ifaceData.MacsecStatistics.MacsecRxScValidatedbytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["MacsecRxScDecryptedbytes"], ifaceData.MacsecStatistics.MacsecRxScDecryptedbytes.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OversizedFrames"], ifaceData.MultilinkInterfaceErrors.OversizedFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputErrorFrames"], ifaceData.MultilinkInterfaceErrors.InputErrorFrames.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["InputDisabledBundle"], ifaceData.MultilinkInterfaceErrors.InputDisabledBundle.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutputDisabledBundle"], ifaceData.MultilinkInterfaceErrors.OutputDisabledBundle.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["QueuingDrops"], ifaceData.MultilinkInterfaceErrors.QueuingDrops.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["PacketBufferOverflow"], ifaceData.MultilinkInterfaceErrors.PacketBufferOverflow.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FragmentBufferOverflow"], ifaceData.MultilinkInterfaceErrors.FragmentBufferOverflow.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["FragmentTimeout"], ifaceData.MultilinkInterfaceErrors.FragmentTimeout.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["SequenceNumberMissing"], ifaceData.MultilinkInterfaceErrors.SequenceNumberMissing.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutOfOrderSequenceNumber"], ifaceData.MultilinkInterfaceErrors.OutOfOrderSequenceNumber.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["OutOfRangeSequenceNumber"], ifaceData.MultilinkInterfaceErrors.OutOfRangeSequenceNumber.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["DataMemoryError"], ifaceData.MultilinkInterfaceErrors.DataMemoryError.Text, ifaceLabels...) + newCounter(logger, ch, ifaceDesc["ControlMemoryError"], ifaceData.MultilinkInterfaceErrors.ControlMemoryError.Text, ifaceLabels...) } return nil } diff --git a/collector/ipsec.go b/collector/ipsec.go index c6ffef0..a2fbfbf 100644 --- a/collector/ipsec.go +++ b/collector/ipsec.go @@ -4,26 +4,30 @@ import ( "encoding/xml" "fmt" "strings" + "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) var ( ipsecSubsystem = "ipsec" - totalIpsecErrors = 0.0 + totalIpsecErrors = 0.0 - ipsecLabels = map[string][]string{"TunnelInformation": []string{"saremotegateway", "satunnelindex"}} + ipsecLabels = map[string][]string{"TunnelInformation": []string{"saremotegateway", "satunnelindex"}} ipsecDesc = map[string]*prometheus.Desc{ - "TunnelStatusUp": colPromDesc(ipsecSubsystem, "tunnel_status_up", "Tunnel Status (1 UP, 0 DOWN)", ipsecLabels["TunnelInformation"]), + "TunnelStatusUp": colPromDesc(ipsecSubsystem, "tunnel_status_up", "Tunnel Status (1 UP, 0 DOWN)", ipsecLabels["TunnelInformation"]), } ) // EnvCollector collects environment metrics, implemented as per the Collector interface. -type IpsecCollector struct{} +type IpsecCollector struct { + logger log.Logger +} // NewEnvCollector returns a new EnvCollector. -func NewIpsecCollector() *IpsecCollector { - return &IpsecCollector{} +func NewIpsecCollector(logger log.Logger) *IpsecCollector { + return &IpsecCollector{logger: logger} } // Name of the collector. @@ -42,7 +46,7 @@ func (c *IpsecCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, } defer s.Close() - // IPsec inactive tunnels + // IPsec inactive tunnels reply, err := s.Exec(netconf.RawMethod(``)) if err != nil { totalIpsecErrors++ @@ -55,7 +59,7 @@ func (c *IpsecCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, errors = append(errors, err) } - // IPsec active tunnels + // IPsec active tunnels reply, err = s.Exec(netconf.RawMethod(``)) if err != nil { totalIpsecErrors++ @@ -78,15 +82,15 @@ func processIpsecInactiveNetconfReply(reply *netconf.RPCReply, ch chan<- prometh return fmt.Errorf("could not unmarshal netconf inactive tunnel reply xml: %s", err) } - // Send tunnel status of inactive tunnels to Prometheus channel. - // Set tunnel_status_up to 0 - for _, ipsecData := range netconfInactiveTunnelReply.IpsecUnestablishedTunnelInformation.IpsecSecurityAssociationsBlock { - saRemoteGateway := strings.Trim(ipsecData.IpsecSecurityAssociations.SaRemoteGateway, "\n") - saTunnelIndex := strings.Trim(ipsecData.IpsecSecurityAssociations.SaTunnelIndex, "\n") - ch <- prometheus.MustNewConstMetric(ipsecDesc["TunnelStatusUp"], prometheus.GaugeValue, 0, saRemoteGateway, saTunnelIndex) - } + // Send tunnel status of inactive tunnels to Prometheus channel. + // Set tunnel_status_up to 0 + for _, ipsecData := range netconfInactiveTunnelReply.IpsecUnestablishedTunnelInformation.IpsecSecurityAssociationsBlock { + saRemoteGateway := strings.Trim(ipsecData.IpsecSecurityAssociations.SaRemoteGateway, "\n") + saTunnelIndex := strings.Trim(ipsecData.IpsecSecurityAssociations.SaTunnelIndex, "\n") + ch <- prometheus.MustNewConstMetric(ipsecDesc["TunnelStatusUp"], prometheus.GaugeValue, 0, saRemoteGateway, saTunnelIndex) + } - return nil + return nil } // Process active ipsec SAs. @@ -97,15 +101,15 @@ func processIpsecActiveNetconfReply(reply *netconf.RPCReply, ch chan<- prometheu return fmt.Errorf("could not unmarshal netconf active tunnel reply xml: %s", err) } - // Send tunnel status of active tunnels to Prometheus channel. - // Set tunnel_status_up to 1 - for _, ipsecData := range netconfActiveTunnelReply.IpsecSecurityAssociationsInformation.IpsecSecurityAssociationsBlock { - saRemoteGateway := strings.Trim(ipsecData.IpsecSecurityAssociations.SaRemoteGateway, "\n") - saTunnelIndex := strings.Trim(ipsecData.IpsecSecurityAssociations.SaTunnelIndex, "\n") - ch <- prometheus.MustNewConstMetric(ipsecDesc["TunnelStatusUp"], prometheus.GaugeValue, 1, saRemoteGateway, saTunnelIndex) - } + // Send tunnel status of active tunnels to Prometheus channel. + // Set tunnel_status_up to 1 + for _, ipsecData := range netconfActiveTunnelReply.IpsecSecurityAssociationsInformation.IpsecSecurityAssociationsBlock { + saRemoteGateway := strings.Trim(ipsecData.IpsecSecurityAssociations.SaRemoteGateway, "\n") + saTunnelIndex := strings.Trim(ipsecData.IpsecSecurityAssociations.SaTunnelIndex, "\n") + ch <- prometheus.MustNewConstMetric(ipsecDesc["TunnelStatusUp"], prometheus.GaugeValue, 1, saRemoteGateway, saTunnelIndex) + } - return nil + return nil } type InactiveTunnelReply struct { @@ -132,7 +136,7 @@ type InactiveTunnelReply struct { } `xml:"ipsec-security-associations"` } `xml:"ipsec-security-associations-block"` } `xml:"ipsec-unestablished-tunnel-information"` -} +} type ActiveTunnelReply struct { XMLName xml.Name `xml:"rpc-reply"` @@ -167,4 +171,4 @@ type ActiveTunnelReply struct { Text string `xml:",chardata"` Banner string `xml:"banner"` } `xml:"cli"` -} +} diff --git a/collector/optics.go b/collector/optics.go index 3f2e868..d13ae56 100644 --- a/collector/optics.go +++ b/collector/optics.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -81,11 +82,13 @@ var ( ) // OpticsCollector collects power metrics, implemented as per the Collector interface. -type OpticsCollector struct{} +type OpticsCollector struct { + logger log.Logger +} // NewOpticsCollector returns a new OpticsCollector . -func NewOpticsCollector() *OpticsCollector { - return &OpticsCollector{} +func NewOpticsCollector(logger log.Logger) *OpticsCollector { + return &OpticsCollector{logger: logger} } // Name of the collector. @@ -111,14 +114,14 @@ func (c *OpticsCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error return errors, totalOpticsErrors } - if err := processOpticsNetconfReply(reply, ch); err != nil { + if err := processOpticsNetconfReply(reply, ch, c.logger); err != nil { totalOpticsErrors++ errors = append(errors, err) } return errors, totalOpticsErrors } -func processOpticsNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) error { +func processOpticsNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, logger log.Logger) error { var netconfReply opticsRPCReply if err := xml.Unmarshal([]byte(reply.RawReply), &netconfReply); err != nil { @@ -128,8 +131,8 @@ func processOpticsNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Met labels := []string{strings.TrimSpace(opticsData.Name.Text)} opticsLaserNoLight := -40.0 - newGauge(ch, opticsDesc["ModuleTemperature"], opticsData.OpticsDiagnostics.ModuleTemperature.Temp, labels...) - newGauge(ch, opticsDesc["ModuleVoltage"], opticsData.OpticsDiagnostics.ModuleVoltage.Text, labels...) + newGauge(logger, ch, opticsDesc["ModuleTemperature"], opticsData.OpticsDiagnostics.ModuleTemperature.Temp, labels...) + newGauge(logger, ch, opticsDesc["ModuleVoltage"], opticsData.OpticsDiagnostics.ModuleVoltage.Text, labels...) opticsTempHighAlarm := 0.0 if opticsData.OpticsDiagnostics.ModuleTemperatureHighAlarm.Text == "off" { @@ -179,69 +182,69 @@ func processOpticsNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Met } ch <- prometheus.MustNewConstMetric(opticsDesc["ModuleVoltageLowWarn"], prometheus.GaugeValue, opticsVoltageLowWarn, labels...) - newGauge(ch, opticsDesc["ModuleTemperatureHighAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureHighAlarmThreshold.Temp, labels...) - newGauge(ch, opticsDesc["ModuleTemperatureLowAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureLowAlarmThreshold.Temp, labels...) - newGauge(ch, opticsDesc["ModuleTemperatureHighWarnThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureHighWarnThreshold.Temp, labels...) - newGauge(ch, opticsDesc["ModuleTemperatureLowWarnThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureLowWarnThreshold.Temp, labels...) - newGauge(ch, opticsDesc["ModuleVoltageHighAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageHighAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["ModuleVoltageLowAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageLowAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["ModuleVoltageHighWarnThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageHighWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["ModuleVoltageLowWarnThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageLowWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserBiasCurrentHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentHighAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserBiasCurrentLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentLowAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserBiasCurrentHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentHighWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserBiasCurrentLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentLowWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerHighAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerHighAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerHighAlarmThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerLowAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerLowAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerLowAlarmThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerHighWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerHighWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerHighWarnThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerLowWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserTxPowerLowWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerLowWarnThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerHighAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerHighAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerHighAlarmThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerLowAlarmThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerLowAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerLowAlarmThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerHighWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerHighWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerHighWarnThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerLowWarnThreshold.Text, labels...) - newGauge(ch, opticsDesc["LaserRxPowerLowWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerLowWarnThresholdDbm.Text, labels...) - newGauge(ch, opticsDesc["NonChannelizedLaserBiasCurrent"], opticsData.OpticsDiagnostics.NonChannelizedLaserBiasCurrent.Text, labels...) - newGauge(ch, opticsDesc["NonChannelizedLaserOutputPower"], opticsData.OpticsDiagnostics.NonChannelizedLaserOutputPower.Text, labels...) - newGauge(ch, opticsDesc["NonChannelizedRxSignalAvgOpticalPower"], opticsData.OpticsDiagnostics.NonChannelizedRxSignalAvgOpticalPower.Text, labels...) + newGauge(logger, ch, opticsDesc["ModuleTemperatureHighAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureHighAlarmThreshold.Temp, labels...) + newGauge(logger, ch, opticsDesc["ModuleTemperatureLowAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureLowAlarmThreshold.Temp, labels...) + newGauge(logger, ch, opticsDesc["ModuleTemperatureHighWarnThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureHighWarnThreshold.Temp, labels...) + newGauge(logger, ch, opticsDesc["ModuleTemperatureLowWarnThreshold"], opticsData.OpticsDiagnostics.ModuleTemperatureLowWarnThreshold.Temp, labels...) + newGauge(logger, ch, opticsDesc["ModuleVoltageHighAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageHighAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["ModuleVoltageLowAlarmThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageLowAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["ModuleVoltageHighWarnThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageHighWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["ModuleVoltageLowWarnThreshold"], opticsData.OpticsDiagnostics.ModuleVoltageLowWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserBiasCurrentHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentHighAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserBiasCurrentLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentLowAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserBiasCurrentHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentHighWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserBiasCurrentLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserBiasCurrentLowWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerHighAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerHighAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerHighAlarmThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerLowAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerLowAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerLowAlarmThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerHighWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerHighWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerHighWarnThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserTxPowerLowWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserTxPowerLowWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserTxPowerLowWarnThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerHighAlarmThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerHighAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerHighAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerHighAlarmThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerLowAlarmThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerLowAlarmThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerLowAlarmThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerLowAlarmThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerHighWarnThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerHighWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerHighWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerHighWarnThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerLowWarnThreshold"], opticsData.OpticsDiagnostics.LaserRxPowerLowWarnThreshold.Text, labels...) + newGauge(logger, ch, opticsDesc["LaserRxPowerLowWarnThresholdDbm"], opticsData.OpticsDiagnostics.LaserRxPowerLowWarnThresholdDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["NonChannelizedLaserBiasCurrent"], opticsData.OpticsDiagnostics.NonChannelizedLaserBiasCurrent.Text, labels...) + newGauge(logger, ch, opticsDesc["NonChannelizedLaserOutputPower"], opticsData.OpticsDiagnostics.NonChannelizedLaserOutputPower.Text, labels...) + newGauge(logger, ch, opticsDesc["NonChannelizedRxSignalAvgOpticalPower"], opticsData.OpticsDiagnostics.NonChannelizedRxSignalAvgOpticalPower.Text, labels...) if strings.TrimSpace(opticsData.OpticsDiagnostics.NonChannelizedLaserOutputPowerDbm.Text) == "- Inf" { ch <- prometheus.MustNewConstMetric(opticsDesc["NonChannelizedLaserOutputPowerDbm"], prometheus.GaugeValue, opticsLaserNoLight, labels...) } else { - newGauge(ch, opticsDesc["NonChannelizedLaserOutputPowerDbm"], opticsData.OpticsDiagnostics.NonChannelizedLaserOutputPowerDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["NonChannelizedLaserOutputPowerDbm"], opticsData.OpticsDiagnostics.NonChannelizedLaserOutputPowerDbm.Text, labels...) } if strings.TrimSpace(opticsData.OpticsDiagnostics.NonChannelizedRxSignalAvgOpticalPowerDbm.Text) == "- Inf" { ch <- prometheus.MustNewConstMetric(opticsDesc["NonChannelizedRxSignalAvgOpticalPowerDbm"], prometheus.GaugeValue, opticsLaserNoLight, labels...) } else { - newGauge(ch, opticsDesc["NonChannelizedRxSignalAvgOpticalPowerDbm"], opticsData.OpticsDiagnostics.NonChannelizedRxSignalAvgOpticalPowerDbm.Text, labels...) + newGauge(logger, ch, opticsDesc["NonChannelizedRxSignalAvgOpticalPowerDbm"], opticsData.OpticsDiagnostics.NonChannelizedRxSignalAvgOpticalPowerDbm.Text, labels...) } for _, lane := range opticsData.OpticsDiagnostics.OpticsDiagLanes { laneIndex := strings.TrimSpace(lane.LaneIndex.Text) laneLabels := append(labels, laneIndex) - newGauge(ch, opticsDesc["LaneIndex"], lane.LaneIndex.Text, laneLabels...) - newGauge(ch, opticsDesc["LaserBiasCurrent"], lane.LaserBiasCurrent.Text, laneLabels...) - newGauge(ch, opticsDesc["LaserOutputPower"], lane.LaserOutputPower.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaneIndex"], lane.LaneIndex.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaserBiasCurrent"], lane.LaserBiasCurrent.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaserOutputPower"], lane.LaserOutputPower.Text, laneLabels...) if strings.TrimSpace(lane.LaserOutputPowerDbm.Text) == "- Inf" { ch <- prometheus.MustNewConstMetric(opticsDesc["LaserOutputPowerDbm"], prometheus.GaugeValue, opticsLaserNoLight, laneLabels...) } else { - newGauge(ch, opticsDesc["LaserOutputPowerDbm"], lane.LaserOutputPowerDbm.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaserOutputPowerDbm"], lane.LaserOutputPowerDbm.Text, laneLabels...) } - newGauge(ch, opticsDesc["LaserRxOpticalPower"], lane.LaserRxOpticalPower.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaserRxOpticalPower"], lane.LaserRxOpticalPower.Text, laneLabels...) if strings.TrimSpace(lane.LaserRxOpticalPowerDbm.Text) == "- Inf" { ch <- prometheus.MustNewConstMetric(opticsDesc["LaserRxOpticalPowerDbm"], prometheus.GaugeValue, opticsLaserNoLight, laneLabels...) } else { - newGauge(ch, opticsDesc["LaserRxOpticalPowerDbm"], lane.LaserRxOpticalPowerDbm.Text, laneLabels...) + newGauge(logger, ch, opticsDesc["LaserRxOpticalPowerDbm"], lane.LaserRxOpticalPowerDbm.Text, laneLabels...) } opticLaneLaserBiasCurrentHighAlarm := 0.0 diff --git a/collector/ospf.go b/collector/ospf.go index 8f987e1..3520f3a 100644 --- a/collector/ospf.go +++ b/collector/ospf.go @@ -3,26 +3,30 @@ package collector import ( "encoding/xml" "fmt" + "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) var ( - ospfSubsystem = "ospf" - totalOSPFErrors = 0.0 + ospfSubsystem = "ospf" + totalOSPFErrors = 0.0 - ospfPeerLabels = []string{"neighbor_address", "neighbor_id", "local_interface"} - ospfDesc = map[string]*prometheus.Desc{ - "NeighborStatus": colPromDesc(ospfSubsystem, "neighbot_status", "OSPF Neighbor Status", ospfPeerLabels), + ospfPeerLabels = []string{"neighbor_address", "neighbor_id", "local_interface"} + ospfDesc = map[string]*prometheus.Desc{ + "NeighborStatus": colPromDesc(ospfSubsystem, "neighbot_status", "OSPF Neighbor Status", ospfPeerLabels), } ) // EnvCollector collects environment metrics, implemented as per the Collector interface. -type OSPFCollector struct{} +type OSPFCollector struct { + logger log.Logger +} // NewEnvCollector returns a new EnvCollector. -func NewOSPFCollector() *OSPFCollector { - return &OSPFCollector{} +func NewOSPFCollector(logger log.Logger) *OSPFCollector { + return &OSPFCollector{logger: logger} } // Name of the collector. @@ -41,7 +45,7 @@ func (c *OSPFCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, } defer s.Close() - // show ospf neighbor | display xml + // show ospf neighbor | display xml reply, err := s.Exec(netconf.RawMethod(``)) if err != nil { totalOSPFErrors++ @@ -49,50 +53,49 @@ func (c *OSPFCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, return errors, totalOSPFErrors } - if err := processOSPFNetconfReply(reply, ch); err != nil { - totalOSPFErrors++ - errors = append(errors, err) - } + if err := processOSPFNetconfReply(reply, ch); err != nil { + totalOSPFErrors++ + errors = append(errors, err) + } return errors, totalOSPFErrors } func processOSPFNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) error { - ospfNbrStatus := 0.0 - var netconfReply ospfNeighborRPCReply - if err := xml.Unmarshal([]byte(reply.RawReply), &netconfReply); err != nil { - return fmt.Errorf("could not unmarshal netconf ospf neighbor reply: %s", err) - } - for _, neighbor := range netconfReply.OSPFNbrInformation.OSPFNeighbor { - ospfNbrStatus = 0.0 - ospfPeerLabels := []string{ - neighbor.NeighborAddress, - neighbor.NeighborId, - neighbor.InterfaceName, - } - if neighbor.OSPFNeighborState == "Full" { - ospfNbrStatus = 1.0 - } - ch <- prometheus.MustNewConstMetric(ospfDesc["NeighborStatus"], prometheus.GaugeValue, ospfNbrStatus, ospfPeerLabels...) - } - return nil + ospfNbrStatus := 0.0 + var netconfReply ospfNeighborRPCReply + if err := xml.Unmarshal([]byte(reply.RawReply), &netconfReply); err != nil { + return fmt.Errorf("could not unmarshal netconf ospf neighbor reply: %s", err) + } + for _, neighbor := range netconfReply.OSPFNbrInformation.OSPFNeighbor { + ospfNbrStatus = 0.0 + ospfPeerLabels := []string{ + neighbor.NeighborAddress, + neighbor.NeighborId, + neighbor.InterfaceName, + } + if neighbor.OSPFNeighborState == "Full" { + ospfNbrStatus = 1.0 + } + ch <- prometheus.MustNewConstMetric(ospfDesc["NeighborStatus"], prometheus.GaugeValue, ospfNbrStatus, ospfPeerLabels...) + } + return nil } type ospfNeighborRPCReply struct { - XMLName xml.Name `xml:"rpc-reply"` - Xmlns string `xml:"xmlns,attr"` - OSPFNbrInformation ospfNbrInformation `xml:"ospf-neighbor-information"` + XMLName xml.Name `xml:"rpc-reply"` + Xmlns string `xml:"xmlns,attr"` + OSPFNbrInformation ospfNbrInformation `xml:"ospf-neighbor-information"` } type ospfNbrInformation struct { - OSPFNeighbor []ospfNeighbor `xml:"ospf-neighbor"` + OSPFNeighbor []ospfNeighbor `xml:"ospf-neighbor"` } type ospfNeighbor struct { - NeighborAddress string `xml:"neighbor-address"` - InterfaceName string `xml:"interface-name"` - OSPFNeighborState string `xml:"ospf-neighbor-state"` - NeighborId string `xml:"neighbor-id"` - NeighborPriority string `xml:"neighbor-priority"` - ActivityTimer string `xml:"activity-timer"` + NeighborAddress string `xml:"neighbor-address"` + InterfaceName string `xml:"interface-name"` + OSPFNeighborState string `xml:"ospf-neighbor-state"` + NeighborId string `xml:"neighbor-id"` + NeighborPriority string `xml:"neighbor-priority"` + ActivityTimer string `xml:"activity-timer"` } - diff --git a/collector/power.go b/collector/power.go index fe90c5e..5fdcfb4 100644 --- a/collector/power.go +++ b/collector/power.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -41,11 +42,13 @@ var ( ) // PowerCollector collects power metrics, implemented as per the Collector interface. -type PowerCollector struct{} +type PowerCollector struct { + logger log.Logger +} // NewPowerCollector returns a new PowerCollector . -func NewPowerCollector() *PowerCollector { - return &PowerCollector{} +func NewPowerCollector(logger log.Logger) *PowerCollector { + return &PowerCollector{logger: logger} } // Name of the collector. @@ -71,14 +74,14 @@ func (c *PowerCollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, return errors, totalPowerErrors } - if err := processPowerNetconfReply(reply, ch); err != nil { + if err := processPowerNetconfReply(reply, ch, c.logger); err != nil { totalPowerErrors++ errors = append(errors, err) } return errors, totalPowerErrors } -func processPowerNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) error { +func processPowerNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, logger log.Logger) error { var netconfReply powerRPCReply if err := xml.Unmarshal([]byte(reply.RawReply), &netconfReply); err != nil { @@ -92,38 +95,38 @@ func processPowerNetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metr powerState = 1.0 } ch <- prometheus.MustNewConstMetric(powerDesc["State"], prometheus.GaugeValue, powerState, labels...) - newGauge(ch, powerDesc["CapacityActual"], powerData.PemCapacityDetail.CapacityActual.Text, labels...) - newGauge(ch, powerDesc["CapacityMax"], powerData.PemCapacityDetail.CapacityMax.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityActual"], powerData.PemCapacityDetail.CapacityActual.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityMax"], powerData.PemCapacityDetail.CapacityMax.Text, labels...) powerACInputState := 0.0 if powerData.AcInputDetail.AcInput.Text == "OK" { powerACInputState = 1.0 } ch <- prometheus.MustNewConstMetric(powerDesc["ACInputState"], prometheus.GaugeValue, powerACInputState, labels...) - newGauge(ch, powerDesc["ACExpectedFeeds"], powerData.AcInputDetail.AcExpectFeed.Text, labels...) - newGauge(ch, powerDesc["ACConnectedFeeds"], powerData.AcInputDetail.AcActualFeed.Text, labels...) + newGauge(logger, ch, powerDesc["ACExpectedFeeds"], powerData.AcInputDetail.AcExpectFeed.Text, labels...) + newGauge(logger, ch, powerDesc["ACConnectedFeeds"], powerData.AcInputDetail.AcActualFeed.Text, labels...) labelsDCOutput := []string{strings.TrimSpace(powerData.Name.Text), strings.TrimSpace(powerData.DcOutputDetail.Zone.Text)} - newGauge(ch, powerDesc["DCOutputPower"], powerData.DcOutputDetail.DcPower.Text, labelsDCOutput...) - newGauge(ch, powerDesc["DCOutputCurrent"], powerData.DcOutputDetail.DcCurrent.Text, labelsDCOutput...) - newGauge(ch, powerDesc["DCOutputVoltage"], powerData.DcOutputDetail.DcVoltage.Text, labelsDCOutput...) - newGauge(ch, powerDesc["DCOutputLoad"], powerData.DcOutputDetail.DcLoad.Text, labelsDCOutput...) + newGauge(logger, ch, powerDesc["DCOutputPower"], powerData.DcOutputDetail.DcPower.Text, labelsDCOutput...) + newGauge(logger, ch, powerDesc["DCOutputCurrent"], powerData.DcOutputDetail.DcCurrent.Text, labelsDCOutput...) + newGauge(logger, ch, powerDesc["DCOutputVoltage"], powerData.DcOutputDetail.DcVoltage.Text, labelsDCOutput...) + newGauge(logger, ch, powerDesc["DCOutputLoad"], powerData.DcOutputDetail.DcLoad.Text, labelsDCOutput...) } for _, powerSystem := range netconfReply.PowerUsageInformation.PowerUsageSystem { for _, zone := range powerSystem.PowerUsageZoneInformation { labels := []string{strings.TrimSpace(zone.Zone.Text)} - newGauge(ch, powerDesc["CapacityZoneActual"], zone.CapacityActual.Text, labels...) - newGauge(ch, powerDesc["CapacityZoneMax"], zone.CapacityMax.Text, labels...) - newGauge(ch, powerDesc["CapacityZoneAllocated"], zone.CapacityAllocated.Text, labels...) - newGauge(ch, powerDesc["CapacityZoneRemaining"], zone.CapacityRemaining.Text, labels...) - newGauge(ch, powerDesc["CapacityZoneUsage"], zone.CapacityActualUsage.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityZoneActual"], zone.CapacityActual.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityZoneMax"], zone.CapacityMax.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityZoneAllocated"], zone.CapacityAllocated.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityZoneRemaining"], zone.CapacityRemaining.Text, labels...) + newGauge(logger, ch, powerDesc["CapacityZoneUsage"], zone.CapacityActualUsage.Text, labels...) } - newGauge(ch, powerDesc["CapacitySysActual"], powerSystem.CapacitySysActual.Text) - newGauge(ch, powerDesc["CapacitySysMax"], powerSystem.CapacitySysMax.Text) - newGauge(ch, powerDesc["CapacitySysRemaining"], powerSystem.CapacitySysRemaining.Text) + newGauge(logger, ch, powerDesc["CapacitySysActual"], powerSystem.CapacitySysActual.Text) + newGauge(logger, ch, powerDesc["CapacitySysMax"], powerSystem.CapacitySysMax.Text) + newGauge(logger, ch, powerDesc["CapacitySysRemaining"], powerSystem.CapacitySysRemaining.Text) } for _, fruItem := range netconfReply.PowerUsageInformation.PowerUsageFruItem { - newGauge(ch, powerDesc["DCUsage"], fruItem.DcPower.Text, fruItem.Name.Text) + newGauge(logger, ch, powerDesc["DCUsage"], fruItem.DcPower.Text, fruItem.Name.Text) } return nil } diff --git a/collector/route_engine.go b/collector/route_engine.go index 4e6d225..f98728a 100644 --- a/collector/route_engine.go +++ b/collector/route_engine.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/go-netconf/netconf" + "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -48,11 +49,13 @@ func getREDesc() (map[string]*prometheus.Desc, map[string]*prometheus.Desc) { } // RECollector collects route engine metrics, implemented as per the Collector interface. -type RECollector struct{} +type RECollector struct { + logger log.Logger +} // NewRECollector returns a new RECollector. -func NewRECollector() *RECollector { - return &RECollector{} +func NewRECollector(logger log.Logger) *RECollector { + return &RECollector{logger: logger} } // Name of the collector. @@ -78,14 +81,14 @@ func (c *RECollector) Get(ch chan<- prometheus.Metric, conf Config) ([]error, fl return errors, totalREErrors } - if err := processRENetconfReply(reply, ch); err != nil { + if err := processRENetconfReply(reply, ch, c.logger); err != nil { totalREErrors++ errors = append(errors, err) } return errors, totalREErrors } -func processRENetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) error { +func processRENetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric, logger log.Logger) error { var netconfReply reRPCReply reDesc, multiREDesc := getREDesc() @@ -102,7 +105,7 @@ func processRENetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) labels = []string{reData.Slot.Text} } labels = append(labels, re.REName) - sendREMetrics(ch, multiREDesc, labels, reData) + sendREMetrics(ch, multiREDesc, labels, reData, logger) } } return nil @@ -114,12 +117,12 @@ func processRENetconfReply(reply *netconf.RPCReply, ch chan<- prometheus.Metric) if reData.Slot.Text != "" { labels = []string{reData.Slot.Text} } - sendREMetrics(ch, reDesc, labels, reData) + sendREMetrics(ch, reDesc, labels, reData, logger) } return nil } -func sendREMetrics(ch chan<- prometheus.Metric, reDesc map[string]*prometheus.Desc, labels []string, reData reEntry) { +func sendREMetrics(ch chan<- prometheus.Metric, reDesc map[string]*prometheus.Desc, labels []string, reData reEntry, logger log.Logger) { state := 0.0 if strings.ToLower(reData.Status.Text) == "ok" { @@ -127,46 +130,46 @@ func sendREMetrics(ch chan<- prometheus.Metric, reDesc map[string]*prometheus.De } ch <- prometheus.MustNewConstMetric(reDesc["state"], prometheus.GaugeValue, state, labels...) - newGauge(ch, reDesc["temp"], reData.Temperature.Temp, labels...) - newGauge(ch, reDesc["cpuTemp"], reData.CPUTemperature.Temp, labels...) - newGauge(ch, reDesc["uptime"], reData.UpTime.Seconds, labels...) + newGauge(logger, ch, reDesc["temp"], reData.Temperature.Temp, labels...) + newGauge(logger, ch, reDesc["cpuTemp"], reData.CPUTemperature.Temp, labels...) + newGauge(logger, ch, reDesc["uptime"], reData.UpTime.Seconds, labels...) - newGaugeMB(ch, reDesc["memTotal"], reData.MemorySystemTotal.Text, labels...) - newGaugeMB(ch, reDesc["memUsed"], reData.MemorySystemTotalUsed.Text, labels...) - newGauge(ch, reDesc["memBuf"], reData.MemoryBufferUtilization.Text, labels...) - newGaugeMB(ch, reDesc["memDRAM"], reData.MemoryDRAMSize.Text, labels...) - newGaugeMB(ch, reDesc["memInstalled"], reData.MemoryInstalledSize.Text, labels...) + newGaugeMB(logger, ch, reDesc["memTotal"], reData.MemorySystemTotal.Text, labels...) + newGaugeMB(logger, ch, reDesc["memUsed"], reData.MemorySystemTotalUsed.Text, labels...) + newGauge(logger, ch, reDesc["memBuf"], reData.MemoryBufferUtilization.Text, labels...) + newGaugeMB(logger, ch, reDesc["memDRAM"], reData.MemoryDRAMSize.Text, labels...) + newGaugeMB(logger, ch, reDesc["memInstalled"], reData.MemoryInstalledSize.Text, labels...) label5s := append(labels, "5s") - newGauge(ch, reDesc["cpuUser"], reData.CPUUser.Text, label5s...) - newGauge(ch, reDesc["cpuBackground"], reData.CPUBackground.Text, label5s...) - newGauge(ch, reDesc["cpuSystem"], reData.CPUSystem.Text, label5s...) - newGauge(ch, reDesc["cpuInterrupt"], reData.CPUInterrupt.Text, label5s...) - newGauge(ch, reDesc["cpuIdle"], reData.CPUIdle.Text, label5s...) + newGauge(logger, ch, reDesc["cpuUser"], reData.CPUUser.Text, label5s...) + newGauge(logger, ch, reDesc["cpuBackground"], reData.CPUBackground.Text, label5s...) + newGauge(logger, ch, reDesc["cpuSystem"], reData.CPUSystem.Text, label5s...) + newGauge(logger, ch, reDesc["cpuInterrupt"], reData.CPUInterrupt.Text, label5s...) + newGauge(logger, ch, reDesc["cpuIdle"], reData.CPUIdle.Text, label5s...) label1m := append(labels, "1m") - newGauge(ch, reDesc["cpuUser"], reData.CPUUser1.Text, label1m...) - newGauge(ch, reDesc["cpuBackground"], reData.CPUBackground1.Text, label1m...) - newGauge(ch, reDesc["cpuSystem"], reData.CPUSystem1.Text, label1m...) - newGauge(ch, reDesc["cpuInterrupt"], reData.CPUInterrupt1.Text, label1m...) - newGauge(ch, reDesc["cpuIdle"], reData.CPUIdle1.Text, label1m...) - newGauge(ch, reDesc["loadAvg"], reData.LoadAverageOne.Text, label1m...) + newGauge(logger, ch, reDesc["cpuUser"], reData.CPUUser1.Text, label1m...) + newGauge(logger, ch, reDesc["cpuBackground"], reData.CPUBackground1.Text, label1m...) + newGauge(logger, ch, reDesc["cpuSystem"], reData.CPUSystem1.Text, label1m...) + newGauge(logger, ch, reDesc["cpuInterrupt"], reData.CPUInterrupt1.Text, label1m...) + newGauge(logger, ch, reDesc["cpuIdle"], reData.CPUIdle1.Text, label1m...) + newGauge(logger, ch, reDesc["loadAvg"], reData.LoadAverageOne.Text, label1m...) label5m := append(labels, "5m") - newGauge(ch, reDesc["cpuUser"], reData.CPUUser2.Text, label5m...) - newGauge(ch, reDesc["cpuBackground"], reData.CPUBackground2.Text, label5m...) - newGauge(ch, reDesc["cpuSystem"], reData.CPUSystem2.Text, label5m...) - newGauge(ch, reDesc["cpuInterrupt"], reData.CPUInterrupt2.Text, label5m...) - newGauge(ch, reDesc["cpuIdle"], reData.CPUIdle2.Text, label5m...) - newGauge(ch, reDesc["loadAvg"], reData.LoadAverageFive.Text, label5m...) + newGauge(logger, ch, reDesc["cpuUser"], reData.CPUUser2.Text, label5m...) + newGauge(logger, ch, reDesc["cpuBackground"], reData.CPUBackground2.Text, label5m...) + newGauge(logger, ch, reDesc["cpuSystem"], reData.CPUSystem2.Text, label5m...) + newGauge(logger, ch, reDesc["cpuInterrupt"], reData.CPUInterrupt2.Text, label5m...) + newGauge(logger, ch, reDesc["cpuIdle"], reData.CPUIdle2.Text, label5m...) + newGauge(logger, ch, reDesc["loadAvg"], reData.LoadAverageFive.Text, label5m...) label15m := append(labels, "15m") - newGauge(ch, reDesc["cpuUser"], reData.CPUUser3.Text, label15m...) - newGauge(ch, reDesc["cpuBackground"], reData.CPUBackground3.Text, label15m...) - newGauge(ch, reDesc["cpuSystem"], reData.CPUSystem3.Text, label15m...) - newGauge(ch, reDesc["cpuInterrupt"], reData.CPUInterrupt3.Text, label15m...) - newGauge(ch, reDesc["cpuIdle"], reData.CPUIdle3.Text, label15m...) - newGauge(ch, reDesc["loadAvg"], reData.LoadAverageFifteen.Text, label15m...) + newGauge(logger, ch, reDesc["cpuUser"], reData.CPUUser3.Text, label15m...) + newGauge(logger, ch, reDesc["cpuBackground"], reData.CPUBackground3.Text, label15m...) + newGauge(logger, ch, reDesc["cpuSystem"], reData.CPUSystem3.Text, label15m...) + newGauge(logger, ch, reDesc["cpuInterrupt"], reData.CPUInterrupt3.Text, label15m...) + newGauge(logger, ch, reDesc["cpuIdle"], reData.CPUIdle3.Text, label15m...) + newGauge(logger, ch, reDesc["loadAvg"], reData.LoadAverageFifteen.Text, label15m...) mState := 0.0 if strings.ToLower(reData.MastershipState.Text) == "master" { diff --git a/go.mod b/go.mod index 9cd1ccb..0d623df 100644 --- a/go.mod +++ b/go.mod @@ -3,26 +3,35 @@ module github.com/tynany/junos_exporter go 1.22 require ( - github.com/Juniper/go-netconf v0.1.1 - github.com/prometheus/client_golang v1.7.1 - github.com/prometheus/common v0.10.0 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - gopkg.in/alecthomas/kingpin.v2 v2.2.6 - gopkg.in/yaml.v2 v2.3.0 + github.com/Juniper/go-netconf v0.3.0 + github.com/alecthomas/kingpin/v2 v2.4.0 + github.com/go-kit/log v0.2.1 + github.com/prometheus/client_golang v1.20.3 + github.com/prometheus/common v0.59.1 + github.com/prometheus/exporter-toolkit v0.12.0 + golang.org/x/crypto v0.27.0 + gopkg.in/yaml.v2 v2.4.0 ) require ( - github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect - github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect + github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/golang/protobuf v1.4.2 // indirect - github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/prometheus/client_model v0.2.0 // indirect - github.com/prometheus/procfs v0.1.3 // indirect - github.com/sirupsen/logrus v1.6.0 // indirect - github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b // indirect - golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect - google.golang.org/protobuf v1.25.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/jpillora/backoff v1.0.0 // indirect + github.com/klauspost/compress v1.17.9 // indirect + github.com/mdlayher/socket v0.5.1 // indirect + github.com/mdlayher/vsock v1.2.1 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/xhit/go-str2duration/v2 v2.1.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect ) diff --git a/go.sum b/go.sum index 8512435..9171548 100644 --- a/go.sum +++ b/go.sum @@ -1,170 +1,97 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Juniper/go-netconf v0.1.1 h1:5fx/T7L2Fwq51UnESPOP1CXgGCs7IYxR/pnyC5quu/k= -github.com/Juniper/go-netconf v0.1.1/go.mod h1:2Fy6tQTWnL//D/Ll1hb0RYXN4jndcTyneRn6xj5E1VE= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/Juniper/go-netconf v0.3.0 h1:STAqk495sGA0MqQ3Q8mUmk/CmTfWuIfbXRqpDYXgWNA= +github.com/Juniper/go-netconf v0.3.0/go.mod h1:QhfUOux77kzKAdY1+DOpQswtzp7LeeooYTn2MT7iXkY= +github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY= +github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= +github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30 h1:t3eaIm0rUkzbrIewtiFmMK5RXHej2XnoXNhxVsAYUfg= +github.com/alecthomas/units v0.0.0-20240626203959-61d1e3462e30/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= +github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= +github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= +github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= +github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= +github.com/prometheus/client_golang v1.20.3/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= +github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/exporter-toolkit v0.12.0 h1:DkE5RcEZR3lQA2QD5JLVQIf41dFKNsVMXFhgqcif7fo= +github.com/prometheus/exporter-toolkit v0.12.0/go.mod h1:fQH0KtTn0yrrS0S82kqppRjDDiwMfIQUwT+RBRRhwUc= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b h1:VfPXB/wCGGt590QhD1bOpv2J/AmC/RJNTg/Q59HKSB0= -github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b/go.mod h1:IZpXDfkJ6tWD3PhBK5YzgQT+xJWh7OsdwiG8hA2MkO4= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= +golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/junos_exporter.go b/junos_exporter.go index 8879387..658b5f6 100644 --- a/junos_exporter.go +++ b/junos_exporter.go @@ -2,24 +2,31 @@ package main import ( "fmt" + inbuiltLog "log" "net/http" "os" "time" + "github.com/alecthomas/kingpin/v2" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" + versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/log" + "github.com/prometheus/common/promlog" + "github.com/prometheus/common/promlog/flag" "github.com/prometheus/common/version" + "github.com/prometheus/exporter-toolkit/web" + "github.com/prometheus/exporter-toolkit/web/kingpinflag" "github.com/tynany/junos_exporter/collector" "github.com/tynany/junos_exporter/config" "golang.org/x/crypto/ssh" - kingpin "gopkg.in/alecthomas/kingpin.v2" ) var ( - listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9347").String() telemetryPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String() configPath = kingpin.Flag("config.path", "Path of the YAML configuration file.").Required().String() + webFlagConfig = kingpinflag.AddFlags(kingpin.CommandLine, ":9347") // Slice of all configs. collectors = []collector.Collector{} @@ -35,16 +42,16 @@ var ( bgpTypeKeys = map[string][]string{} ) -func initCollectors() { - collectors = append(collectors, collector.NewInterfaceCollector()) - collectors = append(collectors, collector.NewBGPCollector()) - collectors = append(collectors, collector.NewEnvCollector()) - collectors = append(collectors, collector.NewPowerCollector()) - collectors = append(collectors, collector.NewRECollector()) - collectors = append(collectors, collector.NewIpsecCollector()) - collectors = append(collectors, collector.NewOpticsCollector()) - collectors = append(collectors, collector.NewOSPFCollector()) - collectors = append(collectors, collector.NewFPCCollector()) +func initCollectors(logger log.Logger) { + collectors = append(collectors, collector.NewInterfaceCollector(logger)) + collectors = append(collectors, collector.NewBGPCollector(logger)) + collectors = append(collectors, collector.NewEnvCollector(logger)) + collectors = append(collectors, collector.NewPowerCollector(logger)) + collectors = append(collectors, collector.NewRECollector(logger)) + collectors = append(collectors, collector.NewIpsecCollector(logger)) + collectors = append(collectors, collector.NewOpticsCollector(logger)) + collectors = append(collectors, collector.NewOSPFCollector(logger)) + collectors = append(collectors, collector.NewFPCCollector(logger)) } func validateRequest(configParam string, targetParam string) error { @@ -82,58 +89,55 @@ TargetFound: return nil } -func handler(w http.ResponseWriter, r *http.Request) { - configParam := r.URL.Query().Get("config") - targetParam := r.URL.Query().Get("target") - if err := validateRequest(configParam, targetParam); err != nil { - http.Error(w, err.Error(), 400) - return - } - registry := prometheus.NewRegistry() - enabledCollectors := []collector.Collector{} - for _, collector := range collectors { - for _, col := range collectorConfig.Config[configParam].Collectors { - if collector.Name() == col { - enabledCollectors = append(enabledCollectors, collector) +func handler(logger log.Logger) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + configParam := r.URL.Query().Get("config") + targetParam := r.URL.Query().Get("target") + if err := validateRequest(configParam, targetParam); err != nil { + http.Error(w, err.Error(), 400) + return + } + registry := prometheus.NewRegistry() + enabledCollectors := []collector.Collector{} + for _, collector := range collectors { + for _, col := range collectorConfig.Config[configParam].Collectors { + if collector.Name() == col { + enabledCollectors = append(enabledCollectors, collector) + } } } - } - config := collector.Config{ - SSHClientConfig: exporterSSHConfig[configParam], - SSHTarget: targetParam, - IfaceDescrKeys: interfaceDescriptionKeys[configParam], - IfaceMetricKeys: interfaceMetricKeys[configParam], - BGPTypeKeys: bgpTypeKeys[configParam], - } + config := collector.Config{ + SSHClientConfig: exporterSSHConfig[configParam], + SSHTarget: targetParam, + IfaceDescrKeys: interfaceDescriptionKeys[configParam], + IfaceMetricKeys: interfaceMetricKeys[configParam], + BGPTypeKeys: bgpTypeKeys[configParam], + } - ne, err := collector.NewExporter(enabledCollectors, config) - if err != nil { - log.Errorf("could not start exporter: %s", err) - return - } + nc, err := collector.NewExporter(enabledCollectors, config, logger) + if err != nil { + level.Error(logger).Log("msg", "could not create collector", "err", err) + os.Exit(1) + } - if err := registry.Register(ne); err != nil { - log.Errorf("could not register exporter: %s", err) - return - } + if err := registry.Register(nc); err != nil { + level.Error(logger).Log("msg", "could not register collector", "err", err) + os.Exit(1) + } - gatherers := prometheus.Gatherers{ - prometheus.DefaultGatherer, - registry, - } - handlerOpts := promhttp.HandlerOpts{ - ErrorLog: log.NewErrorLogger(), - ErrorHandling: promhttp.ContinueOnError, - } - promhttp.HandlerFor(gatherers, handlerOpts).ServeHTTP(w, r) -} + gatherers := prometheus.Gatherers{ + prometheus.DefaultGatherer, + registry, + } + handlerOpts := promhttp.HandlerOpts{ + ErrorLog: inbuiltLog.New(log.NewStdlibAdapter(level.Error(logger)), "", 0), + ErrorHandling: promhttp.ContinueOnError, + } -func parseCLI() { - log.AddFlags(kingpin.CommandLine) - kingpin.Version(version.Print("junos_exporter")) - kingpin.HelpFlag.Short('h') - kingpin.Parse() + metricsHandler := promhttp.HandlerFor(gatherers, handlerOpts) + metricsHandler.ServeHTTP(w, r) + }) } func generateSSHConfig() error { @@ -217,13 +221,21 @@ func getBGPTypeKeys() { } func main() { - prometheus.MustRegister(version.NewCollector("junos_exporter")) + promlogConfig := &promlog.Config{} + + flag.AddFlags(kingpin.CommandLine, promlogConfig) + kingpin.Version(version.Print("junos_exporter")) + kingpin.HelpFlag.Short('h') + kingpin.Parse() - initCollectors() - parseCLI() + logger := promlog.New(promlogConfig) - log.Infof("Starting junos_exporter %s on %s", version.Info(), *listenAddress) + initCollectors(logger) + prometheus.MustRegister(versioncollector.NewCollector("junos_exporter")) + + level.Info(logger).Log("msg", "Starting junos_exporter", "version", version.Info()) + level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) // Get a list of collector names to validate collectors specified in the config file exist. var collectorNames []string for _, collector := range collectors { @@ -232,29 +244,39 @@ func main() { var err error collectorConfig, err = config.LoadConfigFile(*configPath, collectorNames) if err != nil { - log.Fatal(err) + level.Error(logger).Log("err", err) + os.Exit(1) } if err = generateSSHConfig(); err != nil { - log.Errorf("could not generate SSH configuration: %s", err) + level.Error(logger).Log("could not generate SSH configuration", err) } getInterfaceDescriptionKeys() getInterfaceMetricKeys() getBGPTypeKeys() - http.HandleFunc(*telemetryPath, handler) - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(` - junos Exporter - -

junos Exporter

-

Metrics

- - `)) - }) + http.Handle(*telemetryPath, handler(logger)) + if *telemetryPath != "/" && *telemetryPath != "" { + landingConfig := web.LandingConfig{ + Name: "Junos Exporter", + Description: "Prometheus Exporter for Junos", + Version: version.Info(), + Links: []web.LandingLinks{ + {Address: *telemetryPath, Text: "Metrics"}, + }, + } + landingPage, err := web.NewLandingPage(landingConfig) + if err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) + } + http.Handle("/", landingPage) + } - if err := http.ListenAndServe(*listenAddress, nil); err != nil { - log.Fatal(err) + server := &http.Server{} + if err := web.ListenAndServe(server, webFlagConfig, logger); err != nil { + level.Error(logger).Log("err", err) + os.Exit(1) } }