(ch chan<- prometheus.Metric)
| 72 | } |
| 73 | |
| 74 | func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) error { |
| 75 | netClass, err := c.getNetClassInfo() |
| 76 | if err != nil { |
| 77 | if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { |
| 78 | c.logger.Debug("Could not read netclass file", "err", err) |
| 79 | return ErrNoData |
| 80 | } |
| 81 | return fmt.Errorf("could not get net class info: %w", err) |
| 82 | } |
| 83 | for _, ifaceInfo := range netClass { |
| 84 | upDesc := prometheus.NewDesc( |
| 85 | prometheus.BuildFQName(namespace, c.subsystem, "up"), |
| 86 | "Value is 1 if operstate is 'up', 0 otherwise.", |
| 87 | []string{"device"}, |
| 88 | nil, |
| 89 | ) |
| 90 | upValue := 0.0 |
| 91 | if ifaceInfo.OperState == "up" { |
| 92 | upValue = 1.0 |
| 93 | } |
| 94 | |
| 95 | ch <- prometheus.MustNewConstMetric(upDesc, prometheus.GaugeValue, upValue, ifaceInfo.Name) |
| 96 | |
| 97 | infoDesc := prometheus.NewDesc( |
| 98 | prometheus.BuildFQName(namespace, c.subsystem, "info"), |
| 99 | "Non-numeric data from /sys/class/net/<iface>, value is always 1.", |
| 100 | []string{"device", "address", "broadcast", "duplex", "operstate", "adminstate", "ifalias"}, |
| 101 | nil, |
| 102 | ) |
| 103 | infoValue := 1.0 |
| 104 | |
| 105 | ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, getAdminState(ifaceInfo.Flags), ifaceInfo.IfAlias) |
| 106 | |
| 107 | pushMetric(ch, c.getFieldDesc("address_assign_type"), "address_assign_type", ifaceInfo.AddrAssignType, prometheus.GaugeValue, ifaceInfo.Name) |
| 108 | pushMetric(ch, c.getFieldDesc("carrier"), "carrier", ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name) |
| 109 | pushMetric(ch, c.getFieldDesc("carrier_changes_total"), "carrier_changes_total", ifaceInfo.CarrierChanges, prometheus.CounterValue, ifaceInfo.Name) |
| 110 | pushMetric(ch, c.getFieldDesc("carrier_up_changes_total"), "carrier_up_changes_total", ifaceInfo.CarrierUpCount, prometheus.CounterValue, ifaceInfo.Name) |
| 111 | pushMetric(ch, c.getFieldDesc("carrier_down_changes_total"), "carrier_down_changes_total", ifaceInfo.CarrierDownCount, prometheus.CounterValue, ifaceInfo.Name) |
| 112 | pushMetric(ch, c.getFieldDesc("device_id"), "device_id", ifaceInfo.DevID, prometheus.GaugeValue, ifaceInfo.Name) |
| 113 | pushMetric(ch, c.getFieldDesc("dormant"), "dormant", ifaceInfo.Dormant, prometheus.GaugeValue, ifaceInfo.Name) |
| 114 | pushMetric(ch, c.getFieldDesc("flags"), "flags", ifaceInfo.Flags, prometheus.GaugeValue, ifaceInfo.Name) |
| 115 | pushMetric(ch, c.getFieldDesc("iface_id"), "iface_id", ifaceInfo.IfIndex, prometheus.GaugeValue, ifaceInfo.Name) |
| 116 | pushMetric(ch, c.getFieldDesc("iface_link"), "iface_link", ifaceInfo.IfLink, prometheus.GaugeValue, ifaceInfo.Name) |
| 117 | pushMetric(ch, c.getFieldDesc("iface_link_mode"), "iface_link_mode", ifaceInfo.LinkMode, prometheus.GaugeValue, ifaceInfo.Name) |
| 118 | pushMetric(ch, c.getFieldDesc("mtu_bytes"), "mtu_bytes", ifaceInfo.MTU, prometheus.GaugeValue, ifaceInfo.Name) |
| 119 | pushMetric(ch, c.getFieldDesc("name_assign_type"), "name_assign_type", ifaceInfo.NameAssignType, prometheus.GaugeValue, ifaceInfo.Name) |
| 120 | pushMetric(ch, c.getFieldDesc("net_dev_group"), "net_dev_group", ifaceInfo.NetDevGroup, prometheus.GaugeValue, ifaceInfo.Name) |
| 121 | |
| 122 | if ifaceInfo.Speed != nil { |
| 123 | // Some devices return -1 if the speed is unknown. |
| 124 | if *ifaceInfo.Speed >= 0 || !*netclassInvalidSpeed { |
| 125 | speedBytes := int64(*ifaceInfo.Speed * 1000 * 1000 / 8) |
| 126 | pushMetric(ch, c.getFieldDesc("speed_bytes"), "speed_bytes", speedBytes, prometheus.GaugeValue, ifaceInfo.Name) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | pushMetric(ch, c.getFieldDesc("transmit_queue_length"), "transmit_queue_length", ifaceInfo.TxQueueLen, prometheus.GaugeValue, ifaceInfo.Name) |
| 131 | pushMetric(ch, c.getFieldDesc("protocol_type"), "protocol_type", ifaceInfo.Type, prometheus.GaugeValue, ifaceInfo.Name) |
no test coverage detected