From b9b8cfd1ca08892a16a37cfab22931b0e134db38 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Wed, 21 Feb 2018 17:06:07 +0100 Subject: [PATCH] net: export current_bandwidth, fixes #162 --- collector/net.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/collector/net.go b/collector/net.go index 079cd390..b44ea510 100644 --- a/collector/net.go +++ b/collector/net.go @@ -39,6 +39,7 @@ type NetworkCollector struct { PacketsReceivedTotal *prometheus.Desc PacketsReceivedUnknown *prometheus.Desc PacketsSentTotal *prometheus.Desc + CurrentBandwidth *prometheus.Desc nicWhitelistPattern *regexp.Regexp nicBlacklistPattern *regexp.Regexp @@ -115,6 +116,12 @@ func NewNetworkCollector() (Collector, error) { []string{"nic"}, nil, ), + CurrentBandwidth: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "current_bandwidth"), + "(Network.CurrentBandwidth)", + []string{"nic"}, + nil, + ), nicWhitelistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicWhitelist)), nicBlacklistPattern: regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *nicBlacklist)), @@ -150,6 +157,7 @@ type Win32_PerfRawData_Tcpip_NetworkInterface struct { PacketsReceivedPerSec uint64 PacketsReceivedUnknown uint64 PacketsSentPerSec uint64 + CurrentBandwidth uint64 } func (c *NetworkCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { @@ -238,6 +246,12 @@ func (c *NetworkCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des float64(nic.PacketsSentPerSec), name, ) + ch <- prometheus.MustNewConstMetric( + c.CurrentBandwidth, + prometheus.CounterValue, + float64(nic.CurrentBandwidth), + name, + ) } return nil, nil