Skip to content

Enhance show interface extensive#332

Open
gerhweber wants to merge 4 commits into
czerwonk:mainfrom
gerhweber:enhance_show_interface_extensive
Open

Enhance show interface extensive#332
gerhweber wants to merge 4 commits into
czerwonk:mainfrom
gerhweber:enhance_show_interface_extensive

Conversation

@gerhweber

Copy link
Copy Markdown
Contributor

I enhanced the metrics by adding "output errors" displayed in "show interfaces extensive" which are not yet included.
Please have look down at the bold text:
show interfaces ge-0/0/15 extensive
Physical interface: ge-0/0/15, Enabled, Physical link is Up
Interface index: 665, SNMP ifIndex: 545, Generation: 156
Description: 49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch
Link-level type: Ethernet, MTU: 1514, LAN-PHY mode, Link-mode: Full-duplex, Speed: 1000mbps, Duplex: Full-Duplex, BPDU Error: None, Loop Detect PDU Error: None,
Ethernet-Switching Error: None, MAC-REWRITE Error: None, Loopback: Disabled, Source filtering: Disabled, Flow control: Disabled, Auto-negotiation: Enabled,
Remote fault: Online, Media type: Copper, IEEE 802.3az Energy Efficient Ethernet: Disabled, Auto-MDIX: Enabled
Device flags : Present Running
Interface flags: SNMP-Traps Internal: 0x4000
Link flags : None
CoS queues : 12 supported, 12 maximum usable queues
Hold-times : Up 2000 ms, Down 0 ms
Current address: 9c:5a:80:c4:26:92, Hardware address: 9c:5a:80:c4:26:92
Last flapped : 2026-03-06 14:31:48 UTC (5w2d 18:55 ago)
Statistics last cleared: Never
Traffic statistics:
Input bytes : 13415613059 2840 bps
Output bytes : 13356423942 3664 bps
Input packets: 37416959 4 pps
Output packets: 36763815 4 pps
IPv6 transit statistics:
Input bytes : 0
Output bytes : 0
Input packets: 0
Output packets: 0
Input errors:
Errors: 0, Drops: 0, Framing errors: 0, Runts: 0, Policed discards: 0, L3 incompletes: 0, L2 channel errors: 0, L2 mismatch timeouts: 0, FIFO errors: 0, Resource errors: 0
Output errors:
Carrier transitions: 5, Errors: 0, Drops: 0, Collisions: 0, Aged packets: 0, FIFO errors: 0, HS link CRC errors: 0, MTU errors: 0, Resource errors: 0
Egress queues: 12 supported, 8 in use
Queue counters: Queued packets Transmitted packets Dropped packets
0 10666698 10666698 0
1 0 0 0
2 0 0 0
3 26097115 26097115 0
8 0 0 0
9 0 0 0
10 0 0 0
11 0 0 0
Queue number: Mapped forwarding classes
0 best-effort
1 expedited-forwarding
2 assured-forwarding
3 network-control
8 mcast-be
9 mcast-ef
10 mcast-af
11 mcast-nc
Active alarms : None
Active defects : None
PCS statistics Seconds
Bit errors 0
Errored blocks 0
Ethernet FEC statistics Errors
FEC Corrected Errors 0
FEC Uncorrected Errors 0
FEC Corrected Errors Rate 0
FEC Uncorrected Errors Rate 0
MAC statistics: Receive Transmit
Total octets 13415613059 13356423942
Total packets 37416959 36763815
Unicast packets 37158761 36510941
Broadcast packets 53539 48162
Multicast packets 204659 204712
CRC/Align errors 0 0
FIFO errors 0 0
MAC control frames 0 0
MAC pause frames 0 0
Oversized frames 0
Jabber frames 0
Fragment frames 0
VLAN tagged frames 0
Code violations 0
PRBS Mode : Disabled
Autonegotiation information:
Negotiation status: Complete
Link partner:
Link mode: Full-duplex, Flow control: None, Remote fault: OK, Link partner Speed: 1000 Mbps
Local resolution:
Flow control: None, Flow control tx: None, Flow control rx: None, Remote fault: Link OK, Local link Speed: 1000 Mbps, Link mode: Full-duplex
Packet Forwarding Engine configuration:
Destination slot: 0 (0x00)
CoS information:
Direction : Output
CoS transmit queue Bandwidth Buffer Priority Limit
% bps % usec
0 best-effort 75 750000000 75 0 low none
3 network-control 5 50000000 5 0 low none
8 mcast-be 15 150000000 15 0 low none
11 mcast-nc 5 50000000 5 0 low none
Interface transmit statistics: Disabled
MACSec statistics:
Output
Secure Channel Transmitted
Protected Packets : 0
Encrypted Packets : 0
Protected Bytes : 0
Encrypted Bytes : 0
Input
Secure Channel Received
Accepted Packets : 0
Validated Bytes : 0
Decrypted Bytes : 0

