Merge pull request #560 from simon3z/master
Add system uuid and machine id information
This commit is contained in:
commit
7839dd8eef
@ -122,6 +122,12 @@ type MachineInfo struct {
|
|||||||
// The amount of memory (in bytes) in this machine
|
// The amount of memory (in bytes) in this machine
|
||||||
MemoryCapacity int64 `json:"memory_capacity"`
|
MemoryCapacity int64 `json:"memory_capacity"`
|
||||||
|
|
||||||
|
// The machine id
|
||||||
|
MachineID string `json:"machine_id"`
|
||||||
|
|
||||||
|
// The system uuid
|
||||||
|
SystemUUID string `json:"system_uuid"`
|
||||||
|
|
||||||
// Filesystems on this machine.
|
// Filesystems on this machine.
|
||||||
Filesystems []FsInfo `json:"filesystems"`
|
Filesystems []FsInfo `json:"filesystems"`
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ package manager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -24,6 +25,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
dclient "github.com/fsouza/go-dockerclient"
|
dclient "github.com/fsouza/go-dockerclient"
|
||||||
|
"github.com/golang/glog"
|
||||||
"github.com/google/cadvisor/container/docker"
|
"github.com/google/cadvisor/container/docker"
|
||||||
"github.com/google/cadvisor/fs"
|
"github.com/google/cadvisor/fs"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
info "github.com/google/cadvisor/info/v1"
|
||||||
@ -39,6 +41,8 @@ var nodeRegExp = regexp.MustCompile("physical id\\t*: +([0-9]+)")
|
|||||||
var CpuClockSpeedMHz = regexp.MustCompile("cpu MHz\\t*: +([0-9]+.[0-9]+)")
|
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", "File containing the machine-id")
|
||||||
|
|
||||||
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.
|
||||||
const maxFreqFile = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
|
const maxFreqFile = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
|
||||||
@ -205,6 +209,15 @@ func getTopology(sysFs sysfs.SysFs, cpuinfo string) ([]info.Node, int, error) {
|
|||||||
return nodes, numCores, nil
|
return nodes, numCores, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMachineID() string {
|
||||||
|
id, err := ioutil.ReadFile(*machineIdFilePath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Error("Couldn't collect machine-id: ", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(id))
|
||||||
|
}
|
||||||
|
|
||||||
func getMachineInfo(sysFs sysfs.SysFs) (*info.MachineInfo, error) {
|
func getMachineInfo(sysFs sysfs.SysFs) (*info.MachineInfo, error) {
|
||||||
cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo")
|
cpuinfo, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||||
clockSpeed, err := getClockSpeed(cpuinfo)
|
clockSpeed, err := getClockSpeed(cpuinfo)
|
||||||
@ -247,6 +260,11 @@ func getMachineInfo(sysFs sysfs.SysFs) (*info.MachineInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
system_uuid, err := sysinfo.GetSystemUUID(sysFs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
machineInfo := &info.MachineInfo{
|
machineInfo := &info.MachineInfo{
|
||||||
NumCores: numCores,
|
NumCores: numCores,
|
||||||
CpuFrequency: clockSpeed,
|
CpuFrequency: clockSpeed,
|
||||||
@ -254,6 +272,8 @@ func getMachineInfo(sysFs sysfs.SysFs) (*info.MachineInfo, error) {
|
|||||||
DiskMap: diskMap,
|
DiskMap: diskMap,
|
||||||
NetworkDevices: netDevices,
|
NetworkDevices: netDevices,
|
||||||
Topology: topology,
|
Topology: topology,
|
||||||
|
MachineID: getMachineID(),
|
||||||
|
SystemUUID: system_uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fs := range filesystems {
|
for _, fs := range filesystems {
|
||||||
|
@ -108,3 +108,7 @@ func (self *FakeSysFs) SetCacheInfo(cache sysfs.CacheInfo) {
|
|||||||
func (self *FakeSysFs) SetEntryName(name string) {
|
func (self *FakeSysFs) SetEntryName(name string) {
|
||||||
self.info.EntryName = name
|
self.info.EntryName = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *FakeSysFs) GetSystemUUID() (string, error) {
|
||||||
|
return "1F862619-BA9F-4526-8F85-ECEAF0C97430", nil
|
||||||
|
}
|
||||||
|
@ -27,6 +27,7 @@ const (
|
|||||||
blockDir = "/sys/block"
|
blockDir = "/sys/block"
|
||||||
cacheDir = "/sys/devices/system/cpu/cpu"
|
cacheDir = "/sys/devices/system/cpu/cpu"
|
||||||
netDir = "/sys/class/net"
|
netDir = "/sys/class/net"
|
||||||
|
dmiDir = "/sys/class/dmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CacheInfo struct {
|
type CacheInfo struct {
|
||||||
@ -61,6 +62,8 @@ type SysFs interface {
|
|||||||
GetCaches(id int) ([]os.FileInfo, error)
|
GetCaches(id int) ([]os.FileInfo, error)
|
||||||
// Get information for a cache accessible from the given cpu.
|
// Get information for a cache accessible from the given cpu.
|
||||||
GetCacheInfo(cpu int, cache string) (CacheInfo, error)
|
GetCacheInfo(cpu int, cache string) (CacheInfo, error)
|
||||||
|
|
||||||
|
GetSystemUUID() (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type realSysFs struct{}
|
type realSysFs struct{}
|
||||||
@ -228,3 +231,11 @@ func (self *realSysFs) GetCacheInfo(id int, name string) (CacheInfo, error) {
|
|||||||
Cpus: cpuCount,
|
Cpus: cpuCount,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *realSysFs) GetSystemUUID() (string, error) {
|
||||||
|
id, err := ioutil.ReadFile(path.Join(dmiDir, "id", "product_uuid"))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(id)), nil
|
||||||
|
}
|
||||||
|
@ -204,3 +204,7 @@ func getNetworkStats(name string, sysFs sysfs.SysFs) (info.NetworkStats, error)
|
|||||||
}
|
}
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSystemUUID(sysFs sysfs.SysFs) (string, error) {
|
||||||
|
return sysFs.GetSystemUUID()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user