Commit 50b5aa95 authored by Lei Li's avatar Lei Li
Browse files

feat: 增加基础信息获取

parent 4381274d
......@@ -2,21 +2,24 @@ package core
import (
"agent/cmd/agent/config"
"agent/cmd/agent/global"
"agent/cmd/agent/option"
"agent/module"
"agent/module/plugin"
"agent/module/resources"
"fmt"
"linkfog.com/public/lib/monitor_daemon"
"os"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
"linkfog.com/public/lib/l"
"linkfog.com/public/lib/monitor_daemon"
"github.com/judwhite/go-svc"
"github.com/shirou/gopsutil/host"
)
var AgentSvc = &Agent{}
......@@ -117,7 +120,36 @@ func genVersion() string {
}
func initSvcCfg() error {
global.HostInfoTail = &global.HostInfo{
Platform: global.PlatformNameAndroid,
}
// 获取平台和内核版本
hostInfo, err := host.Info()
if err != nil {
l.Warnf("get host info err:%v", err)
} else {
if strings.Contains(hostInfo.KernelArch, "armv7") || strings.Contains(hostInfo.KernelArch, "armv8") {
global.HostInfoTail.Platform = global.PlatformNameAndroid
} else if strings.Contains(hostInfo.KernelArch, "x86") {
global.HostInfoTail.Platform = global.PlatformNameX86
} else if strings.Contains(hostInfo.KernelArch, "aarch") {
global.HostInfoTail.Platform = global.PlatformNameArm64
}
global.HostInfoTail.KernelVersion = hostInfo.KernelVersion
}
// 设置工作目录
l.Infof("the architecture(GOARCH) type is %s", runtime.GOARCH)
if strings.Contains(runtime.GOARCH, "amd64") || strings.Contains(runtime.GOARCH, "arm64") ||
strings.Contains(runtime.GOARCH, "aarch64") {
config.WorkDir = "/linkfog/agent/"
} else if strings.Contains(runtime.GOARCH, "android") || strings.Contains(runtime.GOARCH, "arm") {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err == nil {
config.WorkDir = filepath.Join(strings.Replace(dir, "\\", "/", -1), "agent")
}
}
return nil
}
......
......@@ -3,4 +3,16 @@ package global
const (
ResourceModuleName = "resources"
PluginModuleName = "pluginMgr"
PlatformNameAndroid = "android"
PlatformNameX86 = "x86"
PlatformNameArm64 = "arm"
)
var HostInfoTail *HostInfo
type HostInfo struct {
Platform string
OSVersion string
KernelVersion string
}
......@@ -34,6 +34,8 @@ type options struct {
MonitorDefaultIncrInterval time.Duration
MonitorDefaultMaxRetryTimes int
MonitorDefaultBackupFileName string
SerialNumber string
}
const (
......@@ -57,6 +59,8 @@ const (
ArgMonitorDefaultIncrInterval = "monitor-default-incr-interval"
ArgMonitorDefaultMaxRetryTimes = "monitor-default-max-retry-times"
ArgMonitorDefaultBackupFileName = "monitor-default-backup-file-name"
ArgSerialNumber = "SN"
)
func flagSet() {
......@@ -80,6 +84,8 @@ func flagSet() {
flag.DurationVar(&Opt.MonitorDefaultIncrInterval, ArgMonitorDefaultIncrInterval, 12*time.Second, "every time the process is restarted, the time interval increases")
flag.IntVar(&Opt.MonitorDefaultMaxRetryTimes, ArgMonitorDefaultMaxRetryTimes, 3, "maximum number of error retries")
flag.StringVar(&Opt.MonitorDefaultBackupFileName, ArgMonitorDefaultBackupFileName, "agent.bak", "agent file backup")
flag.StringVar(&Opt.SerialNumber, ArgSerialNumber, "", "serial number")
}
func Parse() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment