Merge pull request #706 from rjnagal/docker
Add 'bytes available' to fs info.
This commit is contained in:
commit
86dd6cc99d
@ -264,6 +264,7 @@ func (self *rawContainerHandler) getFsStats(stats *info.ContainerStats) error {
|
|||||||
Device: fs.Device,
|
Device: fs.Device,
|
||||||
Limit: fs.Capacity,
|
Limit: fs.Capacity,
|
||||||
Usage: fs.Capacity - fs.Free,
|
Usage: fs.Capacity - fs.Free,
|
||||||
|
Available: fs.Available,
|
||||||
ReadsCompleted: fs.DiskStats.ReadsCompleted,
|
ReadsCompleted: fs.DiskStats.ReadsCompleted,
|
||||||
ReadsMerged: fs.DiskStats.ReadsMerged,
|
ReadsMerged: fs.DiskStats.ReadsMerged,
|
||||||
SectorsRead: fs.DiskStats.SectorsRead,
|
SectorsRead: fs.DiskStats.SectorsRead,
|
||||||
|
19
fs/fs.go
19
fs/fs.go
@ -20,6 +20,7 @@ package fs
|
|||||||
/*
|
/*
|
||||||
extern int getBytesFree(const char *path, unsigned long long *bytes);
|
extern int getBytesFree(const char *path, unsigned long long *bytes);
|
||||||
extern int getBytesTotal(const char *path, unsigned long long *bytes);
|
extern int getBytesTotal(const char *path, unsigned long long *bytes);
|
||||||
|
extern int getBytesAvail(const char *path, unsigned long long *bytes);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
@ -176,7 +177,7 @@ func (self *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, er
|
|||||||
_, hasMount := mountSet[partition.mountpoint]
|
_, hasMount := mountSet[partition.mountpoint]
|
||||||
_, hasDevice := deviceSet[device]
|
_, hasDevice := deviceSet[device]
|
||||||
if mountSet == nil || (hasMount && !hasDevice) {
|
if mountSet == nil || (hasMount && !hasDevice) {
|
||||||
total, free, err := getVfsStats(partition.mountpoint)
|
total, free, avail, err := getVfsStats(partition.mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Statvfs failed. Error: %v", err)
|
glog.Errorf("Statvfs failed. Error: %v", err)
|
||||||
} else {
|
} else {
|
||||||
@ -186,7 +187,7 @@ func (self *RealFsInfo) GetFsInfoForPath(mountSet map[string]struct{}) ([]Fs, er
|
|||||||
Major: uint(partition.major),
|
Major: uint(partition.major),
|
||||||
Minor: uint(partition.minor),
|
Minor: uint(partition.minor),
|
||||||
}
|
}
|
||||||
fs := Fs{deviceInfo, total, free, diskStatsMap[device]}
|
fs := Fs{deviceInfo, total, free, avail, diskStatsMap[device]}
|
||||||
filesystems = append(filesystems, fs)
|
filesystems = append(filesystems, fs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,18 +288,22 @@ func (self *RealFsInfo) GetDirUsage(dir string) (uint64, error) {
|
|||||||
return usageInKb * 1024, nil
|
return usageInKb * 1024, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVfsStats(path string) (total uint64, free uint64, err error) {
|
func getVfsStats(path string) (total uint64, free uint64, avail uint64, err error) {
|
||||||
_p0, err := syscall.BytePtrFromString(path)
|
_p0, err := syscall.BytePtrFromString(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, 0, err
|
||||||
}
|
}
|
||||||
res, err := C.getBytesFree((*C.char)(unsafe.Pointer(_p0)), (*_Ctype_ulonglong)(unsafe.Pointer(&free)))
|
res, err := C.getBytesFree((*C.char)(unsafe.Pointer(_p0)), (*_Ctype_ulonglong)(unsafe.Pointer(&free)))
|
||||||
if res != 0 {
|
if res != 0 {
|
||||||
return 0, 0, err
|
return 0, 0, 0, err
|
||||||
}
|
}
|
||||||
res, err = C.getBytesTotal((*C.char)(unsafe.Pointer(_p0)), (*_Ctype_ulonglong)(unsafe.Pointer(&total)))
|
res, err = C.getBytesTotal((*C.char)(unsafe.Pointer(_p0)), (*_Ctype_ulonglong)(unsafe.Pointer(&total)))
|
||||||
if res != 0 {
|
if res != 0 {
|
||||||
return 0, 0, err
|
return 0, 0, 0, err
|
||||||
}
|
}
|
||||||
return total, free, nil
|
res, err = C.getBytesAvail((*C.char)(unsafe.Pointer(_p0)), (*_Ctype_ulonglong)(unsafe.Pointer(&avail)))
|
||||||
|
if res != 0 {
|
||||||
|
return 0, 0, 0, err
|
||||||
|
}
|
||||||
|
return total, free, avail, nil
|
||||||
}
|
}
|
||||||
|
11
fs/statvfs.c
11
fs/statvfs.c
@ -21,3 +21,14 @@ int getBytesTotal(const char *path, unsigned long long *bytes) {
|
|||||||
*bytes = buf.f_frsize * buf.f_blocks;
|
*bytes = buf.f_frsize * buf.f_blocks;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bytes available to non-root.
|
||||||
|
int getBytesAvail(const char *path, unsigned long long *bytes) {
|
||||||
|
struct statvfs buf;
|
||||||
|
int res;
|
||||||
|
if ((res = statvfs(path, &buf)) && res != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*bytes = buf.f_frsize * buf.f_bavail;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@ type Fs struct {
|
|||||||
DeviceInfo
|
DeviceInfo
|
||||||
Capacity uint64
|
Capacity uint64
|
||||||
Free uint64
|
Free uint64
|
||||||
|
Available uint64
|
||||||
DiskStats DiskStats
|
DiskStats DiskStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,6 +341,9 @@ type FsStats struct {
|
|||||||
// Number of bytes that is consumed by the container on this filesystem.
|
// Number of bytes that is consumed by the container on this filesystem.
|
||||||
Usage uint64 `json:"usage"`
|
Usage uint64 `json:"usage"`
|
||||||
|
|
||||||
|
// Number of bytes available for non-root user.
|
||||||
|
Available uint64 `json:"available"`
|
||||||
|
|
||||||
// Number of reads completed
|
// Number of reads completed
|
||||||
// This is the total number of reads completed successfully.
|
// This is the total number of reads completed successfully.
|
||||||
ReadsCompleted uint64 `json:"reads_completed"`
|
ReadsCompleted uint64 `json:"reads_completed"`
|
||||||
|
Loading…
Reference in New Issue
Block a user