Skip to content

Commit

Permalink
Add node_softirqs_total metric (prometheus#2221)
Browse files Browse the repository at this point in the history
This adds a new Linux metric, node_softirqs_total, which corresponds
to the 'softirq' line in /proc/stat. This metric is disabled by
default and it can be enabled with '--collector.stat.softirq'.

Signed-off-by: Jacob Vosmaer <[email protected]>
  • Loading branch information
jacobvosmaer authored and oblitorum committed Apr 9, 2024
1 parent 1ac3167 commit 1ab45bf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3349,6 +3349,18 @@ node_sockstat_UDP_mem_bytes 0
# HELP node_sockstat_sockets_used Number of IPv4 sockets in use.
# TYPE node_sockstat_sockets_used gauge
node_sockstat_sockets_used 229
# HELP node_softirqs_total Number of softirq calls.
# TYPE node_softirqs_total counter
node_softirqs_total{vector="block"} 186066
node_softirqs_total{vector="block_iopoll"} 0
node_softirqs_total{vector="hi"} 250191
node_softirqs_total{vector="hrtimer"} 12499
node_softirqs_total{vector="net_rx"} 211099
node_softirqs_total{vector="net_tx"} 1647
node_softirqs_total{vector="rcu"} 508444
node_softirqs_total{vector="sched"} 622196
node_softirqs_total{vector="tasklet"} 1.783454e+06
node_softirqs_total{vector="timer"} 1.481983e+06
# HELP node_softnet_dropped_total Number of dropped packets
# TYPE node_softnet_dropped_total counter
node_softnet_dropped_total{cpu="0"} 0
Expand Down
31 changes: 31 additions & 0 deletions collector/stat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
"gopkg.in/alecthomas/kingpin.v2"
)

type statCollector struct {
Expand All @@ -32,9 +33,12 @@ type statCollector struct {
btime *prometheus.Desc
procsRunning *prometheus.Desc
procsBlocked *prometheus.Desc
softIRQ *prometheus.Desc
logger log.Logger
}

var statSoftirqFlag = kingpin.Flag("collector.stat.softirq", "Export softirq calls per vector").Default("false").Bool()

func init() {
registerCollector("stat", defaultEnabled, NewStatCollector)
}
Expand Down Expand Up @@ -77,6 +81,11 @@ func NewStatCollector(logger log.Logger) (Collector, error) {
"Number of processes blocked waiting for I/O to complete.",
nil, nil,
),
softIRQ: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "softirqs_total"),
"Number of softirq calls.",
[]string{"vector"}, nil,
),
logger: logger,
}, nil
}
Expand All @@ -97,5 +106,27 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric(c.procsRunning, prometheus.GaugeValue, float64(stats.ProcessesRunning))
ch <- prometheus.MustNewConstMetric(c.procsBlocked, prometheus.GaugeValue, float64(stats.ProcessesBlocked))

if *statSoftirqFlag {
si := stats.SoftIRQ

for _, vec := range []struct {
name string
value uint64
}{
{name: "hi", value: si.Hi},
{name: "timer", value: si.Timer},
{name: "net_tx", value: si.NetTx},
{name: "net_rx", value: si.NetRx},
{name: "block", value: si.Block},
{name: "block_iopoll", value: si.BlockIoPoll},
{name: "tasklet", value: si.Tasklet},
{name: "sched", value: si.Sched},
{name: "hrtimer", value: si.Hrtimer},
{name: "rcu", value: si.Rcu},
} {
ch <- prometheus.MustNewConstMetric(c.softIRQ, prometheus.CounterValue, float64(vec.value), vec.name)
}
}

return nil
}
1 change: 1 addition & 0 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fi
--collector.cpu.info \
--collector.cpu.info.flags-include="^(aes|avx.?|constant_tsc)$" \
--collector.cpu.info.bugs-include="^(cpu_meltdown|spectre_.*|mds)$" \
--collector.stat.softirq \
--web.listen-address "127.0.0.1:${port}" \
--log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &

Expand Down

0 comments on commit 1ab45bf

Please sign in to comment.