https://github.com/samber/go-psi
🥵 Pressure Stall Informations (PSI) and starvation notifier
https://github.com/samber/go-psi
cgroup2 cgroups cpu go golang io linux load memory notification notifier performance pressure psi starvation workload
Last synced: 2 months ago
JSON representation
🥵 Pressure Stall Informations (PSI) and starvation notifier
- Host: GitHub
- URL: https://github.com/samber/go-psi
- Owner: samber
- License: mit
- Created: 2023-05-21T18:22:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-05T13:11:27.000Z (5 months ago)
- Last Synced: 2025-07-22T00:38:27.055Z (3 months ago)
- Topics: cgroup2, cgroups, cpu, go, golang, io, linux, load, memory, notification, notifier, performance, pressure, psi, starvation, workload
- Language: Go
- Homepage: https://pkg.go.dev/github.com/samber/go-psi
- Size: 44.9 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Pressure stall informations (PSI) and starvation notifier
[](https://github.com/samber/go-psi/releases)

[](https://pkg.go.dev/github.com/samber/go-psi)

[](https://goreportcard.com/report/github.com/samber/go-psi)
[](https://codecov.io/gh/samber/go-psi)
[](https://github.com/samber/go-psi/graphs/contributors)
[](./LICENSE)A few readings to getting started with PSI:
- https://docs.kernel.org/accounting/psi.html
- https://facebookmicrosites.github.io/psi/docs/overview
- https://unixism.net/2019/08/linux-pressure-stall-information-psi-by-example/## 🚀 Install
```sh
go get github.com/samber/go-psi
```This library is v1 and follows SemVer strictly. No breaking changes will be made to exported APIs before v2.0.0.
Requires Linux kernel >= 4.20.
## 💡 Usage
GoDoc: [https://pkg.go.dev/github.com/samber/go-psi](https://pkg.go.dev/github.com/samber/go-psi)
### Retrieve current PSI state
```go
import "github.com/samber/go-psi"// Get PSI for a single resource: psi.Memory or psi.CPU or psi.IO.
stats, err := psi.PSIStatsForResource(psi.Memory)// Get all PSI stats.
all, err := psi.AllPSIStats()
```### Get PSI change notifications
```go
import "github.com/samber/go-psi"onChange, done, err := psi.Notify(psi.Memory)
for {
last, _ := <-onChange
fmt.Printf("\nMemory:\n%s\n", last)
}// when you're done, just stop the notifier
done <- struct{}{}
```### Get PSI starvation alerts
```go
import "github.com/samber/go-psi"// Alert starts when CPU 10s average go further 90% and stops when CPU goes below 70%.
onAlert, done, err := psi.NotifyStarvation(psi.CPU, psi.Avg10, 70, 90)for {
alert, _ := <-onAlert
fmt.Printf("\nALERT %t\nCPU: %f%%\n", alert.Starved, alert.Current)
}// when you're done, just stop the notifier
done <- struct{}{}
```## 🤝 Contributing
- Ping me on Twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/go-psi)
- Fix [open issues](https://github.com/samber/go-psi/issues) or request new featuresDon't hesitate ;)
```bash
# Install some dev dependencies
make tools# Run tests
make test
# or
make watch-test
```## 👤 Contributors

## 💫 Show your support
Give a ⭐️ if this project helped you!
[](https://github.com/sponsors/samber)
## 📝 License
Copyright © 2023 [Samuel Berthe](https://github.com/samber).
This project is [MIT](./LICENSE) licensed.