Skip to content

Commit 45411b0

Browse files
committed
collector/netisr_freebsd.go: Added collector for netisr subsystem.
Signed-off-by: Jonathan Davies <[email protected]>
1 parent b87c6a8 commit 45411b0

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ mdadm | Exposes statistics about devices in `/proc/mdstat` (does nothing if no `
107107
meminfo | Exposes memory statistics. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
108108
netclass | Exposes network interface info from `/sys/class/net/` | Linux
109109
netdev | Exposes network interface statistics such as bytes transferred. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
110+
netisr | Exposes netisr statistics | FreeBSD
110111
netstat | Exposes network statistics from `/proc/net/netstat`. This is the same information as `netstat -s`. | Linux
111112
nfs | Exposes NFS client statistics from `/proc/net/rpc/nfs`. This is the same information as `nfsstat -c`. | Linux
112113
nfsd | Exposes NFS kernel server statistics from `/proc/net/rpc/nfsd`. This is the same information as `nfsstat -s`. | Linux

collector/netisr_freebsd.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2023 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 freebsd && !nonetisr
15+
// +build freebsd,!nonetisr
16+
17+
package collector
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/go-kit/log"
23+
"github.com/prometheus/client_golang/prometheus"
24+
)
25+
26+
type netisrCollector struct {
27+
sysctls []bsdSysctl
28+
logger log.Logger
29+
}
30+
31+
const (
32+
netisrCollectorSubsystem = "netisr"
33+
)
34+
35+
func init() {
36+
registerCollector("netisr", defaultEnabled, NewNetisrCollector)
37+
}
38+
39+
func NewNetisrCollector(logger log.Logger) (Collector, error) {
40+
return &netisrCollector{
41+
sysctls: []bsdSysctl{
42+
{
43+
name: "numthreads",
44+
description: "netisr current thread count",
45+
mib: "net.isr.numthreads",
46+
dataType: bsdSysctlTypeUint32,
47+
valueType: prometheus.GaugeValue,
48+
},
49+
{
50+
name: "maxprot",
51+
description: "netisr maximum protocols",
52+
mib: "net.isr.maxprot",
53+
dataType: bsdSysctlTypeUint32,
54+
valueType: prometheus.GaugeValue,
55+
},
56+
{
57+
name: "defaultqlimit",
58+
description: "netisr default queue limit",
59+
mib: "net.isr.defaultqlimit",
60+
dataType: bsdSysctlTypeUint32,
61+
valueType: prometheus.GaugeValue,
62+
},
63+
{
64+
name: "maxqlimit",
65+
description: "netisr maximum queue limit",
66+
mib: "net.isr.maxqlimit",
67+
dataType: bsdSysctlTypeUint32,
68+
valueType: prometheus.GaugeValue,
69+
},
70+
{
71+
name: "bindthreads",
72+
description: "netisr bound to CPUs",
73+
mib: "net.isr.bindthreads",
74+
dataType: bsdSysctlTypeUint32,
75+
valueType: prometheus.GaugeValue,
76+
},
77+
{
78+
name: "maxthreads",
79+
description: "netisr maximum thread count",
80+
mib: "net.isr.maxthreads",
81+
dataType: bsdSysctlTypeUint32,
82+
valueType: prometheus.GaugeValue,
83+
},
84+
},
85+
logger: logger,
86+
}, nil
87+
}
88+
89+
func (c *netisrCollector) Update(ch chan<- prometheus.Metric) error {
90+
for _, m := range c.sysctls {
91+
v, err := m.Value()
92+
if err != nil {
93+
return fmt.Errorf("couldn't get sysctl: %w", err)
94+
}
95+
96+
ch <- prometheus.MustNewConstMetric(
97+
prometheus.NewDesc(
98+
prometheus.BuildFQName(namespace, netisrCollectorSubsystem, m.name),
99+
m.description,
100+
nil, nil,
101+
), m.valueType, v)
102+
}
103+
104+
return nil
105+
}

0 commit comments

Comments
 (0)