forked from open-falcon-archive/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfstat.go
53 lines (43 loc) · 1.62 KB
/
dfstat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package funcs
import (
"fmt"
"github.com/open-falcon/common/model"
"github.com/toolkits/nux"
"log"
)
func DeviceMetrics() (L []*model.MetricValue) {
mountPoints, err := nux.ListMountPoint()
if err != nil {
log.Println(err)
return
}
var diskTotal uint64 = 0
var diskUsed uint64 = 0
for idx := range mountPoints {
var du *nux.DeviceUsage
du, err = nux.BuildDeviceUsage(mountPoints[idx][0], mountPoints[idx][1], mountPoints[idx][2])
if err != nil {
log.Println(err)
continue
}
diskTotal += du.BlocksAll
diskUsed += du.BlocksUsed
tags := fmt.Sprintf("mount=%s,fstype=%s", du.FsFile, du.FsVfstype)
L = append(L, GaugeValue("df.bytes.total", du.BlocksAll, tags))
L = append(L, GaugeValue("df.bytes.used", du.BlocksUsed, tags))
L = append(L, GaugeValue("df.bytes.free", du.BlocksFree, tags))
L = append(L, GaugeValue("df.bytes.used.percent", du.BlocksUsedPercent, tags))
L = append(L, GaugeValue("df.bytes.free.percent", du.BlocksFreePercent, tags))
L = append(L, GaugeValue("df.inodes.total", du.InodesAll, tags))
L = append(L, GaugeValue("df.inodes.used", du.InodesUsed, tags))
L = append(L, GaugeValue("df.inodes.free", du.InodesFree, tags))
L = append(L, GaugeValue("df.inodes.used.percent", du.InodesUsedPercent, tags))
L = append(L, GaugeValue("df.inodes.free.percent", du.InodesFreePercent, tags))
}
if len(L) > 0 && diskTotal > 0 {
L = append(L, GaugeValue("df.statistics.total", float64(diskTotal)))
L = append(L, GaugeValue("df.statistics.used", float64(diskUsed)))
L = append(L, GaugeValue("df.statistics.used.percent", float64(diskUsed)*100.0/float64(diskTotal)))
}
return
}