Redo: Capture host metrics from inside docker container via volume mount /:/rootfs/
This commit is contained in:
parent
ff2de0c715
commit
c5b1a6d77e
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||||||
filename := "/proc/stat"
|
filename := "/rootfs/proc/stat"
|
||||||
var lines = []string{}
|
var lines = []string{}
|
||||||
if percpu {
|
if percpu {
|
||||||
var startIdx uint = 1
|
var startIdx uint = 1
|
||||||
|
|
@ -43,7 +43,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CPUInfo() ([]CPUInfoStat, error) {
|
func CPUInfo() ([]CPUInfoStat, error) {
|
||||||
filename := "/proc/cpuinfo"
|
filename := "/rootfs/proc/cpuinfo"
|
||||||
lines, _ := common.ReadLines(filename)
|
lines, _ := common.ReadLines(filename)
|
||||||
|
|
||||||
var ret []CPUInfoStat
|
var ret []CPUInfoStat
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
||||||
filename := "/proc/diskstats"
|
filename := "/rootfs/proc/diskstats"
|
||||||
lines, err := common.ReadLines(filename)
|
lines, err := common.ReadLines(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -280,12 +280,12 @@ func GetVirtualization() (string, string, error) {
|
||||||
var system string
|
var system string
|
||||||
var role string
|
var role string
|
||||||
|
|
||||||
if common.PathExists("/proc/xen") {
|
if common.PathExists("/rootfs/proc/xen") {
|
||||||
system = "xen"
|
system = "xen"
|
||||||
role = "guest" // assume guest
|
role = "guest" // assume guest
|
||||||
|
|
||||||
if common.PathExists("/proc/xen/capabilities") {
|
if common.PathExists("/rootfs/proc/xen/capabilities") {
|
||||||
contents, err := common.ReadLines("/proc/xen/capabilities")
|
contents, err := common.ReadLines("/rootfs/proc/xen/capabilities")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if common.StringContains(contents, "control_d") {
|
if common.StringContains(contents, "control_d") {
|
||||||
role = "host"
|
role = "host"
|
||||||
|
|
@ -293,8 +293,8 @@ func GetVirtualization() (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if common.PathExists("/proc/modules") {
|
if common.PathExists("/rootfs/proc/modules") {
|
||||||
contents, err := common.ReadLines("/proc/modules")
|
contents, err := common.ReadLines("/rootfs/proc/modules")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if common.StringContains(contents, "kvm") {
|
if common.StringContains(contents, "kvm") {
|
||||||
system = "kvm"
|
system = "kvm"
|
||||||
|
|
@ -309,8 +309,8 @@ func GetVirtualization() (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.PathExists("/proc/cpuinfo") {
|
if common.PathExists("/rootfs/proc/cpuinfo") {
|
||||||
contents, err := common.ReadLines("/proc/cpuinfo")
|
contents, err := common.ReadLines("/rootfs/proc/cpuinfo")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if common.StringContains(contents, "QEMU Virtual CPU") ||
|
if common.StringContains(contents, "QEMU Virtual CPU") ||
|
||||||
common.StringContains(contents, "Common KVM processor") ||
|
common.StringContains(contents, "Common KVM processor") ||
|
||||||
|
|
@ -321,18 +321,18 @@ func GetVirtualization() (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.PathExists("/proc/bc/0") {
|
if common.PathExists("/rootfs/proc/bc/0") {
|
||||||
system = "openvz"
|
system = "openvz"
|
||||||
role = "host"
|
role = "host"
|
||||||
} else if common.PathExists("/proc/vz") {
|
} else if common.PathExists("/rootfs/proc/vz") {
|
||||||
system = "openvz"
|
system = "openvz"
|
||||||
role = "guest"
|
role = "guest"
|
||||||
}
|
}
|
||||||
|
|
||||||
// not use dmidecode because it requires root
|
// not use dmidecode because it requires root
|
||||||
|
|
||||||
if common.PathExists("/proc/self/status") {
|
if common.PathExists("/rootfs/proc/self/status") {
|
||||||
contents, err := common.ReadLines("/proc/self/status")
|
contents, err := common.ReadLines("/rootfs/proc/self/status")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
if common.StringContains(contents, "s_context:") ||
|
if common.StringContains(contents, "s_context:") ||
|
||||||
|
|
@ -343,8 +343,8 @@ func GetVirtualization() (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.PathExists("/proc/self/cgroup") {
|
if common.PathExists("/rootfs/proc/self/cgroup") {
|
||||||
contents, err := common.ReadLines("/proc/self/cgroup")
|
contents, err := common.ReadLines("/rootfs/proc/self/cgroup")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
||||||
if common.StringContains(contents, "lxc") ||
|
if common.StringContains(contents, "lxc") ||
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadAvg() (*LoadAvgStat, error) {
|
func LoadAvg() (*LoadAvgStat, error) {
|
||||||
filename := "/proc/loadavg"
|
filename := "/rootfs/proc/loadavg"
|
||||||
line, err := ioutil.ReadFile(filename)
|
line, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func VirtualMemory() (*VirtualMemoryStat, error) {
|
func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||||
filename := "/proc/meminfo"
|
filename := "/rootfs/proc/meminfo"
|
||||||
lines, _ := common.ReadLines(filename)
|
lines, _ := common.ReadLines(filename)
|
||||||
|
|
||||||
ret := &VirtualMemoryStat{}
|
ret := &VirtualMemoryStat{}
|
||||||
|
|
@ -67,7 +67,7 @@ func SwapMemory() (*SwapMemoryStat, error) {
|
||||||
} else {
|
} else {
|
||||||
ret.UsedPercent = 0
|
ret.UsedPercent = 0
|
||||||
}
|
}
|
||||||
lines, _ := common.ReadLines("/proc/vmstat")
|
lines, _ := common.ReadLines("/rootfs/proc/vmstat")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
fields := strings.Fields(l)
|
fields := strings.Fields(l)
|
||||||
if len(fields) < 2 {
|
if len(fields) < 2 {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
// every network interface installed on the system is returned
|
// every network interface installed on the system is returned
|
||||||
// separately.
|
// separately.
|
||||||
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||||
filename := "/proc/net/dev"
|
filename := "/rootfs/proc/net/dev"
|
||||||
lines, err := common.ReadLines(filename)
|
lines, err := common.ReadLines(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ func (p *Process) IsRunning() (bool, error) {
|
||||||
return true, common.NotImplementedError
|
return true, common.NotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryMaps get memory maps from /proc/(pid)/smaps
|
// MemoryMaps get memory maps from /rootfs/proc/(pid)/smaps
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
|
|
@ -263,7 +263,7 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
||||||
** Internal functions
|
** Internal functions
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// Get num_fds from /proc/(pid)/fd
|
// Get num_fds from /rootfs/proc/(pid)/fd
|
||||||
func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "fd")
|
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "fd")
|
||||||
|
|
@ -296,7 +296,7 @@ func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
||||||
return numFDs, openfiles, nil
|
return numFDs, openfiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cwd from /proc/(pid)/cwd
|
// Get cwd from /rootfs/proc/(pid)/cwd
|
||||||
func (p *Process) fillFromCwd() (string, error) {
|
func (p *Process) fillFromCwd() (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
cwdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cwd")
|
cwdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cwd")
|
||||||
|
|
@ -307,7 +307,7 @@ func (p *Process) fillFromCwd() (string, error) {
|
||||||
return string(cwd), nil
|
return string(cwd), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get exe from /proc/(pid)/exe
|
// Get exe from /rootfs/proc/(pid)/exe
|
||||||
func (p *Process) fillFromExe() (string, error) {
|
func (p *Process) fillFromExe() (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
exePath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "exe")
|
exePath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "exe")
|
||||||
|
|
@ -318,7 +318,7 @@ func (p *Process) fillFromExe() (string, error) {
|
||||||
return string(exe), nil
|
return string(exe), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cmdline from /proc/(pid)/cmdline
|
// Get cmdline from /rootfs/proc/(pid)/cmdline
|
||||||
func (p *Process) fillFromCmdline() (string, error) {
|
func (p *Process) fillFromCmdline() (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
cmdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cmdline")
|
cmdPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "cmdline")
|
||||||
|
|
@ -336,7 +336,7 @@ func (p *Process) fillFromCmdline() (string, error) {
|
||||||
return strings.Join(ret, " "), nil
|
return strings.Join(ret, " "), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get IO status from /proc/(pid)/io
|
// Get IO status from /rootfs/proc/(pid)/io
|
||||||
func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
ioPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "io")
|
ioPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "io")
|
||||||
|
|
@ -375,7 +375,7 @@ func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get memory info from /proc/(pid)/statm
|
// Get memory info from /rootfs/proc/(pid)/statm
|
||||||
func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
memPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "statm")
|
memPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "statm")
|
||||||
|
|
@ -427,7 +427,7 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
||||||
return memInfo, memInfoEx, nil
|
return memInfo, memInfoEx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get various status from /proc/(pid)/status
|
// Get various status from /rootfs/proc/(pid)/status
|
||||||
func (p *Process) fillFromStatus() error {
|
func (p *Process) fillFromStatus() error {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "status")
|
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "status")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue