Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/theodesp/memwatch
- Owner: theodesp
- License: bsd-3-clause
- Created: 2018-10-23T16:53:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-02T14:44:27.000Z (almost 5 years ago)
- Last Synced: 2024-10-03T07:23:36.483Z (about 2 months ago)
- Topics: go, memory-management
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: Contributing.md
- License: LICENSE.md
Awesome Lists containing this project
README
memwatch
---
[![All Contributors](https://img.shields.io/badge/all_contributors-0-orange.svg?style=flat-square)](#contributors)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 mainimport (
"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 monitorThe 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