Giter Site home page Giter Site logo

theodesp / memwatch Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 3.0 10 KB

Trips with an event when the runtime memory usage of the process is over the limit and exits after a while.

License: BSD 3-Clause "New" or "Revised" License

Makefile 7.09% Go 92.91%
go memory-management

memwatch's Introduction

memwatch

All Contributors

GoDoc License

Trips with an event when the runtime memory usage of the process is over the limit and exits after a while.

Installation

go get -u github/theodesp/memwatch

How To Use

package main

import (
	"fmt"
	"time"
	
	"github.com/theodesp/memwatch"
)

func main()  {
	watch := memwatch.New(&memwatch.WatchConfig{
		// Will cycle 10 times if memory is over the WarningLimit
		Cycle: 10,
		WarningLimit: 300 * memwatch.KiloByte,
		// Once we reach the CriticalLimit though we bail immediately
		CriticalLimit: 400 * memwatch.KiloByte,
		// Will exit after 2 seconds
		ExitTime: 2 * time.Second,
	})

	events := watch.Start()

	// Watch for memory overload
	boom := <-events

	// boom you have 2 seconds to evacuate
	fmt.Print(boom)
	time.Sleep(10 * time.Second) // too late!

	fmt.Println("clean up") // sorry won't happen!
}

API

  • Start(): Starts the monitor
  • Stop(): Stops the monitor

The code supports building under Go >= 1.8.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENCE

Copyright © 2017 Theo Despoudis BSD license

memwatch's People

Contributors

millerlogic avatar vhugo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

memwatch's Issues

Add Stop command

We should be able to stop and start again the watcher ideally

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.