|
|
|
@ -11,15 +11,17 @@ import (
|
|
|
|
|
"github.com/toolkits/pkg/nux"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func DeviceMetrics() (L []*dataobj.MetricValue) {
|
|
|
|
|
func DeviceMetrics() []*dataobj.MetricValue {
|
|
|
|
|
ret := make([]*dataobj.MetricValue, 0)
|
|
|
|
|
|
|
|
|
|
mountPoints, err := nux.ListMountPoint()
|
|
|
|
|
fsFileFilter := make(map[string]struct{}) //过滤 /proc/mounts 出现重复的fsFile
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error("collect device metrics fail:", err)
|
|
|
|
|
return
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var myMountPoints map[string]bool = make(map[string]bool)
|
|
|
|
|
var myMountPoints = make(map[string]bool)
|
|
|
|
|
if len(sys.Config.MountPoint) > 0 {
|
|
|
|
|
for _, mp := range sys.Config.MountPoint {
|
|
|
|
|
myMountPoints[mp] = true
|
|
|
|
@ -39,6 +41,7 @@ func DeviceMetrics() (L []*dataobj.MetricValue) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, exists := fsFileFilter[fsFile]; exists {
|
|
|
|
|
logger.Debugf("mount point %s was collected", fsFile)
|
|
|
|
|
continue
|
|
|
|
@ -65,29 +68,29 @@ func DeviceMetrics() (L []*dataobj.MetricValue) {
|
|
|
|
|
diskUsed += du.BlocksUsed
|
|
|
|
|
|
|
|
|
|
tags := fmt.Sprintf("mount=%s", du.FsFile)
|
|
|
|
|
L = append(L, GaugeValue("disk.bytes.total", du.BlocksAll, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.bytes.free", du.BlocksFree, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.bytes.used", du.BlocksUsed, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.bytes.used.percent", du.BlocksUsedPercent, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.bytes.total", du.BlocksAll, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.bytes.free", du.BlocksFree, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.bytes.used", du.BlocksUsed, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.bytes.used.percent", du.BlocksUsedPercent, tags))
|
|
|
|
|
|
|
|
|
|
if du.InodesAll == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
L = append(L, GaugeValue("disk.inodes.total", du.InodesAll, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.inodes.free", du.InodesFree, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.inodes.used", du.InodesUsed, tags))
|
|
|
|
|
L = append(L, GaugeValue("disk.inodes.used.percent", du.InodesUsedPercent, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.inodes.total", du.InodesAll, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.inodes.free", du.InodesFree, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.inodes.used", du.InodesUsed, tags))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.inodes.used.percent", du.InodesUsedPercent, tags))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(L) > 0 && diskTotal > 0 {
|
|
|
|
|
L = append(L, GaugeValue("disk.cap.bytes.total", float64(diskTotal)))
|
|
|
|
|
L = append(L, GaugeValue("disk.cap.bytes.used", float64(diskUsed)))
|
|
|
|
|
L = append(L, GaugeValue("disk.cap.bytes.free", float64(diskTotal-diskUsed)))
|
|
|
|
|
L = append(L, GaugeValue("disk.cap.bytes.used.percent", float64(diskUsed)*100.0/float64(diskTotal)))
|
|
|
|
|
if len(ret) > 0 && diskTotal > 0 {
|
|
|
|
|
ret = append(ret, GaugeValue("disk.cap.bytes.total", float64(diskTotal)))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.cap.bytes.used", float64(diskUsed)))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.cap.bytes.free", float64(diskTotal-diskUsed)))
|
|
|
|
|
ret = append(ret, GaugeValue("disk.cap.bytes.used.percent", float64(diskUsed)*100.0/float64(diskTotal)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func hasIgnorePrefix(fsFile string, ignoreMountPointsPrefix []string) bool {
|
|
|
|
|