Skip to content

Commit

Permalink
feat: Print osinfo when start failed (#191)
Browse files Browse the repository at this point in the history
* feat: print os info when start failed

* feat: add system info logging for crash reports

* refactor: remove unsed log

* refactor: add faq url
  • Loading branch information
hengyoush authored Dec 18, 2024
1 parent 9dc5e32 commit f84fd43
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"context"
"fmt"
"kyanos/agent/analysis"
anc "kyanos/agent/analysis/common"
ac "kyanos/agent/common"
Expand All @@ -15,7 +16,10 @@ import (
"kyanos/bpf/loader"
"kyanos/common"
"os"
"os/exec"
"os/signal"
"runtime"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -139,7 +143,7 @@ func SetupAgent(options ac.AgentOptions) {
common.AgentLog.Info("Waiting for events..")
}
if _bf.Err != nil {
common.AgentLog.Error("Failed to load BPF: ", _bf.Err)
logSystemInfo(_bf.Err)
return
}

Expand Down Expand Up @@ -170,6 +174,52 @@ func SetupAgent(options ac.AgentOptions) {
return
}

func logSystemInfo(loadError error) {
common.SetLogToStdout()
info := []string{
"OS: " + runtime.GOOS,
"Arch: " + runtime.GOARCH,
"NumCPU: " + fmt.Sprintf("%d", runtime.NumCPU()),
"GoVersion: " + runtime.Version(),
}

kernelVersion, err := exec.Command("uname", "-r").Output()
if err == nil {
info = append(info, "Kernel Version: "+strings.TrimSpace(string(kernelVersion)))
} else {
info = append(info, "Failed to get kernel version: "+err.Error())
}

osRelease, err := exec.Command("cat", "/etc/os-release").Output()
if err == nil {
info = append(info, strings.TrimSpace(string(osRelease)))
} else {
info = append(info, "Failed to get Linux distribution: "+err.Error())
}

const crashReportFormat = `
===================================
Kyanos Crash Report
=========Error Message=============
%s
============OS Info================
%s
===================================
FAQ : https://kyanos.io/faq.html
Submit issue: https://github.com/hengyoush/kyanos/issues
`

var errorInfo string
if loadError != nil {
errorInfo = "Error: " + loadError.Error()
} else {
errorInfo = "No load errors detected."
}

fmt.Printf(crashReportFormat, errorInfo, strings.Join(info, "\n"))
}

func startGopsServer(opts ac.AgentOptions) {
if opts.WatchOptions.DebugOutput {
if err := gops.Listen(gops.Options{}); err != nil {
Expand Down

0 comments on commit f84fd43

Please sign in to comment.