Logical interface ge-0/0/15.0 (Index 580) (SNMP ifIndex 547) (HW Token 2047) (Generation 165)
Flags: Up SNMP-Traps 0x4004000 Encapsulation: ENET2
Traffic statistics:
Input bytes : 13415612702
Output bytes : 11379664115
Input packets: 37416967
Output packets: 9717722
Local statistics:
Input bytes : 165732783
Output bytes : 184098688
Input packets: 1166605
Output packets: 1170652
Transit statistics:
Input bytes : 13249879919 2496 bps
Output bytes : 11195565427 0 bps
Input packets: 36250362 4 pps
Output packets: 8547070 0 pps
Protocol inet, MTU: 1500
Max nh cache: 75000, New hold nh limit: 75000, Curr nh cnt: 3, Curr new hold cnt: 0, NH drop cnt: 0
Generation: 194, Route table: 7
Flags: Sendbcast-pkt-to-re, Is-Primary
Addresses, Flags: Is-Default Is-Preferred Is-Primary
Destination: 10.100.121.0/29, Local: 10.100.121.4, Broadcast: 10.100.121.7, Generation: 150

New metrics are:
junos_interface_transmit_carrier_transitions{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0
junos_interface_transmit_collisions{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0
junos_interface_transmit_crc_errors{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0
junos_interface_transmit_fifo_erros{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0
junos_interface_transmit_mtu_errors{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0
junos_interface_transmit_resource_errors{description="49_6151_BORLAB_TOPO-01_5C2C - Uplink to DCN-Switch",mac="9c:5a:80:c4:26:92",name="ge-0/0/15",target="10.100.190.232"} 0

@gerhweber gerhweber requested a review from czerwonk as a code owner April 13, 2026 09:31
Comment thread main.go
sshExpireTimeout = flag.Duration("ssh.expire-timeout", 15*time.Minute, "Duration after an connection is terminated when it is not used")
debug = flag.Bool("debug", false, "Show verbose debug output in log")
alarmEnabled = flag.Bool("alarm.enabled", true, "Scrape Alarm metrics")
alarmEnabled = flag.Bool("alarm.enabled", false, "Scrape Alarm metrics")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an intentional change? The alarm feature is enabled by default in the config handler:

Also, what does alarms feature have to do with the changes in this PR?

@gerhweber

Copy link
Copy Markdown
Contributor Author

This change comes not from my side. In my fork it is set to “false” but I never changed it.

@crabique

Copy link
Copy Markdown
Contributor

This change comes not from my side. In my fork it is set to “false” but I never changed it.

Yes, your fork has the main branch lagging behind the latest changes in this repo; in the meanwhile, the codebase was updated to ensure all feature defaults match for configs and CLI flags, since alarm feature is enabled in config by default, it is also now enabled in CLI flags by default.

Since your PR only changes the CLI flags and not the configs, the TestDefaultsAreConsistent() test will fail.

Could you please sync your fork's main branch with the upstream and rebase the PR off it so that there are no unintentional changes?

@gerhweber

Copy link
Copy Markdown
Contributor Author

I will sync my fork but I need some time to do it - I have other tasks before

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the exporter’s JunOS scraping capabilities by adding additional “output error” counters from show interfaces extensive, and it also introduces a new NTP collector feature that can be enabled via config/flags.

Changes:

  • Add additional interface transmit/output-error counters (carrier transitions, collisions, FIFO/CRC/MTU/resource errors, etc.).
  • Introduce a new ntp collector (plus config + CLI flag wiring) for scraping show ntp status.
  • Adjust feature-flag defaults (notably alarm.enabled).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pkg/features/ntp/rpc.go Adds XML reply type + key/value parser for NTP output.
pkg/features/ntp/collector.go Implements NTP collector and exports NTP-related metrics.
pkg/features/interfaces/rpc.go Extends RPC XML mapping for additional output-error fields.
pkg/features/interfaces/interface_stats.go Adds new output-error fields to the internal stats model.
pkg/features/interfaces/collector.go Adds new Prometheus descriptors and exports new output-error metrics.
main.go Adds -ntp.enabled flag and wires it into feature config; changes -alarm.enabled default.
internal/config/config.go Adds features.ntp and default value handling.
collectors.go Registers the new NTP collector when enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +87
d.transmitAgedPackets = prometheus.NewDesc(prefix+"transmit_aged_packets", "Number of outgoing aged packets ", l, nil)
d.transmitFIFOErrors = prometheus.NewDesc(prefix+"transmit_fifo_erros", "Number of outgoing packets with FIFO errors", l, nil)
d.transmitCRCErrors = prometheus.NewDesc(prefix+"transmit_crc_errors", "Number of outgoing packets with CRC errors ", l, nil)
d.transmitMTUErrors = prometheus.NewDesc(prefix+"transmit_mtu_errors", "Number of outgoing packets with MTU errors ", l, nil)
d.transmitResourceErrors = prometheus.NewDesc(prefix+"transmit_resource_errors", "Number of coutgoing packets with resource errors", l, nil)
ReceivePackets: float64(phy.Stats.InputPackets),
Speed: phy.Speed,
BPDUError: phy.BPDUError == "detected",
CarrierTransitions: float64(phy.OutputErrors.CarrierTransitions),
func (c *ntpCollector) Collect(client collector.Client, ch chan<- prometheus.Metric, labelValues []string) error {
var reply rpcReply

err := client.RunCommandAndParse("show ntp status | display xml", &reply)
Comment on lines +29 to +34
ntpStratumDesc = prometheus.NewDesc(prefix+"stratum", "NTP stratum level (0: reference clock, 1-15: hops to refernce clock, 16: not syncronized)", l, nil)
ntpOffsetDesc = prometheus.NewDesc(prefix+"offset", "Time offset in msec", l, nil)
ntpSysJitterDesc = prometheus.NewDesc(prefix+"system_jitter", "System jitter in msec", l, nil)
ntpClkJitterDesc = prometheus.NewDesc(prefix+"clock_jitter", "Clock jitter in msec", l, nil)
ntpRootDelayDesc = prometheus.NewDesc(prefix+"root_delay", "Root delay in msec", l, nil)
ntpLeapDesc = prometheus.NewDesc(prefix+"leap", "Leap indicator (00=ok, 01: last minute with 61 seconds, 10: last minute with 59 seconds, 11: not syncronized)", l, nil)
Comment thread pkg/features/ntp/rpc.go
Comment on lines +1 to +8
// In rpc.go NUR folgendes belassen:
package ntp

import (
"encoding/xml"
"regexp"
"strings"
)
Comment thread pkg/features/ntp/rpc.go
Comment on lines +30 to +32
func parseNTPOutput(output string) map[string]string {
re := regexp.MustCompile(`(\w+)=("[^"]+"|\S+)`)
matches := re.FindAllStringSubmatch(output, -1)
Comment thread main.go
Comment on lines 41 to 46
sshKeepAliveTimeout = flag.Duration("ssh.keep-alive-timeout", 15*time.Second, "Duration to wait for keep alive message response")
sshExpireTimeout = flag.Duration("ssh.expire-timeout", 15*time.Minute, "Duration after an connection is terminated when it is not used")
debug = flag.Bool("debug", false, "Show verbose debug output in log")
alarmEnabled = flag.Bool("alarm.enabled", true, "Scrape Alarm metrics")
alarmEnabled = flag.Bool("alarm.enabled", false, "Scrape Alarm metrics")
ntpEnabled = flag.Bool("ntp.enabled", false, "Scrape NTP metrics")
bgpEnabled = flag.Bool("bgp.enabled", true, "Scrape BGP metrics")
Comment on lines +68 to +81
// Hier wird das parseResult direkt aus den Metriken erzeugt
metrics := parseNTPOutput(reply.Output.Text)
if len(metrics) == 0 {
return errors.New("no NTP metrics parsed")
}

tc := mustParseFloat(metrics["tc"])
if tc == 0 {
tc = 10
}

// Konvertierung der Metriken in parseResult
result := &parseResult{
AssocID: metrics["associd"],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants