Skip to content

Commit

Permalink
Merge branch 'master' into marctc/refactor_kingpin
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc committed Sep 27, 2023
2 parents 97ddc9b + e8c5110 commit 58bc86d
Show file tree
Hide file tree
Showing 57 changed files with 416 additions and 96 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ executors:
# should also be updated.
golang:
docker:
- image: cimg/go:1.20
- image: cimg/go:1.21
arm:
machine:
image: ubuntu-2004:current
image: ubuntu-2204:current
resource_class: arm.medium

jobs:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- run: git diff --exit-code
build:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2204:current
parallelism: 3
steps:
- prometheus/setup_environment
Expand All @@ -58,7 +58,7 @@ jobs:
destination: /build
test_docker:
machine:
image: ubuntu-2204:2022.04.2
image: ubuntu-2204:current
environment:
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.18-base
REPO_PATH: github.com/prometheus/node_exporter
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: install Go
uses: actions/setup-go@v3
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version: 1.20.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@v3.4.0
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: v1.53.3
version: v1.54.2
2 changes: 1 addition & 1 deletion .promu-cgo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu.yml should also be updated.
version: 1.20
version: 1.21
cgo: true
repository:
path: github.com/prometheus/node_exporter
Expand Down
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu-cgo.yml should also be updated.
version: 1.20
version: 1.21
repository:
path: github.com/prometheus/node_exporter
build:
Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.53.3
GOLANGCI_LINT_VERSION ?= v1.54.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ buddyinfo | Exposes statistics of memory fragments as reported by /proc/buddyinf
cgroups | A summary of the number of active and enabled cgroups | Linux
cpu\_vulnerabilities | Exposes CPU vulnerability information from sysfs. | Linux
devstat | Exposes device statistics | Dragonfly, FreeBSD
drm | Expose GPU metrics using sysfs / DRM, `amdgpu` is the only driver which exposes this information through DRM | Linux
drbd | Exposes Distributed Replicated Block Device statistics (to version 8.4) | Linux
ethtool | Exposes network interface information and network driver statistics equivalent to `ethtool`, `ethtool -S`, and `ethtool -i`. | Linux
interrupts | Exposes detailed interrupts statistics. | Linux, OpenBSD
Expand Down
66 changes: 62 additions & 4 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@
package collector

import (
"errors"
"fmt"
"net"

"github.com/go-kit/log"
"github.com/jsimonetti/rtnetlink"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
"golang.org/x/sys/unix"
)

type arpCollector struct {
fs procfs.FS
deviceFilter deviceFilter
entries *prometheus.Desc
logger log.Logger
config NodeCollectorConfig
}

func init() {
Expand All @@ -38,6 +43,7 @@ func init() {
type ArpConfig struct {
DeviceInclude *string
DeviceExclude *string
Netlink *bool
}

// NewARPCollector returns a new Collector exposing ARP stats.
Expand Down Expand Up @@ -69,13 +75,65 @@ func getTotalArpEntries(deviceEntries []procfs.ARPEntry) map[string]uint32 {
return entries
}

func (c *arpCollector) Update(ch chan<- prometheus.Metric) error {
entries, err := c.fs.GatherARPEntries()
func getTotalArpEntriesRTNL() (map[string]uint32, error) {
conn, err := rtnetlink.Dial(nil)
if err != nil {
return nil, err
}
defer conn.Close()

neighbors, err := conn.Neigh.List()
if err != nil {
return fmt.Errorf("could not get ARP entries: %w", err)
return nil, err
}

ifIndexEntries := make(map[uint32]uint32)

for _, n := range neighbors {
// Neighbors will also contain IPv6 neighbors, but since this is purely an ARP collector,
// restrict to AF_INET. Also skip entries which have state NUD_NOARP to conform to output
// of /proc/net/arp.
if n.Family == unix.AF_INET && n.State&unix.NUD_NOARP == 0 {
ifIndexEntries[n.Index]++
}
}

enumEntries := make(map[string]uint32)

// Convert interface indexes to names.
for ifIndex, entryCount := range ifIndexEntries {
iface, err := net.InterfaceByIndex(int(ifIndex))
if err != nil {
if errors.Unwrap(err).Error() == "no such network interface" {
continue
}
return nil, err
}

enumEntries[iface.Name] = entryCount
}

enumeratedEntry := getTotalArpEntries(entries)
return enumEntries, nil
}

func (c *arpCollector) Update(ch chan<- prometheus.Metric) error {
var enumeratedEntry map[string]uint32

if *c.config.Arp.Netlink {
var err error

enumeratedEntry, err = getTotalArpEntriesRTNL()
if err != nil {
return fmt.Errorf("could not get ARP entries: %w", err)
}
} else {
entries, err := c.fs.GatherARPEntries()
if err != nil {
return fmt.Errorf("could not get ARP entries: %w", err)
}

enumeratedEntry = getTotalArpEntries(entries)
}

for device, entryCount := range enumeratedEntry {
if c.deviceFilter.ignored(device) {
Expand Down
3 changes: 3 additions & 0 deletions collector/bonding_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nobonding
// +build !nobonding

package collector

import (
Expand Down
4 changes: 2 additions & 2 deletions collector/boot_time_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build solaris && !noboottime
// +build solaris,!noboottime
//go:build !noboottime
// +build !noboottime

package collector

Expand Down
1 change: 1 addition & 0 deletions collector/btrfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error)
"err", err)
continue
}
defer fs.Close()

fsInfo, err := fs.Info()
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type cpuCollector struct {
fs procfs.FS
cpu *prometheus.Desc
cpuInfo *prometheus.Desc
cpuFrequencyHz *prometheus.Desc
cpuFlagsInfo *prometheus.Desc
cpuBugsInfo *prometheus.Desc
cpuGuest *prometheus.Desc
Expand Down Expand Up @@ -100,6 +101,11 @@ func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector,
"CPU information from /proc/cpuinfo.",
[]string{"package", "core", "cpu", "vendor", "family", "model", "model_name", "microcode", "stepping", "cachesize"}, nil,
),
cpuFrequencyHz: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "frequency_hertz"),
"CPU frequency in hertz from /proc/cpuinfo.",
[]string{"package", "core", "cpu"}, nil,
),
cpuFlagsInfo: prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "flag_info"),
"The `flags` field of CPU information from /proc/cpuinfo taken from the first core.",
Expand Down Expand Up @@ -202,6 +208,20 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
cpu.CacheSize)
}

cpuFreqEnabled, ok := collectorState["cpufreq"]
if !ok || cpuFreqEnabled == nil {
level.Debug(c.logger).Log("cpufreq key missing or nil value in collectorState map", err)
} else if !*cpuFreqEnabled {
for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
prometheus.GaugeValue,
cpu.CPUMHz*1e6,
cpu.PhysicalID,
cpu.CoreID,
strconv.Itoa(int(cpu.Processor)))
}
}

if len(info) != 0 {
cpu := info[0]
if err := updateFieldInfo(cpu.Flags, c.cpuFlagsIncludeRegexp, c.cpuFlagsInfo, ch); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions collector/cpu_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build solaris && !nocpu
// +build solaris,!nocpu
//go:build !nocpu
// +build !nocpu

package collector

Expand Down
4 changes: 2 additions & 2 deletions collector/cpufreq_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build solaris && !nocpu
// +build solaris,!nocpu
//go:build !nocpu
// +build !nocpu

package collector

Expand Down
3 changes: 3 additions & 0 deletions collector/diskstats_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nodiskstats
// +build !nodiskstats

package collector

import (
Expand Down
4 changes: 2 additions & 2 deletions collector/diskstats_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build openbsd && !amd64 && !nodiskstats
// +build openbsd,!amd64,!nodiskstats
//go:build !nodiskstats && !amd64
// +build !nodiskstats,!amd64

package collector

Expand Down
3 changes: 3 additions & 0 deletions collector/ethtool_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !noethtool
// +build !noethtool

package collector

import (
Expand Down
6 changes: 6 additions & 0 deletions collector/exec_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,37 @@ func NewExecCollector(config NodeCollectorConfig, logger log.Logger) (Collector,
name: "exec_context_switches_total",
description: "Context switches since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_swtch",
labels: nil,
},
{
name: "exec_traps_total",
description: "Traps since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_trap",
labels: nil,
},
{
name: "exec_system_calls_total",
description: "System calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_syscall",
},
labels: nil,
{
name: "exec_device_interrupts_total",
description: "Device interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_intr",
labels: nil,
},
{
name: "exec_software_interrupts_total",
description: "Software interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_soft",
labels: nil,
},
{
name: "exec_forks_total",
description: "Number of fork() calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.vm.v_forks",
labels: nil,
},
},
logger: logger,
Expand Down
4 changes: 2 additions & 2 deletions collector/fibrechannel_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux && !nofibrechannel
// +build linux,!nofibrechannel
//go:build !nofibrechannel
// +build !nofibrechannel

package collector

Expand Down
3 changes: 3 additions & 0 deletions collector/filefd_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !nofilefd
// +build !nofilefd

package collector

import "testing"
Expand Down
9 changes: 5 additions & 4 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
c.deviceErrorDesc, prometheus.GaugeValue,
s.deviceError, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
ch <- prometheus.MustNewConstMetric(
c.roDesc, prometheus.GaugeValue,
s.ro, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)

if s.deviceError > 0 {
continue
}
Expand All @@ -205,10 +210,6 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
c.filesFreeDesc, prometheus.GaugeValue,
s.filesFree, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
ch <- prometheus.MustNewConstMetric(
c.roDesc, prometheus.GaugeValue,
s.ro, s.labels.device, s.labels.mountPoint, s.labels.fsType,
)
}
return nil
}
Loading

0 comments on commit 58bc86d

Please sign in to comment.