|
|
@ -26,7 +26,7 @@ type Logger struct {
|
|
|
|
ctx context.Context
|
|
|
|
ctx context.Context
|
|
|
|
cancelFn context.CancelFunc
|
|
|
|
cancelFn context.CancelFunc
|
|
|
|
|
|
|
|
|
|
|
|
ticker time.Ticker
|
|
|
|
ticker *time.Ticker
|
|
|
|
logf logger.Logf
|
|
|
|
logf logger.Logf
|
|
|
|
logbuffer *filch.Filch
|
|
|
|
logbuffer *filch.Filch
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -52,7 +52,7 @@ type event struct {
|
|
|
|
|
|
|
|
|
|
|
|
// NewLogger returns a new Logger that will store stats in logdir.
|
|
|
|
// NewLogger returns a new Logger that will store stats in logdir.
|
|
|
|
// On platforms that do not support sockstat logging, a nil Logger will be returned.
|
|
|
|
// On platforms that do not support sockstat logging, a nil Logger will be returned.
|
|
|
|
// The returned Logger is not yet running.
|
|
|
|
// The returned Logger must be shut down with Shutdown when it is no longer needed.
|
|
|
|
func NewLogger(logdir string, logf logger.Logf) (*Logger, error) {
|
|
|
|
func NewLogger(logdir string, logf logger.Logf) (*Logger, error) {
|
|
|
|
if !sockstats.IsAvailable {
|
|
|
|
if !sockstats.IsAvailable {
|
|
|
|
return nil, nil
|
|
|
|
return nil, nil
|
|
|
@ -68,17 +68,17 @@ func NewLogger(logdir string, logf logger.Logf) (*Logger, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
return &Logger{
|
|
|
|
logger := &Logger{
|
|
|
|
ctx: ctx,
|
|
|
|
ctx: ctx,
|
|
|
|
cancelFn: cancel,
|
|
|
|
cancelFn: cancel,
|
|
|
|
ticker: *time.NewTicker(pollPeriod),
|
|
|
|
ticker: time.NewTicker(pollPeriod),
|
|
|
|
logf: logf,
|
|
|
|
logf: logf,
|
|
|
|
logbuffer: filch,
|
|
|
|
logbuffer: filch,
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *Logger) Start() {
|
|
|
|
go logger.poll()
|
|
|
|
go l.poll()
|
|
|
|
|
|
|
|
|
|
|
|
return logger, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// poll fetches the current socket stats at the configured time interval,
|
|
|
|
// poll fetches the current socket stats at the configured time interval,
|
|
|
|