Skip to content
/ go-psi Public

πŸ₯΅ Pressure Stall Informations (PSI) and starvation notifier

License

Notifications You must be signed in to change notification settings

samber/go-psi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Pressure stall informations (PSI) and starvation notifier

tag Go Version GoDoc Build Status Go report Coverage Contributors License

A few readings to getting started with PSI:

πŸš€ Install

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

Retrieve current PSI state

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

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

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

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

πŸ‘€ Contributors

Contributors

πŸ’« Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

πŸ“ License

Copyright Β© 2023 Samuel Berthe.

This project is MIT licensed.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy