Cleanup kmsg log wather.

This commit is contained in:
Random-Liu
2017-05-30 15:58:45 -07:00
parent be6c516cfd
commit 51351f91b2
3 changed files with 9 additions and 29 deletions
+2 -2
View File
@@ -47,7 +47,7 @@ System log monitor supports different log management tools with different log
watchers: watchers:
* [filelog](./logwatchers/filelog): Log watcher for * [filelog](./logwatchers/filelog): Log watcher for
arbitrary file based log. arbitrary file based log.
* [journald](.//logwatchers/journald): Log watcher for * [journald](.//logwatchers/journald): Log watcher for journald.
* [kmsg](./logwatchers/kmsg): Log watcher for the kernel ring buffer device, /dev/kmsg. * [kmsg](./logwatchers/kmsg): Log watcher for the kernel ring buffer device, /dev/kmsg.
Set `plugin` in the configuration file to specify log watcher. Set `plugin` in the configuration file to specify log watcher.
@@ -67,7 +67,7 @@ Log watcher specific configurations are configured in `pluginConfig`.
* timestampFormat: The format of the timestamp. The format string is the time * timestampFormat: The format of the timestamp. The format string is the time
`2006-01-02T15:04:05Z07:00` in the expected format. (See `2006-01-02T15:04:05Z07:00` in the expected format. (See
[golang timestamp format](https://golang.org/pkg/time/#pkg-constants)) [golang timestamp format](https://golang.org/pkg/time/#pkg-constants))
* **kmsg** * **kmsg**: No configuration for now.
### Change Log Path ### Change Log Path
@@ -17,7 +17,6 @@ limitations under the License.
package kmsg package kmsg
import ( import (
"bufio"
"fmt" "fmt"
"strings" "strings"
"time" "time"
@@ -32,10 +31,9 @@ import (
) )
type kernelLogWatcher struct { type kernelLogWatcher struct {
cfg types.WatcherConfig cfg types.WatcherConfig
logCh chan *logtypes.Log logCh chan *logtypes.Log
tomb *util.Tomb tomb *util.Tomb
reader *bufio.Reader
kmsgParser kmsgparser.Parser kmsgParser kmsgparser.Parser
clock utilclock.Clock clock utilclock.Clock
@@ -43,7 +41,6 @@ type kernelLogWatcher struct {
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg // NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher { func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
kmsgparser.NewParser()
return &kernelLogWatcher{ return &kernelLogWatcher{
cfg: cfg, cfg: cfg,
tomb: util.NewTomb(), tomb: util.NewTomb(),
@@ -92,7 +89,9 @@ func (k *kernelLogWatcher) watchLoop(lookback time.Duration) {
select { select {
case <-k.tomb.Stopping(): case <-k.tomb.Stopping():
glog.Infof("Stop watching kernel log") glog.Infof("Stop watching kernel log")
k.kmsgParser.Close() if err := k.kmsgParser.Close(); err != nil {
glog.Errorf("Failed to close kmsg parser: %v", err)
}
return return
case msg := <-kmsgs: case msg := <-kmsgs:
glog.V(5).Infof("got kernel message: %+v", msg) glog.V(5).Infof("got kernel message: %+v", msg)
@@ -102,7 +101,7 @@ func (k *kernelLogWatcher) watchLoop(lookback time.Duration) {
// Discard too old messages // Discard too old messages
if k.clock.Since(msg.Timestamp) > lookback { if k.clock.Since(msg.Timestamp) > lookback {
glog.V(5).Infof("throwing away msg %v for being too old: %v > %v", msg.Message, msg.Timestamp.String(), lookback.String()) glog.V(5).Infof("Throwing away msg %v for being too old: %v > %v", msg.Message, msg.Timestamp.String(), lookback.String())
continue continue
} }
@@ -17,7 +17,6 @@ limitations under the License.
package kmsg package kmsg
import ( import (
"io"
"testing" "testing"
"code.cloudfoundry.org/clock/fakeclock" "code.cloudfoundry.org/clock/fakeclock"
@@ -140,21 +139,3 @@ func TestWatch(t *testing.T) {
} }
} }
} }
type fakeKmsgReader struct {
logLines []string
}
func (r *fakeKmsgReader) Read(data []byte) (int, error) {
if len(r.logLines) == 0 {
return 0, io.EOF
}
l := r.logLines[0]
r.logLines = r.logLines[1:]
copy(data, []byte(l))
return len(l), nil
}
func (r *fakeKmsgReader) Close() error {
return nil
}