8000 feat: Print osinfo when start failed by hengyoush · Pull Request #191 · hengyoush/kyanos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Print osinfo when start failed #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
0