dispatch: generate warning if messages are being dropped

This commit is contained in:
Aaron Meihm 2017-09-07 09:37:27 -05:00
Родитель 263c517f1d
Коммит ab29f79ae9
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -16,6 +16,7 @@ import (
"fmt"
"net/http"
"runtime"
"time"
"mig.ninja/mig"
"mig.ninja/mig/modules"
@ -61,6 +62,10 @@ var agtHostname string
// runDispatch
var messageBuf chan string
// lastDrop stores the last time a message was dropped by the dispatch module
var lastDrop time.Time
var dropCounter int
// Dispatch record describes the formatting of JSON data submitted from the dispatch
// module.
type DispatchRecord struct {
@ -128,7 +133,15 @@ func dispatchIn(msg string) {
select {
case messageBuf <- msg:
default:
dropCounter++
// If we can't queue the message it is just dropped
now := time.Now()
if now.After(lastDrop.Add(time.Duration(time.Minute * 5))) {
logChan <- fmt.Sprintf("warning, dispatch module dropping messages "+
"(buffer full, %v dropped since last warning)", dropCounter)
lastDrop = now
dropCounter = 0
}
}
}