Skip to content

Commit

Permalink
Log system details to aid in debugging
Browse files Browse the repository at this point in the history
This adds logging of system information to provide more situational awareness when debugging. When a Beat starts it will log data about the host, process, build, and go runtime.

One goal is to help resolve issues faster because there will be fewer back-and-forths. When logs are provided by the user there wouldn't be a need for questions like "how did you run it", "what OS", "what kernel", "what kind of hardware", "are you running in Docker", "what is the machine's local timezone", etc.

Closes #5946
  • Loading branch information
andrewkroh authored and ruflin committed Apr 6, 2018
1 parent d2f4262 commit 26c4fc9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Add add_host_metadata processor {pull}5968[5968]
- Retry configuration to load dashboards if Kibana is not reachable when the beat starts. {pull}6560[6560]
- Add support for spooling to disk to the beats event publishing pipeline. {pull}6581[6581]
- Added logging of system info at Beat startup. {issue}5946[5946]

*Auditbeat*

Expand Down
73 changes: 73 additions & 0 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
svc "github.com/elastic/beats/libbeat/service"
"github.com/elastic/beats/libbeat/template"
"github.com/elastic/beats/libbeat/version"
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"

// Register publisher pipeline modules
_ "github.com/elastic/beats/libbeat/publisher/includes"
Expand Down Expand Up @@ -219,6 +221,7 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) {
return nil, err
}

logSystemInfo(b.Info)
logp.Info("Setup Beat: %s; Version: %s", b.Info.Beat, b.Info.Version)

err = b.registerTemplateLoading()
Expand Down Expand Up @@ -679,3 +682,73 @@ func handleError(err error) error {
fmt.Fprintf(os.Stderr, "Exiting: %v\n", err)
return err
}

// logSystemInfo logs information about this system for situational awareness
// in debugging. This information includes data about the beat, build, go
// runtime, host, and process. If any of the data is not available it will be
// omitted.
func logSystemInfo(info beat.Info) {
defer logp.Recover("An unexpected error occurred while collecting " +
"information about the system.")
log := logp.NewLogger("beat").With(logp.Namespace("system_info"))

// Beat
beat := common.MapStr{
"type": info.Beat,
"uuid": info.UUID,
"path": common.MapStr{
"config": paths.Resolve(paths.Config, ""),
"data": paths.Resolve(paths.Data, ""),
"home": paths.Resolve(paths.Home, ""),
"logs": paths.Resolve(paths.Logs, ""),
},
}
log.Infow("Beat info", "beat", beat)

// Build
build := common.MapStr{
"commit": version.Commit(),
"time": version.BuildTime(),
"version": info.Version,
"libbeat": version.GetDefaultVersion(),
}
log.Infow("Build info", "build", build)

// Go Runtime
log.Infow("Go runtime info", "go", sysinfo.Go())

// Host
if host, err := sysinfo.Host(); err == nil {
log.Infow("Host info", "host", host.Info())
}

// Process
if self, err := sysinfo.Self(); err == nil {
process := common.MapStr{}

if info, err := self.Info(); err == nil {
process["name"] = info.Name
process["pid"] = info.PID
process["ppid"] = info.PPID
process["cwd"] = info.CWD
process["exe"] = info.Exe
process["start_time"] = info.StartTime
}

if proc, ok := self.(types.Seccomp); ok {
if seccomp, err := proc.Seccomp(); err == nil {
process["seccomp"] = seccomp
}
}

if proc, ok := self.(types.Capabilities); ok {
if caps, err := proc.Capabilities(); err == nil {
process["capabilities"] = caps
}
}

if len(process) > 0 {
log.Infow("Process info", "process", process)
}
}
}
2 changes: 1 addition & 1 deletion libbeat/processors/add_host_metadata/add_host_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/processors"
sysinfo "github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo"
"github.com/elastic/go-sysinfo/types"
)

Expand Down

0 comments on commit 26c4fc9

Please sign in to comment.