|
@@ -3,6 +3,7 @@ package sysinfo
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"math"
|
|
"math"
|
|
|
|
+ "os"
|
|
"runtime"
|
|
"runtime"
|
|
"sort"
|
|
"sort"
|
|
"strconv"
|
|
"strconv"
|
|
@@ -73,24 +74,52 @@ type MountpointInfo struct {
|
|
}
|
|
}
|
|
|
|
|
|
type SystemInfoRequest struct {
|
|
type SystemInfoRequest struct {
|
|
- CPUTempSensor string `yaml:"cpu-temp-sensor"`
|
|
|
|
- Mountpoints map[string]MointpointRequest `yaml:"mountpoints"`
|
|
|
|
|
|
+ CPUTempSensor string `yaml:"cpu-temp-sensor"`
|
|
|
|
+ HideMountpointsByDefault bool `yaml:"hide-mountpoints-by-default"`
|
|
|
|
+ Mountpoints map[string]MointpointRequest `yaml:"mountpoints"`
|
|
}
|
|
}
|
|
|
|
|
|
type MointpointRequest struct {
|
|
type MointpointRequest struct {
|
|
Name string `yaml:"name"`
|
|
Name string `yaml:"name"`
|
|
- Hide bool `yaml:"hide"`
|
|
|
|
|
|
+ Hide *bool `yaml:"hide"`
|
|
}
|
|
}
|
|
|
|
|
|
// Currently caches hostname indefinitely which isn't ideal
|
|
// Currently caches hostname indefinitely which isn't ideal
|
|
// Potential issue with caching boot time as it may not initially get reported correctly:
|
|
// Potential issue with caching boot time as it may not initially get reported correctly:
|
|
// https://github.com/shirou/gopsutil/issues/842#issuecomment-1908972344
|
|
// https://github.com/shirou/gopsutil/issues/842#issuecomment-1908972344
|
|
-var cachedHostInfo = struct {
|
|
|
|
|
|
+type cacheableHostInfo struct {
|
|
available bool
|
|
available bool
|
|
hostname string
|
|
hostname string
|
|
platform string
|
|
platform string
|
|
bootTime timestampJSON
|
|
bootTime timestampJSON
|
|
-}{}
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var cachedHostInfo cacheableHostInfo
|
|
|
|
+
|
|
|
|
+func getHostInfo() (cacheableHostInfo, error) {
|
|
|
|
+ var err error
|
|
|
|
+ info := cacheableHostInfo{}
|
|
|
|
+
|
|
|
|
+ info.hostname, err = os.Hostname()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return info, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ info.platform, _, _, err = host.PlatformInformation()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return info, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bootTime, err := host.BootTime()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return info, err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ info.bootTime = timestampJSON{time.Unix(int64(bootTime), 0)}
|
|
|
|
+ info.available = true
|
|
|
|
+
|
|
|
|
+ return info, nil
|
|
|
|
+}
|
|
|
|
|
|
func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
|
|
func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
|
|
if req == nil {
|
|
if req == nil {
|
|
@@ -117,13 +146,9 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
|
|
if cachedHostInfo.available {
|
|
if cachedHostInfo.available {
|
|
applyCachedHostInfo()
|
|
applyCachedHostInfo()
|
|
} else {
|
|
} else {
|
|
- hostInfo, err := host.Info()
|
|
|
|
|
|
+ hostInfo, err := getHostInfo()
|
|
if err == nil {
|
|
if err == nil {
|
|
- cachedHostInfo.available = true
|
|
|
|
- cachedHostInfo.bootTime = timestampJSON{time.Unix(int64(hostInfo.BootTime), 0)}
|
|
|
|
- cachedHostInfo.hostname = hostInfo.Hostname
|
|
|
|
- cachedHostInfo.platform = hostInfo.Platform
|
|
|
|
-
|
|
|
|
|
|
+ cachedHostInfo = hostInfo
|
|
applyCachedHostInfo()
|
|
applyCachedHostInfo()
|
|
} else {
|
|
} else {
|
|
addErr(fmt.Errorf("getting host info: %v", err))
|
|
addErr(fmt.Errorf("getting host info: %v", err))
|
|
@@ -205,7 +230,11 @@ func Collect(req *SystemInfoRequest) (*SystemInfo, []error) {
|
|
if err == nil {
|
|
if err == nil {
|
|
for _, fs := range filesystems {
|
|
for _, fs := range filesystems {
|
|
mpReq, ok := req.Mountpoints[fs.Mountpoint]
|
|
mpReq, ok := req.Mountpoints[fs.Mountpoint]
|
|
- if ok && mpReq.Hide {
|
|
|
|
|
|
+ isHidden := req.HideMountpointsByDefault
|
|
|
|
+ if ok && mpReq.Hide != nil {
|
|
|
|
+ isHidden = *mpReq.Hide
|
|
|
|
+ }
|
|
|
|
+ if isHidden {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|