Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/scollector: Make MaxMem kill switch configurable #1652

Merged
merged 1 commit into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/scollector/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type Conf struct {
BatchSize int
// MaxQueueLen is the number of metrics keept internally.
MaxQueueLen int
// MaxMem is the maximum number of megabytes that can be allocated
// before scollector panics (shuts down). Default of 500 MB. This
// is a saftey mechanism to protect the host from the monitoring
// agent
MaxMem uint64
// Filter filters collectors matching these terms.
Filter []string
// PProf is an IP:Port binding to be used for debugging with pprof package.
Expand Down
13 changes: 8 additions & 5 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,17 @@ func main() {
}
collect.MaxQueueLen = conf.MaxQueueLen
}

maxMemMegaBytes := uint64(500)
if conf.MaxMem != 0 {
maxMemMegaBytes = conf.MaxMem
}
go func() {
const maxMem = 500 * 1024 * 1024 // 500MB
maxMemBytes := maxMemMegaBytes * 1024 * 1024
var m runtime.MemStats
for range time.Tick(time.Minute) {
for range time.Tick(time.Second * 30) {
runtime.ReadMemStats(&m)
if m.Alloc > maxMem {
panic("memory max reached")
if m.Alloc > maxMemBytes {
panic(fmt.Sprintf("memory max reached: (current: %v bytes, max: %v bytes)", m.Alloc, maxMemBytes))
}
}
}()
Expand Down