mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-27 14:39:53 -08:00
Refactor netclass_rtnl collector (#2528)
* Refactor netclass_rtnl collector Merge the netclass_rtnl collector into the netclass collector. * Disabled by default * Followup to #2492 Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
956a3f8d47
commit
13a5cc1f74
|
@ -198,3 +198,49 @@ var ErrNoData = errors.New("collector returned no data")
|
|||
func IsNoDataError(err error) bool {
|
||||
return err == ErrNoData
|
||||
}
|
||||
|
||||
// pushMetric helps construct and convert a variety of value types into Prometheus float64 metrics.
|
||||
func pushMetric(ch chan<- prometheus.Metric, fieldDesc *prometheus.Desc, name string, value interface{}, valueType prometheus.ValueType, labelValues ...string) {
|
||||
var fVal float64
|
||||
switch val := value.(type) {
|
||||
case uint8:
|
||||
fVal = float64(val)
|
||||
case uint16:
|
||||
fVal = float64(val)
|
||||
case uint32:
|
||||
fVal = float64(val)
|
||||
case uint64:
|
||||
fVal = float64(val)
|
||||
case int64:
|
||||
fVal = float64(val)
|
||||
case *uint8:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint16:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint32:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint64:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *int64:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, fVal, labelValues...)
|
||||
}
|
||||
|
|
|
@ -2355,47 +2355,47 @@ node_netstat_Udp_RcvbufErrors 9
|
|||
# HELP node_netstat_Udp_SndbufErrors Statistic UdpSndbufErrors.
|
||||
# TYPE node_netstat_Udp_SndbufErrors untyped
|
||||
node_netstat_Udp_SndbufErrors 8
|
||||
# HELP node_network_address_assign_type address_assign_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_address_assign_type Network device property: address_assign_type
|
||||
# TYPE node_network_address_assign_type gauge
|
||||
node_network_address_assign_type{device="bond0"} 3
|
||||
node_network_address_assign_type{device="eth0"} 3
|
||||
# HELP node_network_carrier carrier value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier Network device property: carrier
|
||||
# TYPE node_network_carrier gauge
|
||||
node_network_carrier{device="bond0"} 1
|
||||
node_network_carrier{device="eth0"} 1
|
||||
# HELP node_network_carrier_changes_total carrier_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_changes_total Network device property: carrier_changes_total
|
||||
# TYPE node_network_carrier_changes_total counter
|
||||
node_network_carrier_changes_total{device="bond0"} 2
|
||||
node_network_carrier_changes_total{device="eth0"} 2
|
||||
# HELP node_network_carrier_down_changes_total carrier_down_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_down_changes_total Network device property: carrier_down_changes_total
|
||||
# TYPE node_network_carrier_down_changes_total counter
|
||||
node_network_carrier_down_changes_total{device="bond0"} 1
|
||||
node_network_carrier_down_changes_total{device="eth0"} 1
|
||||
# HELP node_network_carrier_up_changes_total carrier_up_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_up_changes_total Network device property: carrier_up_changes_total
|
||||
# TYPE node_network_carrier_up_changes_total counter
|
||||
node_network_carrier_up_changes_total{device="bond0"} 1
|
||||
node_network_carrier_up_changes_total{device="eth0"} 1
|
||||
# HELP node_network_device_id device_id value of /sys/class/net/<iface>.
|
||||
# HELP node_network_device_id Network device property: device_id
|
||||
# TYPE node_network_device_id gauge
|
||||
node_network_device_id{device="bond0"} 32
|
||||
node_network_device_id{device="eth0"} 32
|
||||
# HELP node_network_dormant dormant value of /sys/class/net/<iface>.
|
||||
# HELP node_network_dormant Network device property: dormant
|
||||
# TYPE node_network_dormant gauge
|
||||
node_network_dormant{device="bond0"} 1
|
||||
node_network_dormant{device="eth0"} 1
|
||||
# HELP node_network_flags flags value of /sys/class/net/<iface>.
|
||||
# HELP node_network_flags Network device property: flags
|
||||
# TYPE node_network_flags gauge
|
||||
node_network_flags{device="bond0"} 4867
|
||||
node_network_flags{device="eth0"} 4867
|
||||
# HELP node_network_iface_id iface_id value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_id Network device property: iface_id
|
||||
# TYPE node_network_iface_id gauge
|
||||
node_network_iface_id{device="bond0"} 2
|
||||
node_network_iface_id{device="eth0"} 2
|
||||
# HELP node_network_iface_link iface_link value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_link Network device property: iface_link
|
||||
# TYPE node_network_iface_link gauge
|
||||
node_network_iface_link{device="bond0"} 2
|
||||
node_network_iface_link{device="eth0"} 2
|
||||
# HELP node_network_iface_link_mode iface_link_mode value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_link_mode Network device property: iface_link_mode
|
||||
# TYPE node_network_iface_link_mode gauge
|
||||
node_network_iface_link_mode{device="bond0"} 1
|
||||
node_network_iface_link_mode{device="eth0"} 1
|
||||
|
@ -2403,19 +2403,19 @@ node_network_iface_link_mode{device="eth0"} 1
|
|||
# TYPE node_network_info gauge
|
||||
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
|
||||
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
|
||||
# HELP node_network_mtu_bytes mtu_bytes value of /sys/class/net/<iface>.
|
||||
# HELP node_network_mtu_bytes Network device property: mtu_bytes
|
||||
# TYPE node_network_mtu_bytes gauge
|
||||
node_network_mtu_bytes{device="bond0"} 1500
|
||||
node_network_mtu_bytes{device="eth0"} 1500
|
||||
# HELP node_network_name_assign_type name_assign_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_name_assign_type Network device property: name_assign_type
|
||||
# TYPE node_network_name_assign_type gauge
|
||||
node_network_name_assign_type{device="bond0"} 2
|
||||
node_network_name_assign_type{device="eth0"} 2
|
||||
# HELP node_network_net_dev_group net_dev_group value of /sys/class/net/<iface>.
|
||||
# HELP node_network_net_dev_group Network device property: net_dev_group
|
||||
# TYPE node_network_net_dev_group gauge
|
||||
node_network_net_dev_group{device="bond0"} 0
|
||||
node_network_net_dev_group{device="eth0"} 0
|
||||
# HELP node_network_protocol_type protocol_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_protocol_type Network device property: protocol_type
|
||||
# TYPE node_network_protocol_type gauge
|
||||
node_network_protocol_type{device="bond0"} 1
|
||||
node_network_protocol_type{device="eth0"} 1
|
||||
|
@ -2444,7 +2444,7 @@ node_network_receive_multicast_total{device="lo"} 0
|
|||
node_network_receive_nohandler_total{device="lo"} 0
|
||||
# HELP node_network_receive_packets_total Network device statistic receive_packets.
|
||||
# TYPE node_network_receive_packets_total counter
|
||||
# HELP node_network_speed_bytes speed_bytes value of /sys/class/net/<iface>.
|
||||
# HELP node_network_speed_bytes Network device property: speed_bytes
|
||||
# TYPE node_network_speed_bytes gauge
|
||||
node_network_speed_bytes{device="eth0"} 1.25e+08
|
||||
# HELP node_network_transmit_bytes_total Network device statistic transmit_bytes.
|
||||
|
@ -2469,7 +2469,7 @@ node_network_transmit_errs_total{device="lo"} 0
|
|||
node_network_transmit_fifo_total{device="lo"} 0
|
||||
# HELP node_network_transmit_packets_total Network device statistic transmit_packets.
|
||||
# TYPE node_network_transmit_packets_total counter
|
||||
# HELP node_network_transmit_queue_length transmit_queue_length value of /sys/class/net/<iface>.
|
||||
# HELP node_network_transmit_queue_length Network device property: transmit_queue_length
|
||||
# TYPE node_network_transmit_queue_length gauge
|
||||
node_network_transmit_queue_length{device="bond0"} 1000
|
||||
node_network_transmit_queue_length{device="eth0"} 1000
|
||||
|
|
|
@ -2377,47 +2377,47 @@ node_netstat_Udp_RcvbufErrors 9
|
|||
# HELP node_netstat_Udp_SndbufErrors Statistic UdpSndbufErrors.
|
||||
# TYPE node_netstat_Udp_SndbufErrors untyped
|
||||
node_netstat_Udp_SndbufErrors 8
|
||||
# HELP node_network_address_assign_type address_assign_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_address_assign_type Network device property: address_assign_type
|
||||
# TYPE node_network_address_assign_type gauge
|
||||
node_network_address_assign_type{device="bond0"} 3
|
||||
node_network_address_assign_type{device="eth0"} 3
|
||||
# HELP node_network_carrier carrier value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier Network device property: carrier
|
||||
# TYPE node_network_carrier gauge
|
||||
node_network_carrier{device="bond0"} 1
|
||||
node_network_carrier{device="eth0"} 1
|
||||
# HELP node_network_carrier_changes_total carrier_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_changes_total Network device property: carrier_changes_total
|
||||
# TYPE node_network_carrier_changes_total counter
|
||||
node_network_carrier_changes_total{device="bond0"} 2
|
||||
node_network_carrier_changes_total{device="eth0"} 2
|
||||
# HELP node_network_carrier_down_changes_total carrier_down_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_down_changes_total Network device property: carrier_down_changes_total
|
||||
# TYPE node_network_carrier_down_changes_total counter
|
||||
node_network_carrier_down_changes_total{device="bond0"} 1
|
||||
node_network_carrier_down_changes_total{device="eth0"} 1
|
||||
# HELP node_network_carrier_up_changes_total carrier_up_changes_total value of /sys/class/net/<iface>.
|
||||
# HELP node_network_carrier_up_changes_total Network device property: carrier_up_changes_total
|
||||
# TYPE node_network_carrier_up_changes_total counter
|
||||
node_network_carrier_up_changes_total{device="bond0"} 1
|
||||
node_network_carrier_up_changes_total{device="eth0"} 1
|
||||
# HELP node_network_device_id device_id value of /sys/class/net/<iface>.
|
||||
# HELP node_network_device_id Network device property: device_id
|
||||
# TYPE node_network_device_id gauge
|
||||
node_network_device_id{device="bond0"} 32
|
||||
node_network_device_id{device="eth0"} 32
|
||||
# HELP node_network_dormant dormant value of /sys/class/net/<iface>.
|
||||
# HELP node_network_dormant Network device property: dormant
|
||||
# TYPE node_network_dormant gauge
|
||||
node_network_dormant{device="bond0"} 1
|
||||
node_network_dormant{device="eth0"} 1
|
||||
# HELP node_network_flags flags value of /sys/class/net/<iface>.
|
||||
# HELP node_network_flags Network device property: flags
|
||||
# TYPE node_network_flags gauge
|
||||
node_network_flags{device="bond0"} 4867
|
||||
node_network_flags{device="eth0"} 4867
|
||||
# HELP node_network_iface_id iface_id value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_id Network device property: iface_id
|
||||
# TYPE node_network_iface_id gauge
|
||||
node_network_iface_id{device="bond0"} 2
|
||||
node_network_iface_id{device="eth0"} 2
|
||||
# HELP node_network_iface_link iface_link value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_link Network device property: iface_link
|
||||
# TYPE node_network_iface_link gauge
|
||||
node_network_iface_link{device="bond0"} 2
|
||||
node_network_iface_link{device="eth0"} 2
|
||||
# HELP node_network_iface_link_mode iface_link_mode value of /sys/class/net/<iface>.
|
||||
# HELP node_network_iface_link_mode Network device property: iface_link_mode
|
||||
# TYPE node_network_iface_link_mode gauge
|
||||
node_network_iface_link_mode{device="bond0"} 1
|
||||
node_network_iface_link_mode{device="eth0"} 1
|
||||
|
@ -2425,19 +2425,19 @@ node_network_iface_link_mode{device="eth0"} 1
|
|||
# TYPE node_network_info gauge
|
||||
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="bond0",duplex="full",ifalias="",operstate="up"} 1
|
||||
node_network_info{address="01:01:01:01:01:01",broadcast="ff:ff:ff:ff:ff:ff",device="eth0",duplex="full",ifalias="",operstate="up"} 1
|
||||
# HELP node_network_mtu_bytes mtu_bytes value of /sys/class/net/<iface>.
|
||||
# HELP node_network_mtu_bytes Network device property: mtu_bytes
|
||||
# TYPE node_network_mtu_bytes gauge
|
||||
node_network_mtu_bytes{device="bond0"} 1500
|
||||
node_network_mtu_bytes{device="eth0"} 1500
|
||||
# HELP node_network_name_assign_type name_assign_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_name_assign_type Network device property: name_assign_type
|
||||
# TYPE node_network_name_assign_type gauge
|
||||
node_network_name_assign_type{device="bond0"} 2
|
||||
node_network_name_assign_type{device="eth0"} 2
|
||||
# HELP node_network_net_dev_group net_dev_group value of /sys/class/net/<iface>.
|
||||
# HELP node_network_net_dev_group Network device property: net_dev_group
|
||||
# TYPE node_network_net_dev_group gauge
|
||||
node_network_net_dev_group{device="bond0"} 0
|
||||
node_network_net_dev_group{device="eth0"} 0
|
||||
# HELP node_network_protocol_type protocol_type value of /sys/class/net/<iface>.
|
||||
# HELP node_network_protocol_type Network device property: protocol_type
|
||||
# TYPE node_network_protocol_type gauge
|
||||
node_network_protocol_type{device="bond0"} 1
|
||||
node_network_protocol_type{device="eth0"} 1
|
||||
|
@ -2466,7 +2466,7 @@ node_network_receive_multicast_total{device="lo"} 0
|
|||
node_network_receive_nohandler_total{device="lo"} 0
|
||||
# HELP node_network_receive_packets_total Network device statistic receive_packets.
|
||||
# TYPE node_network_receive_packets_total counter
|
||||
# HELP node_network_speed_bytes speed_bytes value of /sys/class/net/<iface>.
|
||||
# HELP node_network_speed_bytes Network device property: speed_bytes
|
||||
# TYPE node_network_speed_bytes gauge
|
||||
node_network_speed_bytes{device="eth0"} 1.25e+08
|
||||
# HELP node_network_transmit_bytes_total Network device statistic transmit_bytes.
|
||||
|
@ -2491,7 +2491,7 @@ node_network_transmit_errs_total{device="lo"} 0
|
|||
node_network_transmit_fifo_total{device="lo"} 0
|
||||
# HELP node_network_transmit_packets_total Network device statistic transmit_packets.
|
||||
# TYPE node_network_transmit_packets_total counter
|
||||
# HELP node_network_transmit_queue_length transmit_queue_length value of /sys/class/net/<iface>.
|
||||
# HELP node_network_transmit_queue_length Network device property: transmit_queue_length
|
||||
# TYPE node_network_transmit_queue_length gauge
|
||||
node_network_transmit_queue_length{device="bond0"} 1000
|
||||
node_network_transmit_queue_length{device="eth0"} 1000
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
var (
|
||||
netclassIgnoredDevices = kingpin.Flag("collector.netclass.ignored-devices", "Regexp of net devices to ignore for netclass collector.").Default("^$").String()
|
||||
netclassInvalidSpeed = kingpin.Flag("collector.netclass.ignore-invalid-speed", "Ignore devices where the speed is invalid. This will be the default behavior in 2.x.").Bool()
|
||||
netclassNetlink = kingpin.Flag("collector.netclass.netlink", "Use netlink to gather stats instead of /proc/net/dev.").Default("false").Bool()
|
||||
)
|
||||
|
||||
type netClassCollector struct {
|
||||
|
@ -63,6 +64,13 @@ func NewNetClassCollector(logger log.Logger) (Collector, error) {
|
|||
}
|
||||
|
||||
func (c *netClassCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
if *netclassNetlink {
|
||||
return c.netClassRTNLUpdate(ch)
|
||||
}
|
||||
return c.netClassSysfsUpdate(ch)
|
||||
}
|
||||
|
||||
func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) error {
|
||||
netClass, err := c.getNetClassInfo()
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
|
||||
|
@ -132,7 +140,7 @@ func (c *netClassCollector) getFieldDesc(name string) *prometheus.Desc {
|
|||
if !exists {
|
||||
fieldDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, c.subsystem, name),
|
||||
fmt.Sprintf("%s value of /sys/class/net/<iface>.", name),
|
||||
fmt.Sprintf("Network device property: %s", name),
|
||||
[]string{"device"},
|
||||
nil,
|
||||
)
|
||||
|
|
|
@ -20,9 +20,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/jsimonetti/rtnetlink"
|
||||
"github.com/mdlayher/ethtool"
|
||||
|
@ -31,37 +29,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
netclassRTNLIgnoredDevices = kingpin.Flag("collector.netclass_rtnl.ignored-devices", "Regexp of net devices to ignore for netclass_rtnl collector.").Default("^$").String()
|
||||
netclassRTNLWithStats = kingpin.Flag("collector.netclass_rtnl.with-stats", "Expose the statistics for each network device, replacing netdev collector.").Bool()
|
||||
operstateStr = []string{
|
||||
netclassRTNLWithStats = kingpin.Flag("collector.netclass_rtnl.with-stats", "Expose the statistics for each network device, replacing netdev collector.").Bool()
|
||||
operstateStr = []string{
|
||||
"unknown", "notpresent", "down", "lowerlayerdown", "testing",
|
||||
"dormant", "up",
|
||||
}
|
||||
)
|
||||
|
||||
type netClassRTNLCollector struct {
|
||||
subsystem string
|
||||
ignoredDevicesPattern *regexp.Regexp
|
||||
metricDescs map[string]*prometheus.Desc
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCollector("netclass_rtnl", defaultDisabled, NewNetClassRTNLCollector)
|
||||
}
|
||||
|
||||
// NewNetClassCollector returns a new Collector exposing network class stats.
|
||||
func NewNetClassRTNLCollector(logger log.Logger) (Collector, error) {
|
||||
pattern := regexp.MustCompile(*netclassRTNLIgnoredDevices)
|
||||
return &netClassRTNLCollector{
|
||||
subsystem: "network",
|
||||
ignoredDevicesPattern: pattern,
|
||||
metricDescs: map[string]*prometheus.Desc{},
|
||||
logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *netClassRTNLCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
func (c *netClassCollector) netClassRTNLUpdate(ch chan<- prometheus.Metric) error {
|
||||
linkModes := make(map[string]*ethtool.LinkMode)
|
||||
lms, err := c.getLinkModes()
|
||||
if err != nil {
|
||||
|
@ -146,7 +121,7 @@ func (c *netClassRTNLCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
pushMetric(ch, c.getFieldDesc("transmit_queue_length"), "transmit_queue_length", msg.Attributes.TxQueueLen, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("protocol_type"), "protocol_type", msg.Type, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
||||
// skip statistics if argument collector.netclass_rtnl.with-stats is false or statistics are unavailable.
|
||||
// Skip statistics if argument collector.netclass_rtnl.with-stats is false or statistics are unavailable.
|
||||
if netclassRTNLWithStats == nil || !*netclassRTNLWithStats || msg.Attributes.Stats64 == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -162,7 +137,7 @@ func (c *netClassRTNLCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
pushMetric(ch, c.getFieldDesc("multicast_total"), "multicast_total", msg.Attributes.Stats64.Multicast, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("collisions_total"), "collisions_total", msg.Attributes.Stats64.Collisions, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
||||
// detailed rx_errors
|
||||
// Detailed rx_errors.
|
||||
pushMetric(ch, c.getFieldDesc("receive_length_errors_total"), "receive_length_errors_total", msg.Attributes.Stats64.RXLengthErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("receive_over_errors_total"), "receive_over_errors_total", msg.Attributes.Stats64.RXOverErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("receive_crc_errors_total"), "receive_crc_errors_total", msg.Attributes.Stats64.RXCRCErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
@ -170,14 +145,14 @@ func (c *netClassRTNLCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
pushMetric(ch, c.getFieldDesc("receive_fifo_errors_total"), "receive_fifo_errors_total", msg.Attributes.Stats64.RXFIFOErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("receive_missed_errors_total"), "receive_missed_errors_total", msg.Attributes.Stats64.RXMissedErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
||||
// detailed tx_errors
|
||||
// Detailed tx_errors.
|
||||
pushMetric(ch, c.getFieldDesc("transmit_aborted_errors_total"), "transmit_aborted_errors_total", msg.Attributes.Stats64.TXAbortedErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("transmit_carrier_errors_total"), "transmit_carrier_errors_total", msg.Attributes.Stats64.TXCarrierErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("transmit_fifo_errors_total"), "transmit_fifo_errors_total", msg.Attributes.Stats64.TXFIFOErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("transmit_heartbeat_errors_total"), "transmit_heartbeat_errors_total", msg.Attributes.Stats64.TXHeartbeatErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("transmit_window_errors_total"), "transmit_window_errors_total", msg.Attributes.Stats64.TXWindowErrors, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
||||
// for cslip etc
|
||||
// For cslip, etc.
|
||||
pushMetric(ch, c.getFieldDesc("receive_compressed_total"), "receive_compressed_total", msg.Attributes.Stats64.RXCompressed, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("transmit_compressed_total"), "transmit_compressed_total", msg.Attributes.Stats64.TXCompressed, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
pushMetric(ch, c.getFieldDesc("receive_nohandler_total"), "receive_nohandler_total", msg.Attributes.Stats64.RXNoHandler, prometheus.GaugeValue, msg.Attributes.Name)
|
||||
|
@ -187,23 +162,7 @@ func (c *netClassRTNLCollector) Update(ch chan<- prometheus.Metric) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *netClassRTNLCollector) getFieldDesc(name string) *prometheus.Desc {
|
||||
fieldDesc, exists := c.metricDescs[name]
|
||||
|
||||
if !exists {
|
||||
fieldDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, c.subsystem, name),
|
||||
fmt.Sprintf("Network device property %s.", name),
|
||||
[]string{"device"},
|
||||
nil,
|
||||
)
|
||||
c.metricDescs[name] = fieldDesc
|
||||
}
|
||||
|
||||
return fieldDesc
|
||||
}
|
||||
|
||||
func (c *netClassRTNLCollector) getNetClassInfoRTNL() ([]rtnetlink.LinkMessage, error) {
|
||||
func (c *netClassCollector) getNetClassInfoRTNL() ([]rtnetlink.LinkMessage, error) {
|
||||
conn, err := rtnetlink.Dial(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -216,7 +175,7 @@ func (c *netClassRTNLCollector) getNetClassInfoRTNL() ([]rtnetlink.LinkMessage,
|
|||
|
||||
}
|
||||
|
||||
func (c *netClassRTNLCollector) getLinkModes() ([]*ethtool.LinkMode, error) {
|
||||
func (c *netClassCollector) getLinkModes() ([]*ethtool.LinkMode, error) {
|
||||
conn, err := ethtool.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright 2022 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !nonetclass && linux
|
||||
// +build !nonetclass,linux
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func pushMetric(ch chan<- prometheus.Metric, fieldDesc *prometheus.Desc, name string, value interface{}, valueType prometheus.ValueType, labelValues ...string) {
|
||||
var fVal float64
|
||||
switch val := value.(type) {
|
||||
case uint8:
|
||||
fVal = float64(val)
|
||||
case uint16:
|
||||
fVal = float64(val)
|
||||
case uint32:
|
||||
fVal = float64(val)
|
||||
case uint64:
|
||||
fVal = float64(val)
|
||||
case int64:
|
||||
fVal = float64(val)
|
||||
case *uint8:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint16:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint32:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *uint64:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
case *int64:
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
fVal = float64(*val)
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(fieldDesc, valueType, fVal, labelValues...)
|
||||
}
|
Loading…
Reference in a new issue