Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collector/netisr_freebsd.go: Added collector for netisr subsystem #2668

Merged
merged 1 commit into from
May 11, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ mdadm | Exposes statistics about devices in `/proc/mdstat` (does nothing if no `
meminfo | Exposes memory statistics. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
netclass | Exposes network interface info from `/sys/class/net/` | Linux
netdev | Exposes network interface statistics such as bytes transferred. | Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
netisr | Exposes netisr statistics | FreeBSD
netstat | Exposes network statistics from `/proc/net/netstat`. This is the same information as `netstat -s`. | Linux
nfs | Exposes NFS client statistics from `/proc/net/rpc/nfs`. This is the same information as `nfsstat -c`. | Linux
nfsd | Exposes NFS kernel server statistics from `/proc/net/rpc/nfsd`. This is the same information as `nfsstat -s`. | Linux
Expand Down
105 changes: 105 additions & 0 deletions collector/netisr_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2023 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build freebsd && !nonetisr
// +build freebsd,!nonetisr

package collector

import (
"fmt"

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
)

type netisrCollector struct {
sysctls []bsdSysctl
logger log.Logger
}

const (
netisrCollectorSubsystem = "netisr"
)

func init() {
registerCollector("netisr", defaultEnabled, NewNetisrCollector)
}

func NewNetisrCollector(logger log.Logger) (Collector, error) {
return &netisrCollector{
sysctls: []bsdSysctl{
{
name: "numthreads",
description: "netisr current thread count",
mib: "net.isr.numthreads",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
{
name: "maxprot",
description: "netisr maximum protocols",
mib: "net.isr.maxprot",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
{
name: "defaultqlimit",
description: "netisr default queue limit",
mib: "net.isr.defaultqlimit",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
{
name: "maxqlimit",
description: "netisr maximum queue limit",
mib: "net.isr.maxqlimit",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
{
name: "bindthreads",
description: "netisr threads bound to CPUs",
mib: "net.isr.bindthreads",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
{
name: "maxthreads",
description: "netisr maximum thread count",
mib: "net.isr.maxthreads",
dataType: bsdSysctlTypeUint32,
valueType: prometheus.GaugeValue,
},
},
logger: logger,
}, nil
}

func (c *netisrCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return fmt.Errorf("couldn't get sysctl: %w", err)
}

ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, netisrCollectorSubsystem, m.name),
m.description,
nil, nil,
), m.valueType, v)
}

return nil
}