Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/theodesp/memwatch

Trips with an event when the runtime memory usage of the process is over the limit and exits after a while.
https://github.com/theodesp/memwatch

go memory-management

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

memwatch
---
[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#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

```go
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](https://github.com/kentcdodds/all-contributors#emoji-key)):

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

### LICENCE

Copyright © 2017 Theo Despoudis BSD license