|
| 1 | +// Copyright 2024 The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +//go:build !nonetdev |
| 15 | +// +build !nonetdev |
| 16 | + |
| 17 | +package collector |
| 18 | + |
| 19 | +import ( |
| 20 | + "log/slog" |
| 21 | + |
| 22 | + "github.com/power-devops/perfstat" |
| 23 | +) |
| 24 | + |
| 25 | +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { |
| 26 | + netDev := netDevStats{} |
| 27 | + |
| 28 | + stats, err := perfstat.NetAdapterStat() |
| 29 | + if err != nil { |
| 30 | + return nil, err |
| 31 | + } |
| 32 | + |
| 33 | + for _, stat := range stats { |
| 34 | + netDev[stat.Name] = map[string]uint64{ |
| 35 | + "receive_packets": uint64(stat.RxPackets), |
| 36 | + "transmit_packets": uint64(stat.TxPackets), |
| 37 | + "receive_bytes": uint64(stat.RxBytes), |
| 38 | + "transmit_bytes": uint64(stat.TxBytes), |
| 39 | + "receive_errors": uint64(stat.RxErrors), |
| 40 | + "transmit_errors": uint64(stat.TxErrors), |
| 41 | + "receive_dropped": uint64(stat.RxPacketsDropped), |
| 42 | + "transmit_dropped": uint64(stat.TxPacketsDropped), |
| 43 | + "receive_multicast": uint64(stat.RxMulticastPackets), |
| 44 | + "transmit_multicast": uint64(stat.TxMulticastPackets), |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return netDev, nil |
| 49 | +} |
| 50 | + |
| 51 | +func getNetDevLabels() (map[string]map[string]string, error) { |
| 52 | + // to be implemented if needed |
| 53 | + return nil, nil |
| 54 | +} |
0 commit comments