Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export interface speeds #39

Merged
merged 2 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions interfaces/interface_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
receivePacketsDesc *prometheus.Desc
receiveErrorsDesc *prometheus.Desc
receiveDropsDesc *prometheus.Desc
interfaceSpeedDesc *prometheus.Desc
transmitBytesDesc *prometheus.Desc
transmitPacketsDesc *prometheus.Desc
transmitErrorsDesc *prometheus.Desc
Expand All @@ -24,6 +25,17 @@ var (
adminStatusDesc *prometheus.Desc
operStatusDesc *prometheus.Desc
errorStatusDesc *prometheus.Desc
speedMap = map[string]float64{
"10mbps": float64(10000000.0),
"100mbps": float64(100000000.0),
"1000mbps": float64(1000000000.0),
"10Gbps": float64(10000000000.0),
"20Gbps": float64(20000000000.0),
"40Gbps": float64(40000000000.0),
"50Gbps": float64(50000000000.0),
"80Gbps": float64(80000000000.0),
"100Gbps": float64(100000000000.0),
}
)

func init() {
Expand All @@ -32,6 +44,7 @@ func init() {
receivePacketsDesc = prometheus.NewDesc(prefix+"receive_packets_total", "Received packets", l, nil)
receiveErrorsDesc = prometheus.NewDesc(prefix+"receive_errors", "Number of errors caused by incoming packets", l, nil)
receiveDropsDesc = prometheus.NewDesc(prefix+"receive_drops", "Number of dropped incoming packets", l, nil)
interfaceSpeedDesc = prometheus.NewDesc(prefix+"speed", "speed in in bps", l, nil)
transmitBytesDesc = prometheus.NewDesc(prefix+"transmit_bytes", "Transmitted data in bytes", l, nil)
transmitPacketsDesc = prometheus.NewDesc(prefix+"transmit_packets_total", "Transmitted packets", l, nil)
transmitErrorsDesc = prometheus.NewDesc(prefix+"transmit_errors", "Number of errors caused by outgoing packets", l, nil)
Expand Down Expand Up @@ -60,6 +73,7 @@ func (*interfaceCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- receivePacketsDesc
ch <- receiveErrorsDesc
ch <- receiveDropsDesc
ch <- interfaceSpeedDesc
ch <- transmitBytesDesc
ch <- transmitPacketsDesc
ch <- transmitDropsDesc
Expand Down Expand Up @@ -108,6 +122,7 @@ func (c *interfaceCollector) interfaceStats(client *rpc.Client) ([]*InterfaceSta
ReceiveErrors: float64(phy.InputErrors.Errors),
ReceiveBytes: float64(phy.Stats.InputBytes),
ReceivePackets: float64(phy.Stats.InputPackets),
Speed: speedMap[phy.Speed],
TransmitDrops: float64(phy.OutputErrors.Drops),
TransmitErrors: float64(phy.OutputErrors.Errors),
TransmitBytes: float64(phy.Stats.OutputBytes),
Expand Down Expand Up @@ -175,5 +190,7 @@ func (*interfaceCollector) collectForInterface(s *InterfaceStats, ch chan<- prom
ch <- prometheus.MustNewConstMetric(transmitDropsDesc, prometheus.GaugeValue, s.TransmitDrops, l...)
ch <- prometheus.MustNewConstMetric(receiveErrorsDesc, prometheus.GaugeValue, s.ReceiveErrors, l...)
ch <- prometheus.MustNewConstMetric(receiveDropsDesc, prometheus.GaugeValue, s.ReceiveDrops, l...)
ch <- prometheus.MustNewConstMetric(interfaceSpeedDesc, prometheus.GaugeValue, s.Speed, l...)

}
}
1 change: 1 addition & 0 deletions interfaces/interface_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type InterfaceStats struct {
Description string
Mac string
IsPhysical bool
Speed float64
ReceiveBytes float64
ReceivePackets float64
ReceiveErrors float64
Expand Down
9 changes: 5 additions & 4 deletions interfaces/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PhyInterface struct {
OperStatus string `xml:"oper-status"`
Description string `xml:"description"`
MacAddress string `xml:"current-physical-address"`
Speed string `xml:"speed"`
Stats TrafficStat `xml:"traffic-statistics"`
LogicalInterfaces []LogInterface `xml:"logical-interface"`
InputErrors struct {
Expand All @@ -31,10 +32,10 @@ type LogInterface struct {
}

type TrafficStat struct {
InputBytes uint64 `xml:"input-bytes"`
InputPackets uint64 `xml:"input-packets"`
OutputBytes uint64 `xml:"output-bytes"`
OutputPackets uint64 `xml:"output-packets"`
InputBytes uint64 `xml:"input-bytes"`
InputPackets uint64 `xml:"input-packets"`
OutputBytes uint64 `xml:"output-bytes"`
OutputPackets uint64 `xml:"output-packets"`
IPv6Traffic IPv6Stat `xml:"ipv6-transit-statistics"`
}

Expand Down