Skip to content

Commit

Permalink
CBG-549: SGCollect collects stderr and stdout Linux (#4329)
Browse files Browse the repository at this point in the history
* CBG-549: SGCollect collects stderr and stdout Linux

* Pipe stdout and stderr to Event Error

* Switch log to info and collect with SGCollect
  • Loading branch information
JRascagneres authored and adamcfraser committed Nov 20, 2019
1 parent ef01c82 commit 5767c11
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions service/sg-windows/sg-service/sg-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const installLocation = "C:\\Program Files\\Couchbase\\Sync Gateway\\"
const defaultLogFilePath = installLocation + "var\\lib\\couchbase\\logs"

var logger service.Logger
var infoLogger systemLoggerError

type program struct {
ExePath string
Expand All @@ -40,7 +41,11 @@ func (p *program) startup() error {
p.SyncGateway = exec.Command(p.ExePath, "--defaultLogFilePath", defaultLogFilePath)
}

p.SyncGateway.Stdout = infoLogger
p.SyncGateway.Stderr = infoLogger

err := p.SyncGateway.Start()

if err != nil {
logger.Errorf("Failed to start Sync Gateway due to error %v", err)
return err
Expand Down Expand Up @@ -105,6 +110,15 @@ func main() {
log.Fatal(err)
}

systemLogger, err := s.SystemLogger(nil)
if err != nil {
log.Fatalf("Unable to setup system logger: %v", err)
}

infoLogger = systemLoggerError{
systemLogger: systemLogger,
}

switch {
case os.Args[1] == "install":
logger.Info("Installing Sync Gateway")
Expand Down Expand Up @@ -141,3 +155,12 @@ func main() {
}
logger.Infof("Exiting Sync Gateway service.")
}

type systemLoggerError struct {
systemLogger service.Logger
}

func (n systemLoggerError) Write(b []byte) (int, error) {
n.systemLogger.Info(string(b))
return len(b), nil
}
21 changes: 21 additions & 0 deletions tools/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ def make_event_log_task():
"/FORMAT:list" % locals())


def make_event_log_task_sg_info():
from datetime import datetime, timedelta

# I found that wmic ntevent can be extremely slow; so limiting the output
# to approximately last month
limit = datetime.today() - timedelta(days=31)
limit = limit.strftime('%Y%m%d000000.000000-000')

return WindowsTask("SG Event log",
"wmic ntevent where "
"\""
"SourceName='SyncGateway' and "
"TimeGenerated>'%(limit)s'"
"\" "
"get TimeGenerated,LogFile,SourceName,EventType,Message "
"/FORMAT:list" % locals())


def make_os_tasks(processes):
programs = " ".join(processes)

Expand Down Expand Up @@ -645,6 +663,8 @@ def make_os_tasks(processes):
UnixTask("Processor status", "mpstat 1 10"),
UnixTask("System log", "cat /var/adm/messages"),
LinuxTask("Raw /proc/uptime", "cat /proc/uptime"),
LinuxTask("Systemd journal", "journalctl 2>&1 | gzip -c",
log_file="systemd_journal.gz", no_header=True),
LinuxTask("All logs", "tar cz /var/log/syslog* /var/log/dmesg /var/log/messages* /var/log/daemon* /var/log/debug* /var/log/kern.log* 2>/dev/null",
log_file="syslog.tar.gz", no_header=True),
LinuxTask("Relevant proc data", "echo %(programs)s | "
Expand All @@ -663,6 +683,7 @@ def make_os_tasks(processes):
LinuxTask("Full raw netstat", "cat /proc/net/netstat"),
LinuxTask("CPU throttling info", "echo /sys/devices/system/cpu/cpu*/thermal_throttle/* | xargs -n1 -- sh -c 'echo $1; cat $1' --"),
make_event_log_task(),
make_event_log_task_sg_info(),
]

return _tasks
Expand Down

0 comments on commit 5767c11

Please sign in to comment.