Abbey Woodyear
2 years ago
committed by
GitHub
7 changed files with 177 additions and 0 deletions
@ -0,0 +1,11 @@ |
|||||||
|
CPU0 CPU1 |
||||||
|
HI: 7 1 |
||||||
|
TIMER: 424191 108342 |
||||||
|
NET_TX: 2301 2430 |
||||||
|
NET_RX: 43066 104508 |
||||||
|
BLOCK: 23776 24115 |
||||||
|
IRQ_POLL: 0 0 |
||||||
|
TASKLET: 372 1899 |
||||||
|
SCHED: 378895 152852 |
||||||
|
HRTIMER: 40 346 |
||||||
|
RCU: 155929 146631 |
@ -0,0 +1,68 @@ |
|||||||
|
// 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 !nosoftirqs
|
||||||
|
// +build !nosoftirqs
|
||||||
|
|
||||||
|
package collector |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"strconv" |
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus" |
||||||
|
) |
||||||
|
|
||||||
|
var ( |
||||||
|
softirqLabelNames = []string{"cpu", "type"} |
||||||
|
) |
||||||
|
|
||||||
|
func (c *softirqsCollector) Update(ch chan<- prometheus.Metric) (err error) { |
||||||
|
softirqs, err := c.fs.Softirqs() |
||||||
|
if err != nil { |
||||||
|
return fmt.Errorf("couldn't get softirqs: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
for cpuNo, value := range softirqs.Hi { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "HI") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.Timer { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "TIMER") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.NetTx { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "NET_TX") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.NetRx { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "NET_RX") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.Block { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "BLOCK") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.IRQPoll { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "IRQ_POLL") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.Tasklet { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "TASKLET") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.Sched { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "SCHED") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.HRTimer { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "HRTIMER") |
||||||
|
} |
||||||
|
for cpuNo, value := range softirqs.RCU { |
||||||
|
ch <- c.desc.mustNewConstMetric(float64(value), strconv.Itoa(cpuNo), "RCU") |
||||||
|
} |
||||||
|
|
||||||
|
return err |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
// 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 linux && !nosoftirqs
|
||||||
|
// +build linux,!nosoftirqs
|
||||||
|
|
||||||
|
package collector |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"github.com/go-kit/log" |
||||||
|
"github.com/prometheus/client_golang/prometheus" |
||||||
|
"github.com/prometheus/procfs" |
||||||
|
) |
||||||
|
|
||||||
|
type softirqsCollector struct { |
||||||
|
fs procfs.FS |
||||||
|
desc typedDesc |
||||||
|
logger log.Logger |
||||||
|
} |
||||||
|
|
||||||
|
func init() { |
||||||
|
registerCollector("softirqs", defaultDisabled, NewSoftirqsCollector) |
||||||
|
} |
||||||
|
|
||||||
|
// NewSoftirqsCollector returns a new Collector exposing softirq stats.
|
||||||
|
func NewSoftirqsCollector(logger log.Logger) (Collector, error) { |
||||||
|
desc := typedDesc{prometheus.NewDesc( |
||||||
|
namespace+"_softirqs_functions_total", |
||||||
|
"Softirq counts per CPU.", |
||||||
|
softirqLabelNames, nil, |
||||||
|
), prometheus.CounterValue} |
||||||
|
|
||||||
|
fs, err := procfs.NewFS(*procPath) |
||||||
|
if err != nil { |
||||||
|
return nil, fmt.Errorf("failed to open procfs: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
return &softirqsCollector{fs, desc, logger}, nil |
||||||
|
} |
Loading…
Reference in new issue