Skip to content

Commit 6e35bcf

Browse files
authored
Merge pull request #88 from Random-Liu/add-arbitray-log-support
Add arbitray system log support
2 parents 5e56393 + 01334e7 commit 6e35bcf

20 files changed

+1207
-202
lines changed

Godeps/Godeps.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/docker-monitor-filelog.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"plugin": "syslog",
3+
"pluginConfig": {
4+
"timestamp": "^time=\"(\\S*)\"",
5+
"message": "msg=\"([^\n]*)\"",
6+
"timestampFormat": "2006-01-02T15:04:05.999999999-07:00"
7+
},
8+
"logPath": "/var/log/docker.log",
9+
"lookback": "5m",
10+
"bufferSize": 10,
11+
"source": "docker-monitor",
12+
"conditions": [],
13+
"rules": []
14+
}

config/docker-monitor.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"plugin": "journald",
3+
"pluginConfig": {
4+
"source": "docker"
5+
},
6+
"logPath": "/var/log/journal",
7+
"lookback": "5m",
8+
"bufferSize": 10,
9+
"source": "docker-monitor",
10+
"conditions": [],
11+
"rules": []
12+
}

config/kernel-monitor-filelog.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"plugin": "syslog",
3+
"pluginConfig": {
4+
"timestamp": "^.{15}",
5+
"message": "kernel: \\[.*\\] (.*)",
6+
"timestampFormat": "Jan _2 15:04:05"
7+
},
8+
"logPath": "/var/log/kern.log",
9+
"lookback": "5m",
10+
"bufferSize": 10,
11+
"source": "kernel-monitor",
12+
"conditions": [
13+
{
14+
"type": "KernelDeadlock",
15+
"reason": "KernelHasNoDeadlock",
16+
"message": "kernel has no deadlock"
17+
}
18+
],
19+
"rules": [
20+
{
21+
"type": "temporary",
22+
"reason": "OOMKilling",
23+
"pattern": "Kill process \\d+ (.+) score \\d+ or sacrifice child\\nKilled process \\d+ (.+) total-vm:\\d+kB, anon-rss:\\d+kB, file-rss:\\d+kB"
24+
},
25+
{
26+
"type": "temporary",
27+
"reason": "TaskHung",
28+
"pattern": "task \\S+:\\w+ blocked for more than \\w+ seconds\\."
29+
},
30+
{
31+
"type": "temporary",
32+
"reason": "UnregisterNetDevice",
33+
"pattern": "unregister_netdevice: waiting for \\w+ to become free. Usage count = \\d+"
34+
},
35+
{
36+
"type": "temporary",
37+
"reason": "KernelOops",
38+
"pattern": "BUG: unable to handle kernel NULL pointer dereference at .*"
39+
},
40+
{
41+
"type": "temporary",
42+
"reason": "KernelOops",
43+
"pattern": "divide error: 0000 \\[#\\d+\\] SMP"
44+
},
45+
{
46+
"type": "permanent",
47+
"condition": "KernelDeadlock",
48+
"reason": "AUFSUmountHung",
49+
"pattern": "task umount\\.aufs:\\w+ blocked for more than \\w+ seconds\\."
50+
},
51+
{
52+
"type": "permanent",
53+
"condition": "KernelDeadlock",
54+
"reason": "DockerHung",
55+
"pattern": "task docker:\\w+ blocked for more than \\w+ seconds\\."
56+
}
57+
]
58+
}

config/kernel-monitor.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"plugin": "journald",
3+
"pluginConfig": {
4+
"source": "kernel"
5+
},
36
"logPath": "/var/log/journal",
47
"lookback": "5m",
58
"bufferSize": 10,

pkg/kernelmonitor/logwatchers/journald/log_watcher.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ func (j *journaldWatcher) watchLoop() {
114114
}
115115
}
116116

117-
// defaultJournalLogPath is the default path of journal log.
118-
const defaultJournalLogPath = "/var/log/journal"
117+
const (
118+
// defaultJournalLogPath is the default path of journal log.
119+
defaultJournalLogPath = "/var/log/journal"
120+
121+
// configSourceKey is the key of source configuration in the plugin configuration.
122+
configSourceKey = "source"
123+
)
119124

120125
// getJournal returns a journal client.
121126
func getJournal(cfg types.WatcherConfig) (*sdjournal.Journal, error) {
@@ -140,14 +145,18 @@ func getJournal(cfg types.WatcherConfig) (*sdjournal.Journal, error) {
140145
if err != nil {
141146
return nil, fmt.Errorf("failed to lookback %q: %v", since, err)
142147
}
143-
// TODO(random-liu): Make this configurable to support parsing other logs.
144-
kernelMatch := sdjournal.Match{
145-
Field: sdjournal.SD_JOURNAL_FIELD_TRANSPORT,
146-
Value: "kernel",
148+
// Empty source is not allowed and treated as an error.
149+
source := cfg.PluginConfig[configSourceKey]
150+
if source == "" {
151+
return nil, fmt.Errorf("failed to filter journal log, empty source is not allowed")
152+
}
153+
match := sdjournal.Match{
154+
Field: sdjournal.SD_JOURNAL_FIELD_SYSLOG_IDENTIFIER,
155+
Value: source,
147156
}
148-
err = journal.AddMatch(kernelMatch.String())
157+
err = journal.AddMatch(match.String())
149158
if err != nil {
150-
return nil, fmt.Errorf("failed to add log filter %#v: %v", kernelMatch, err)
159+
return nil, fmt.Errorf("failed to add log filter %#v: %v", match, err)
151160
}
152161
return journal, nil
153162
}

pkg/kernelmonitor/logwatchers/syslog/helpers.go

Lines changed: 0 additions & 102 deletions
This file was deleted.

pkg/kernelmonitor/logwatchers/syslog/helpers_test.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)