Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
enable:
- depguard
- misspell
- modernize
- revive
settings:
depguard:
Expand All @@ -17,11 +18,6 @@ linters:
# Used in HTTP handlers, any error is handled by the server itself.
exclude-functions:
- (net/http.ResponseWriter).Write
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true
exclusions:
generated: lax
presets:
Expand Down
4 changes: 2 additions & 2 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func DisableDefaultCollectors() {
// does not contain information about which flag called the action.
// See: https://github.com/alecthomas/kingpin/issues/294
func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error {
return func(ctx *kingpin.ParseContext) error {
return func(_ *kingpin.ParseContext) error {
forcedCollectors[collector] = true
return nil
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func IsNoDataError(err error) bool {
}

// 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 any, valueType prometheus.ValueType, labelValues ...string) {
func pushMetric(ch chan<- prometheus.Metric, fieldDesc *prometheus.Desc, value any, valueType prometheus.ValueType, labelValues ...string) {
var fVal float64
switch val := value.(type) {
case uint8:
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (c *cpuCollector) updateCPUStats(newStats map[int64]procfs.CPUStat) {
// Remove offline CPUs.
if len(newStats) != len(c.cpuStats) {
onlineCPUIds := slices.Collect(maps.Keys(newStats))
maps.DeleteFunc(c.cpuStats, func(key int64, item procfs.CPUStat) bool {
maps.DeleteFunc(c.cpuStats, func(key int64, _ procfs.CPUStat) bool {
return !slices.Contains(onlineCPUIds, key)
})
}
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_vulnerabilities_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
registerCollector(cpuVulnerabilitiesCollectorSubsystem, defaultDisabled, NewVulnerabilitySysfsCollector)
}

func NewVulnerabilitySysfsCollector(logger *slog.Logger) (Collector, error) {
func NewVulnerabilitySysfsCollector(_ *slog.Logger) (Collector, error) {
return &cpuVulnerabilitiesCollector{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion collector/diskstats_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
diskstatsDeviceExclude = kingpin.Flag(
"collector.diskstats.device-exclude",
"Regexp of diskstats devices to exclude (mutually exclusive to device-include).",
).Default(diskstatsDefaultIgnoredDevices).PreAction(func(c *kingpin.ParseContext) error {
).Default(diskstatsDefaultIgnoredDevices).PreAction(func(_ *kingpin.ParseContext) error {
diskstatsDeviceExcludeSet = true
return nil
}).String()
Expand Down
4 changes: 1 addition & 3 deletions collector/fibrechannel_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"

"github.com/prometheus/node_exporter/collector/utils"
)

const maxUint64 = ^uint64(0)
Expand Down Expand Up @@ -114,7 +112,7 @@ func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error {
infoValue := 1.0

// First push the Host values
ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, utils.SafeDereference(
ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, SafeDereference(
host.Name,
host.Speed,
host.PortState,
Expand Down
4 changes: 2 additions & 2 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
mountPointsExclude = kingpin.Flag(
"collector.filesystem.mount-points-exclude",
"Regexp of mount points to exclude for filesystem collector. (mutually exclusive to mount-points-include)",
).Default(defMountPointsExcluded).PreAction(func(c *kingpin.ParseContext) error {
).Default(defMountPointsExcluded).PreAction(func(_ *kingpin.ParseContext) error {
mountPointsExcludeSet = true
return nil
}).String()
Expand All @@ -52,7 +52,7 @@ var (
fsTypesExclude = kingpin.Flag(
"collector.filesystem.fs-types-exclude",
"Regexp of filesystem types to exclude for filesystem collector. (mutually exclusive to fs-types-include)",
).Default(defFSTypesExcluded).PreAction(func(c *kingpin.ParseContext) error {
).Default(defFSTypesExcluded).PreAction(func(_ *kingpin.ParseContext) error {
fsTypesExcludeSet = true
return nil
}).String()
Expand Down
8 changes: 3 additions & 5 deletions collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {

workerCount := max(*statWorkerCount, 1)

for i := 0; i < workerCount; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range workerCount {
wg.Go(func() {
for labels := range labelChan {
statChan <- c.processStat(labels)
}
}()
})
}

go func() {
Expand Down
22 changes: 7 additions & 15 deletions collector/hwmon_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log/slog"
"os"
"path/filepath"
"slices"
"testing"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -133,15 +134,6 @@ func newTestHwmonCollector() *hwMonCollector {
return &hwMonCollector{logger: slog.New(slog.NewTextHandler(io.Discard, nil))}
}

func contains(haystack []string, needle string) bool {
for _, h := range haystack {
if h == needle {
return true
}
}
return false
}

// Two hwmon entries sharing the same parent device — the configuration
// that triggered #3637 on ASUS WMI laptops — must produce distinct chip
// labels and not error during gather.
Expand Down Expand Up @@ -177,10 +169,10 @@ func TestHwmonDuplicateChipNamesAreDisambiguated(t *testing.T) {
t.Fatalf("gather: %v", err)
}

if !contains(chips, "platform_asus_nb_wmi_asus") {
if !slices.Contains(chips, "platform_asus_nb_wmi_asus") {
t.Errorf("expected disambiguated chip 'platform_asus_nb_wmi_asus', got %v", uniq(chips))
}
if !contains(chips, "platform_asus_nb_wmi_asus_wmi_sensors") {
if !slices.Contains(chips, "platform_asus_nb_wmi_asus_wmi_sensors") {
t.Errorf("expected disambiguated chip 'platform_asus_nb_wmi_asus_wmi_sensors', got %v", uniq(chips))
}
for _, chip := range chips {
Expand Down Expand Up @@ -217,10 +209,10 @@ func TestHwmonUniqueChipNamesAreUnchanged(t *testing.T) {
if err != nil {
t.Fatalf("gather: %v", err)
}
if !contains(chips, "platform_coretemp_0") {
if !slices.Contains(chips, "platform_coretemp_0") {
t.Errorf("expected platform_coretemp_0, got %v", uniq(chips))
}
if !contains(chips, "platform_coretemp_1") {
if !slices.Contains(chips, "platform_coretemp_1") {
t.Errorf("expected platform_coretemp_1, got %v", uniq(chips))
}
}
Expand Down Expand Up @@ -253,10 +245,10 @@ func TestHwmonDuplicateChipNamesWithSameNameFile(t *testing.T) {
if err != nil {
t.Fatalf("gather: %v", err)
}
if !contains(chips, "platform_asus_nb_wmi_hwmon3") {
if !slices.Contains(chips, "platform_asus_nb_wmi_hwmon3") {
t.Errorf("expected platform_asus_nb_wmi_hwmon3, got %v", uniq(chips))
}
if !contains(chips, "platform_asus_nb_wmi_hwmon4") {
if !slices.Contains(chips, "platform_asus_nb_wmi_hwmon4") {
t.Errorf("expected platform_asus_nb_wmi_hwmon4, got %v", uniq(chips))
}
}
Expand Down
4 changes: 1 addition & 3 deletions collector/interrupts_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"strconv"
"unsafe"

"github.com/prometheus/node_exporter/collector/utils"

"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -50,7 +48,7 @@ func intr(idx _C_int) (itr interrupt, err error) {
return
}
dev := *(*[128]byte)(unsafe.Pointer(&buf[0]))
itr.device = utils.SafeBytesToString(dev[:])
itr.device = SafeBytesToString(dev[:])

mib[2] = KERN_INTRCNT_VECTOR
buf, err = sysctl(mib[:])
Expand Down
34 changes: 17 additions & 17 deletions collector/netclass_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err

ch <- prometheus.MustNewConstMetric(infoDesc, prometheus.GaugeValue, infoValue, ifaceInfo.Name, ifaceInfo.Address, ifaceInfo.Broadcast, ifaceInfo.Duplex, ifaceInfo.OperState, getAdminState(ifaceInfo.Flags), ifaceInfo.IfAlias)

pushMetric(ch, c.getFieldDesc("address_assign_type"), "address_assign_type", ifaceInfo.AddrAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier"), "carrier", ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_changes_total"), "carrier_changes_total", ifaceInfo.CarrierChanges, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_up_changes_total"), "carrier_up_changes_total", ifaceInfo.CarrierUpCount, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_down_changes_total"), "carrier_down_changes_total", ifaceInfo.CarrierDownCount, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("device_id"), "device_id", ifaceInfo.DevID, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("dormant"), "dormant", ifaceInfo.Dormant, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("flags"), "flags", ifaceInfo.Flags, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_id"), "iface_id", ifaceInfo.IfIndex, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_link"), "iface_link", ifaceInfo.IfLink, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_link_mode"), "iface_link_mode", ifaceInfo.LinkMode, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("mtu_bytes"), "mtu_bytes", ifaceInfo.MTU, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("name_assign_type"), "name_assign_type", ifaceInfo.NameAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("net_dev_group"), "net_dev_group", ifaceInfo.NetDevGroup, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("address_assign_type"), ifaceInfo.AddrAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier"), ifaceInfo.Carrier, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_changes_total"), ifaceInfo.CarrierChanges, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_up_changes_total"), ifaceInfo.CarrierUpCount, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("carrier_down_changes_total"), ifaceInfo.CarrierDownCount, prometheus.CounterValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("device_id"), ifaceInfo.DevID, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("dormant"), ifaceInfo.Dormant, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("flags"), ifaceInfo.Flags, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_id"), ifaceInfo.IfIndex, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_link"), ifaceInfo.IfLink, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("iface_link_mode"), ifaceInfo.LinkMode, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("mtu_bytes"), ifaceInfo.MTU, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("name_assign_type"), ifaceInfo.NameAssignType, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("net_dev_group"), ifaceInfo.NetDevGroup, prometheus.GaugeValue, ifaceInfo.Name)

if ifaceInfo.Speed != nil {
// Some devices return -1 if the speed is unknown.
if *ifaceInfo.Speed >= 0 || !*netclassInvalidSpeed {
speedBytes := int64(*ifaceInfo.Speed * 1000 * 1000 / 8)
pushMetric(ch, c.getFieldDesc("speed_bytes"), "speed_bytes", speedBytes, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("speed_bytes"), speedBytes, prometheus.GaugeValue, ifaceInfo.Name)
}
}

pushMetric(ch, c.getFieldDesc("transmit_queue_length"), "transmit_queue_length", ifaceInfo.TxQueueLen, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("protocol_type"), "protocol_type", ifaceInfo.Type, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("transmit_queue_length"), ifaceInfo.TxQueueLen, prometheus.GaugeValue, ifaceInfo.Name)
pushMetric(ch, c.getFieldDesc("protocol_type"), ifaceInfo.Type, prometheus.GaugeValue, ifaceInfo.Name)

}

Expand Down
Loading
Loading