-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: prometheus/procfs#186 Signed-off-by: Phil Frost <phil@postmates.com>
- Loading branch information
Showing
13 changed files
with
297 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ enabled_collectors=$(cat << COLLECTORS | |
nfsd | ||
pressure | ||
qdisc | ||
schedstat | ||
sockstat | ||
stat | ||
textfile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters