github.com/netdata/go.d.plugin@v0.58.1/modules/windows/collect_net.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package windows 4 5 import ( 6 "strings" 7 8 "github.com/netdata/go.d.plugin/pkg/prometheus" 9 ) 10 11 const ( 12 metricNetBytesReceivedTotal = "windows_net_bytes_received_total" 13 metricNetBytesSentTotal = "windows_net_bytes_sent_total" 14 metricNetPacketsReceivedTotal = "windows_net_packets_received_total" 15 metricNetPacketsSentTotal = "windows_net_packets_sent_total" 16 metricNetPacketsReceivedDiscardedTotal = "windows_net_packets_received_discarded_total" 17 metricNetPacketsOutboundDiscardedTotal = "windows_net_packets_outbound_discarded_total" 18 metricNetPacketsReceivedErrorsTotal = "windows_net_packets_received_errors_total" 19 metricNetPacketsOutboundErrorsTotal = "windows_net_packets_outbound_errors_total" 20 ) 21 22 func (w *Windows) collectNet(mx map[string]int64, pms prometheus.Series) { 23 seen := make(map[string]bool) 24 px := "net_nic_" 25 for _, pm := range pms.FindByName(metricNetBytesReceivedTotal) { 26 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 27 seen[nic] = true 28 mx[px+nic+"_bytes_received"] += int64(pm.Value * 8) 29 } 30 } 31 for _, pm := range pms.FindByName(metricNetBytesSentTotal) { 32 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 33 seen[nic] = true 34 mx[px+nic+"_bytes_sent"] += int64(pm.Value * 8) 35 } 36 } 37 for _, pm := range pms.FindByName(metricNetPacketsReceivedTotal) { 38 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 39 seen[nic] = true 40 mx[px+nic+"_packets_received_total"] += int64(pm.Value) 41 } 42 } 43 for _, pm := range pms.FindByName(metricNetPacketsSentTotal) { 44 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 45 seen[nic] = true 46 mx[px+nic+"_packets_sent_total"] += int64(pm.Value) 47 } 48 } 49 for _, pm := range pms.FindByName(metricNetPacketsReceivedDiscardedTotal) { 50 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 51 seen[nic] = true 52 mx[px+nic+"_packets_received_discarded"] += int64(pm.Value) 53 } 54 } 55 for _, pm := range pms.FindByName(metricNetPacketsOutboundDiscardedTotal) { 56 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 57 seen[nic] = true 58 mx[px+nic+"_packets_outbound_discarded"] += int64(pm.Value) 59 } 60 } 61 for _, pm := range pms.FindByName(metricNetPacketsReceivedErrorsTotal) { 62 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 63 seen[nic] = true 64 mx[px+nic+"_packets_received_errors"] += int64(pm.Value) 65 } 66 } 67 for _, pm := range pms.FindByName(metricNetPacketsOutboundErrorsTotal) { 68 if nic := cleanNICID(pm.Labels.Get("nic")); nic != "" { 69 seen[nic] = true 70 mx[px+nic+"_packets_outbound_errors"] += int64(pm.Value) 71 } 72 } 73 74 for nic := range seen { 75 if !w.cache.nics[nic] { 76 w.cache.nics[nic] = true 77 w.addNICCharts(nic) 78 } 79 } 80 for nic := range w.cache.nics { 81 if !seen[nic] { 82 delete(w.cache.nics, nic) 83 w.removeNICCharts(nic) 84 } 85 } 86 } 87 88 func cleanNICID(id string) string { 89 return strings.Replace(id, "__", "_", -1) 90 }