mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 04:06:24 +00:00
Merge pull request #112 from Random-Liu/cleanup-kmsg-log-watcher
Cleanup kmsg log watcher
This commit is contained in:
@@ -47,7 +47,7 @@ System log monitor supports different log management tools with different log
|
||||
watchers:
|
||||
* [filelog](./logwatchers/filelog): Log watcher for
|
||||
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.
|
||||
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
|
||||
`2006-01-02T15:04:05Z07:00` in the expected format. (See
|
||||
[golang timestamp format](https://golang.org/pkg/time/#pkg-constants))
|
||||
* **kmsg**
|
||||
* **kmsg**: No configuration for now.
|
||||
|
||||
### Change Log Path
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package kmsg
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -32,10 +31,9 @@ import (
|
||||
)
|
||||
|
||||
type kernelLogWatcher struct {
|
||||
cfg types.WatcherConfig
|
||||
logCh chan *logtypes.Log
|
||||
tomb *util.Tomb
|
||||
reader *bufio.Reader
|
||||
cfg types.WatcherConfig
|
||||
logCh chan *logtypes.Log
|
||||
tomb *util.Tomb
|
||||
|
||||
kmsgParser kmsgparser.Parser
|
||||
clock utilclock.Clock
|
||||
@@ -43,7 +41,6 @@ type kernelLogWatcher struct {
|
||||
|
||||
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
|
||||
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
|
||||
kmsgparser.NewParser()
|
||||
return &kernelLogWatcher{
|
||||
cfg: cfg,
|
||||
tomb: util.NewTomb(),
|
||||
@@ -92,7 +89,9 @@ func (k *kernelLogWatcher) watchLoop(lookback time.Duration) {
|
||||
select {
|
||||
case <-k.tomb.Stopping():
|
||||
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
|
||||
case msg := <-kmsgs:
|
||||
glog.V(5).Infof("got kernel message: %+v", msg)
|
||||
@@ -102,7 +101,7 @@ func (k *kernelLogWatcher) watchLoop(lookback time.Duration) {
|
||||
|
||||
// Discard too old messages
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package kmsg
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user