Code Monkey home page Code Monkey logo

go-psi's Introduction

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.

go-psi's People

Contributors

samber avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

go-psi's Issues

Cgroup2 PSI

Adapt the current notifiers to listen to PSI from a single cgroup.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.