From a5d99c3aa8243dda44907741b083dcdf0a99e0b2 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Thu, 23 Apr 2015 19:04:58 -0700 Subject: [PATCH] Add /var/log/kern.log to kernel log files. This file is present in most distros and provides most of the logs we're looking for. We support the others if this one is not available. --- utils/oomparser/oomparser.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/utils/oomparser/oomparser.go b/utils/oomparser/oomparser.go index cf5c84fd..deafc273 100644 --- a/utils/oomparser/oomparser.go +++ b/utils/oomparser/oomparser.go @@ -16,7 +16,7 @@ package oomparser import ( "bufio" - "errors" + "fmt" "io" "os" "os/exec" @@ -187,17 +187,20 @@ func trySystemd() (*OomParser, error) { } +// List of possible kernel log files. These are prioritized in order so that +// we will use the first one that is available. +var kernelLogFiles = []string{"/var/log/kern.log", "/var/log/messages", "/var/log/syslog"} + // looks for system files that contain kernel messages and if one is found, sets // the systemFile attribute of the OomParser object func getSystemFile() (string, error) { - const varLogMessages = "/var/log/messages" - const varLogSyslog = "/var/log/syslog" - if utils.FileExists(varLogMessages) { - return varLogMessages, nil - } else if utils.FileExists(varLogSyslog) { - return varLogSyslog, nil + for _, logFile := range kernelLogFiles { + if utils.FileExists(logFile) { + glog.Infof("OOM parser using kernel log file: %q", logFile) + return logFile, nil + } } - return "", errors.New("neither " + varLogSyslog + " nor " + varLogMessages + " exists from which to read kernel errors") + return "", fmt.Errorf("unable to find any kernel log file available from our set: %v", kernelLogFiles) } // initializes an OomParser object and calls getSystemFile to set the systemFile