Skip to content

Commit

Permalink
net: export current_bandwidth, fixes #162
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Feb 21, 2018
1 parent 6b98771 commit b9b8cfd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions collector/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9b8cfd

Please sign in to comment.