Scrape CPU latency stats from /proc/schedstat (#1389)
These are useful as a direct indication of CPU contention and task scheduler latency. Handy references: - https://github.com/torvalds/linux/blob/master/Documentation/scheduler/sched-stats.txt - https://doc.opensuse.org/documentation/leap/tuning/html/book.sle.tuning/cha.tuning.taskscheduler.html procfs is updated to pull in the enabling change: https://github.com/prometheus/procfs/pull/186 Signed-off-by: Phil Frost <phil@postmates.com>
This commit is contained in:
parent
777b751f90
commit
f693a71c06
13 changed files with 297 additions and 5 deletions
|
|
@ -2438,6 +2438,18 @@ node_qdisc_packets_total{device="wlan0",kind="fq"} 42
|
|||
# TYPE node_qdisc_requeues_total counter
|
||||
node_qdisc_requeues_total{device="eth0",kind="pfifo_fast"} 2
|
||||
node_qdisc_requeues_total{device="wlan0",kind="fq"} 1
|
||||
# HELP node_schedstat_running_seconds_total Number of seconds CPU spent running a process.
|
||||
# TYPE node_schedstat_running_seconds_total counter
|
||||
node_schedstat_running_seconds_total{cpu="0"} 2.045936778163039e+13
|
||||
node_schedstat_running_seconds_total{cpu="1"} 1.904686152592476e+13
|
||||
# HELP node_schedstat_timeslices_total Number of timeslices executed by CPU.
|
||||
# TYPE node_schedstat_timeslices_total counter
|
||||
node_schedstat_timeslices_total{cpu="0"} 4.767485306e+09
|
||||
node_schedstat_timeslices_total{cpu="1"} 5.145567945e+09
|
||||
# HELP node_schedstat_waiting_seconds_total Number of seconds spent by processing waiting for this CPU.
|
||||
# TYPE node_schedstat_waiting_seconds_total counter
|
||||
node_schedstat_waiting_seconds_total{cpu="0"} 3.43796328169361e+12
|
||||
node_schedstat_waiting_seconds_total{cpu="1"} 3.64107263788241e+12
|
||||
# HELP node_scrape_collector_duration_seconds node_exporter: Duration of a collector scrape.
|
||||
# TYPE node_scrape_collector_duration_seconds gauge
|
||||
# HELP node_scrape_collector_success node_exporter: Whether a collector succeeded.
|
||||
|
|
@ -2472,6 +2484,7 @@ node_scrape_collector_success{collector="nfsd"} 1
|
|||
node_scrape_collector_success{collector="pressure"} 1
|
||||
node_scrape_collector_success{collector="processes"} 1
|
||||
node_scrape_collector_success{collector="qdisc"} 1
|
||||
node_scrape_collector_success{collector="schedstat"} 1
|
||||
node_scrape_collector_success{collector="sockstat"} 1
|
||||
node_scrape_collector_success{collector="stat"} 1
|
||||
node_scrape_collector_success{collector="textfile"} 1
|
||||
|
|
|
|||
|
|
@ -2438,6 +2438,18 @@ node_qdisc_packets_total{device="wlan0",kind="fq"} 42
|
|||
# TYPE node_qdisc_requeues_total counter
|
||||
node_qdisc_requeues_total{device="eth0",kind="pfifo_fast"} 2
|
||||
node_qdisc_requeues_total{device="wlan0",kind="fq"} 1
|
||||
# HELP node_schedstat_running_seconds_total Number of seconds CPU spent running a process.
|
||||
# TYPE node_schedstat_running_seconds_total counter
|
||||
node_schedstat_running_seconds_total{cpu="0"} 2.045936778163039e+13
|
||||
node_schedstat_running_seconds_total{cpu="1"} 1.904686152592476e+13
|
||||
# HELP node_schedstat_timeslices_total Number of timeslices executed by CPU.
|
||||
# TYPE node_schedstat_timeslices_total counter
|
||||
node_schedstat_timeslices_total{cpu="0"} 4.767485306e+09
|
||||
node_schedstat_timeslices_total{cpu="1"} 5.145567945e+09
|
||||
# HELP node_schedstat_waiting_seconds_total Number of seconds spent by processing waiting for this CPU.
|
||||
# TYPE node_schedstat_waiting_seconds_total counter
|
||||
node_schedstat_waiting_seconds_total{cpu="0"} 3.43796328169361e+12
|
||||
node_schedstat_waiting_seconds_total{cpu="1"} 3.64107263788241e+12
|
||||
# HELP node_scrape_collector_duration_seconds node_exporter: Duration of a collector scrape.
|
||||
# TYPE node_scrape_collector_duration_seconds gauge
|
||||
# HELP node_scrape_collector_success node_exporter: Whether a collector succeeded.
|
||||
|
|
@ -2472,6 +2484,7 @@ node_scrape_collector_success{collector="nfsd"} 1
|
|||
node_scrape_collector_success{collector="pressure"} 1
|
||||
node_scrape_collector_success{collector="processes"} 1
|
||||
node_scrape_collector_success{collector="qdisc"} 1
|
||||
node_scrape_collector_success{collector="schedstat"} 1
|
||||
node_scrape_collector_success{collector="sockstat"} 1
|
||||
node_scrape_collector_success{collector="stat"} 1
|
||||
node_scrape_collector_success{collector="textfile"} 1
|
||||
|
|
|
|||
6
collector/fixtures/proc/schedstat
Normal file
6
collector/fixtures/proc/schedstat
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
version 15
|
||||
timestamp 15819019232
|
||||
cpu0 498494191 0 3533438552 2553969831 3853684107 2465731542 2045936778163039 343796328169361 4767485306
|
||||
domain0 00000000,00000003 212499247 210112015 1861015 1860405436 536440 369895 32599 210079416 25368550 24241256 384652 927363878 807233 6366 1647 24239609 2122447165 1886868564 121112060 2848625533 125678146 241025 1032026 1885836538 2545 12 2533 0 0 0 0 0 0 1387952561 21076581 0
|
||||
cpu1 518377256 0 4155211005 2778589869 10466382 2867629021 1904686152592476 364107263788241 5145567945
|
||||
domain0 00000000,00000003 217653037 215526982 1577949 1580427380 557469 393576 28538 215498444 28721913 27662819 371153 870843407 745912 5523 1639 27661180 2331056874 2107732788 111442342 652402556 123615235 196159 1045245 2106687543 2400 3 2397 0 0 0 0 0 0 1437804657 26220076 0
|
||||
94
collector/schedstat_linux.go
Normal file
94
collector/schedstat_linux.go
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2019 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.
|
||||
|
||||
package collector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/procfs"
|
||||
)
|
||||
|
||||
var (
|
||||
runningSecondsTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "schedstat", "running_seconds_total"),
|
||||
"Number of seconds CPU spent running a process.",
|
||||
[]string{"cpu"},
|
||||
nil,
|
||||
)
|
||||
|
||||
waitingSecondsTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "schedstat", "waiting_seconds_total"),
|
||||
"Number of seconds spent by processing waiting for this CPU.",
|
||||
[]string{"cpu"},
|
||||
nil,
|
||||
)
|
||||
|
||||
timeslicesTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "schedstat", "timeslices_total"),
|
||||
"Number of timeslices executed by CPU.",
|
||||
[]string{"cpu"},
|
||||
nil,
|
||||
)
|
||||
)
|
||||
|
||||
// NewSchedstatCollector returns a new Collector exposing task scheduler statistics
|
||||
func NewSchedstatCollector() (Collector, error) {
|
||||
fs, err := procfs.NewFS(*procPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open procfs: %v", err)
|
||||
}
|
||||
|
||||
return &schedstatCollector{fs: fs}, nil
|
||||
}
|
||||
|
||||
type schedstatCollector struct {
|
||||
fs procfs.FS
|
||||
}
|
||||
|
||||
func init() {
|
||||
registerCollector("schedstat", defaultEnabled, NewSchedstatCollector)
|
||||
}
|
||||
|
||||
func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error {
|
||||
stats, err := c.fs.Schedstat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cpu := range stats.CPUs {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
runningSecondsTotal,
|
||||
prometheus.CounterValue,
|
||||
cpu.RunningSeconds(),
|
||||
cpu.CPUNum,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
waitingSecondsTotal,
|
||||
prometheus.CounterValue,
|
||||
cpu.WaitingSeconds(),
|
||||
cpu.CPUNum,
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
timeslicesTotal,
|
||||
prometheus.CounterValue,
|
||||
float64(cpu.RunTimeslices),
|
||||
cpu.CPUNum,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue