Merge pull request #609 from simon3z/boot-id
machine: collect node boot id if available
This commit is contained in:
commit
41a0c30fbf
@ -128,6 +128,9 @@ type MachineInfo struct {
|
|||||||
// The system uuid
|
// The system uuid
|
||||||
SystemUUID string `json:"system_uuid"`
|
SystemUUID string `json:"system_uuid"`
|
||||||
|
|
||||||
|
// The boot id
|
||||||
|
BootID string `json:"boot_id"`
|
||||||
|
|
||||||
// Filesystems on this machine.
|
// Filesystems on this machine.
|
||||||
Filesystems []FsInfo `json:"filesystems"`
|
Filesystems []FsInfo `json:"filesystems"`
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ var CpuClockSpeedMHz = regexp.MustCompile("cpu MHz\\t*: +([0-9]+.[0-9]+)")
|
|||||||
var memoryCapacityRegexp = regexp.MustCompile("MemTotal: *([0-9]+) kB")
|
var memoryCapacityRegexp = regexp.MustCompile("MemTotal: *([0-9]+) kB")
|
||||||
|
|
||||||
var machineIdFilePath = flag.String("machine_id_file", "/etc/machine-id,/var/lib/dbus/machine-id", "Comma-separated list of files to check for machine-id. Use the first one that exists.")
|
var machineIdFilePath = flag.String("machine_id_file", "/etc/machine-id,/var/lib/dbus/machine-id", "Comma-separated list of files to check for machine-id. Use the first one that exists.")
|
||||||
|
var bootIdFilePath = flag.String("boot_id_file", "/proc/sys/kernel/random/boot_id", "Comma-separated list of files to check for boot-id. Use the first one that exists.")
|
||||||
|
|
||||||
func getClockSpeed(procInfo []byte) (uint64, error) {
|
func getClockSpeed(procInfo []byte) (uint64, error) {
|
||||||
// First look through sys to find a max supported cpu frequency.
|
// First look through sys to find a max supported cpu frequency.
|
||||||
@ -209,17 +210,17 @@ func getTopology(sysFs sysfs.SysFs, cpuinfo string) ([]info.Node, int, error) {
|
|||||||
return nodes, numCores, nil
|
return nodes, numCores, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMachineID() string {
|
func getInfoFromFiles(filePaths string) string {
|
||||||
if len(*machineIdFilePath) == 0 {
|
if len(filePaths) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
for _, file := range strings.Split(*machineIdFilePath, ",") {
|
for _, file := range strings.Split(filePaths, ",") {
|
||||||
id, err := ioutil.ReadFile(file)
|
id, err := ioutil.ReadFile(file)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return strings.TrimSpace(string(id))
|
return strings.TrimSpace(string(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.Infof("Couldn't collect machine-id from any of the files in %q", *machineIdFilePath)
|
glog.Infof("Couldn't collect info from any of the files in %q", filePaths)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,8 +274,9 @@ func getMachineInfo(sysFs sysfs.SysFs, fsInfo fs.FsInfo) (*info.MachineInfo, err
|
|||||||
DiskMap: diskMap,
|
DiskMap: diskMap,
|
||||||
NetworkDevices: netDevices,
|
NetworkDevices: netDevices,
|
||||||
Topology: topology,
|
Topology: topology,
|
||||||
MachineID: getMachineID(),
|
MachineID: getInfoFromFiles(*machineIdFilePath),
|
||||||
SystemUUID: systemUUID,
|
SystemUUID: systemUUID,
|
||||||
|
BootID: getInfoFromFiles(*bootIdFilePath),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fs := range filesystems {
|
for _, fs := range filesystems {
|
||||||
|
Loading…
Reference in New Issue
Block a user