diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/go/collectors/go.d.plugin/modules/windows/collect_net.go | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/windows/collect_net.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/windows/collect_net.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/windows/collect_net.go b/src/go/collectors/go.d.plugin/modules/windows/collect_net.go new file mode 100644 index 000000000..e72bf646f --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/windows/collect_net.go @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package windows + +import ( + "strings" + + "github.com/netdata/netdata/go/go.d.plugin/pkg/prometheus" +) + +const ( + metricNetBytesReceivedTotal = "windows_net_bytes_received_total" + metricNetBytesSentTotal = "windows_net_bytes_sent_total" + metricNetPacketsReceivedTotal = "windows_net_packets_received_total" + metricNetPacketsSentTotal = "windows_net_packets_sent_total" + metricNetPacketsReceivedDiscardedTotal = "windows_net_packets_received_discarded_total" + metricNetPacketsOutboundDiscardedTotal = "windows_net_packets_outbound_discarded_total" + metricNetPacketsReceivedErrorsTotal = "windows_net_packets_received_errors_total" + metricNetPacketsOutboundErrorsTotal = "windows_net_packets_outbound_errors_total" +) + +func (w *Windows) collectNet(mx map[string]int64, pms prometheus.Series) { + seen := make(map[string]bool) + px := "net_nic_" + for _, pm := range pms.FindByName(metricNetBytesReceivedTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_bytes_received"] += int64(pm.Value * 8) + } + } + for _, pm := range pms.FindByName(metricNetBytesSentTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_bytes_sent"] += int64(pm.Value * 8) + } + } + for _, pm := range pms.FindByName(metricNetPacketsReceivedTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_received_total"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricNetPacketsSentTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_sent_total"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricNetPacketsReceivedDiscardedTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_received_discarded"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricNetPacketsOutboundDiscardedTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_outbound_discarded"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricNetPacketsReceivedErrorsTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_received_errors"] += int64(pm.Value) + } + } + for _, pm := range pms.FindByName(metricNetPacketsOutboundErrorsTotal) { + if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { + seen[nic] = true + mx[px+nic+"_packets_outbound_errors"] += int64(pm.Value) + } + } + + for nic := range seen { + if !w.cache.nics[nic] { + w.cache.nics[nic] = true + w.addNICCharts(nic) + } + } + for nic := range w.cache.nics { + if !seen[nic] { + delete(w.cache.nics, nic) + w.removeNICCharts(nic) + } + } +} + +func cleanNICID(id string) string { + return strings.Replace(id, "__", "_", -1) +} |