|
|
@ -26,8 +26,8 @@ func DoSysctrl(mib string) ([]string, error) {
|
|
|
|
return []string{}, err
|
|
|
|
return []string{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v := strings.Replace(string(out), "{ ", "", 1)
|
|
|
|
v := strings.Replace(string(out), "{ ", "", 1)
|
|
|
|
v = strings.Replace(string(v), " }", "", 1)
|
|
|
|
v = strings.Replace(v, " }", "", 1)
|
|
|
|
values := strings.Fields(string(v))
|
|
|
|
values := strings.Fields(v)
|
|
|
|
|
|
|
|
|
|
|
|
return values, nil
|
|
|
|
return values, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -55,7 +55,6 @@ func NumProcs() (uint64, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
|
|
|
|
|
|
|
|
system, role, err := Virtualization()
|
|
|
|
system, role, err := Virtualization()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
return 0, err
|
|
|
@ -76,6 +75,18 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
return 0, err
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if statFile == "uptime" {
|
|
|
|
|
|
|
|
if len(lines) != 1 {
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("wrong uptime format")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f := strings.Fields(lines[0])
|
|
|
|
|
|
|
|
b, err := strconv.ParseFloat(f[0], 64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t := uint64(time.Now().Unix()) - uint64(b)
|
|
|
|
|
|
|
|
return t, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
if statFile == "stat" {
|
|
|
|
if statFile == "stat" {
|
|
|
|
for _, line := range lines {
|
|
|
|
for _, line := range lines {
|
|
|
|
if strings.HasPrefix(line, "btime") {
|
|
|
|
if strings.HasPrefix(line, "btime") {
|
|
|
@ -91,17 +102,6 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
return t, nil
|
|
|
|
return t, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if statFile == "uptime" {
|
|
|
|
|
|
|
|
if len(lines) != 1 {
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("wrong uptime format")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f := strings.Fields(lines[0])
|
|
|
|
|
|
|
|
b, err := strconv.ParseFloat(f[0], 64)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t := uint64(time.Now().Unix()) - uint64(b)
|
|
|
|
|
|
|
|
return t, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0, fmt.Errorf("could not find btime")
|
|
|
|
return 0, fmt.Errorf("could not find btime")
|
|
|
@ -111,7 +111,7 @@ func Virtualization() (string, string, error) {
|
|
|
|
return VirtualizationWithContext(context.Background())
|
|
|
|
return VirtualizationWithContext(context.Background())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// required variables for concurrency safe virtualization caching
|
|
|
|
// required variables for concurrency safe virtualization caching.
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
cachedVirtMap map[string]string
|
|
|
|
cachedVirtMap map[string]string
|
|
|
|
cachedVirtMutex sync.RWMutex
|
|
|
|
cachedVirtMutex sync.RWMutex
|
|
|
@ -137,10 +137,8 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
if PathExists(filepath.Join(filename, "capabilities")) {
|
|
|
|
if PathExists(filepath.Join(filename, "capabilities")) {
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "capabilities"))
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "capabilities"))
|
|
|
|
if err == nil {
|
|
|
|
if err == nil && StringsContains(contents, "control_d") {
|
|
|
|
if StringsContains(contents, "control_d") {
|
|
|
|
role = "host"
|
|
|
|
role = "host"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,16 +147,17 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|
|
|
if PathExists(filename) {
|
|
|
|
if PathExists(filename) {
|
|
|
|
contents, err := ReadLines(filename)
|
|
|
|
contents, err := ReadLines(filename)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
if StringsContains(contents, "kvm") {
|
|
|
|
switch {
|
|
|
|
|
|
|
|
case StringsContains(contents, "kvm"):
|
|
|
|
system = "kvm"
|
|
|
|
system = "kvm"
|
|
|
|
role = "host"
|
|
|
|
role = "host"
|
|
|
|
} else if StringsContains(contents, "vboxdrv") {
|
|
|
|
case StringsContains(contents, "vboxdrv"):
|
|
|
|
system = "vbox"
|
|
|
|
system = "vbox"
|
|
|
|
role = "host"
|
|
|
|
role = "host"
|
|
|
|
} else if StringsContains(contents, "vboxguest") {
|
|
|
|
case StringsContains(contents, "vboxguest"):
|
|
|
|
system = "vbox"
|
|
|
|
system = "vbox"
|
|
|
|
role = "guest"
|
|
|
|
role = "guest"
|
|
|
|
} else if StringsContains(contents, "vmware") {
|
|
|
|
case StringsContains(contents, "vmware"):
|
|
|
|
system = "vmware"
|
|
|
|
system = "vmware"
|
|
|
|
role = "guest"
|
|
|
|
role = "guest"
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -201,7 +200,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|
|
|
if PathExists(filepath.Join(filename, "self", "status")) {
|
|
|
|
if PathExists(filepath.Join(filename, "self", "status")) {
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "self", "status"))
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "self", "status"))
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
|
|
|
|
if StringsContains(contents, "s_context:") ||
|
|
|
|
if StringsContains(contents, "s_context:") ||
|
|
|
|
StringsContains(contents, "VxID:") {
|
|
|
|
StringsContains(contents, "VxID:") {
|
|
|
|
system = "linux-vserver"
|
|
|
|
system = "linux-vserver"
|
|
|
@ -224,16 +222,17 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|
|
|
if PathExists(filepath.Join(filename, "self", "cgroup")) {
|
|
|
|
if PathExists(filepath.Join(filename, "self", "cgroup")) {
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "self", "cgroup"))
|
|
|
|
contents, err := ReadLines(filepath.Join(filename, "self", "cgroup"))
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
if StringsContains(contents, "lxc") {
|
|
|
|
switch {
|
|
|
|
|
|
|
|
case StringsContains(contents, "lxc"):
|
|
|
|
system = "lxc"
|
|
|
|
system = "lxc"
|
|
|
|
role = "guest"
|
|
|
|
role = "guest"
|
|
|
|
} else if StringsContains(contents, "docker") {
|
|
|
|
case StringsContains(contents, "docker"):
|
|
|
|
system = "docker"
|
|
|
|
system = "docker"
|
|
|
|
role = "guest"
|
|
|
|
role = "guest"
|
|
|
|
} else if StringsContains(contents, "machine-rkt") {
|
|
|
|
case StringsContains(contents, "machine-rkt"):
|
|
|
|
system = "rkt"
|
|
|
|
system = "rkt"
|
|
|
|
role = "guest"
|
|
|
|
role = "guest"
|
|
|
|
} else if PathExists("/usr/bin/lxc-version") {
|
|
|
|
case PathExists("/usr/bin/lxc-version"):
|
|
|
|
system = "lxc"
|
|
|
|
system = "lxc"
|
|
|
|
role = "host"
|
|
|
|
role = "host"
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -281,7 +280,7 @@ func GetOSRelease() (platform string, version string, err error) {
|
|
|
|
return platform, version, nil
|
|
|
|
return platform, version, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove quotes of the source string
|
|
|
|
// trimQuotes removes quotes in the source string.
|
|
|
|
func trimQuotes(s string) string {
|
|
|
|
func trimQuotes(s string) string {
|
|
|
|
if len(s) >= 2 {
|
|
|
|
if len(s) >= 2 {
|
|
|
|
if s[0] == '"' && s[len(s)-1] == '"' {
|
|
|
|
if s[0] == '"' && s[len(s)-1] == '"' {
|
|
|
|