MCPcopy
hub / github.com/dgraph-io/dgraph / MonitorDiskMetrics

Function MonitorDiskMetrics

x/disk_metrics_linux.go:25–53  ·  view source on GitHub ↗
(dirTag string, dir string, lc *z.Closer)

Source from the content-addressed store, hash-verified

23)
24
25func MonitorDiskMetrics(dirTag string, dir string, lc *z.Closer) {
26 defer lc.Done()
27 ctx, err := tag.New(context.Background(), tag.Upsert(KeyDirType, dirTag))
28
29 fastTicker := time.Tick(10 * time.Second)
30
31 if err != nil {
32 glog.Errorln("Invalid Tag", err)
33 return
34 }
35
36 for {
37 select {
38 case <-lc.HasBeenClosed():
39 return
40 case <-fastTicker:
41 s := syscall.Statfs_t{}
42 err = syscall.Statfs(dir, &s)
43 if err != nil {
44 continue
45 }
46 reservedBlocks := s.Bfree - s.Bavail
47 total := int64(s.Frsize) * int64(s.Blocks-reservedBlocks)
48 free := int64(s.Frsize) * int64(s.Bavail)
49 stats.Record(ctx, DiskFree.M(free), DiskUsed.M(total-free), DiskTotal.M(total))
50 }
51 }
52
53}

Callers

nothing calls this directly

Calls 3

UpsertMethod · 0.80
RecordMethod · 0.80
DoneMethod · 0.45

Tested by

no test coverage detected