[ARVADOS] created: 1.1.4-696-ge4c31590b

Git user git at public.curoverse.com
Tue Jul 24 10:32:05 EDT 2018


        at  e4c31590b4dafaac8f4814ea4504a8bc1956f9b0 (commit)


commit e4c31590b4dafaac8f4814ea4504a8bc1956f9b0
Author: Lucas Di Pentima <ldipentima at veritasgenetics.com>
Date:   Tue Jul 24 11:31:29 2018 -0300

    12444: Adds tmpdir stats to crunchstat reporting
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima at veritasgenetics.com>

diff --git a/lib/crunchstat/crunchstat.go b/lib/crunchstat/crunchstat.go
index 056ef0d18..714e7929a 100644
--- a/lib/crunchstat/crunchstat.go
+++ b/lib/crunchstat/crunchstat.go
@@ -17,6 +17,7 @@ import (
 	"os"
 	"strconv"
 	"strings"
+	"syscall"
 	"time"
 )
 
@@ -55,10 +56,11 @@ type Reporter struct {
 	// Where to write statistics. Must not be nil.
 	Logger *log.Logger
 
-	reportedStatFile map[string]string
-	lastNetSample    map[string]ioSample
-	lastDiskSample   map[string]ioSample
-	lastCPUSample    cpuSample
+	reportedStatFile    map[string]string
+	lastNetSample       map[string]ioSample
+	lastDiskIOSample    map[string]ioSample
+	lastCPUSample       cpuSample
+	lastDiskSpaceSample diskSpaceSample
 
 	done    chan struct{} // closed when we should stop reporting
 	flushed chan struct{} // closed when we have made our last report
@@ -216,14 +218,14 @@ func (r *Reporter) doBlkIOStats() {
 			continue
 		}
 		delta := ""
-		if prev, ok := r.lastDiskSample[dev]; ok {
+		if prev, ok := r.lastDiskIOSample[dev]; ok {
 			delta = fmt.Sprintf(" -- interval %.4f seconds %d write %d read",
 				sample.sampleTime.Sub(prev.sampleTime).Seconds(),
 				sample.txBytes-prev.txBytes,
 				sample.rxBytes-prev.rxBytes)
 		}
 		r.Logger.Printf("blkio:%s %d write %d read%s\n", dev, sample.txBytes, sample.rxBytes, delta)
-		r.lastDiskSample[dev] = sample
+		r.lastDiskIOSample[dev] = sample
 	}
 }
 
@@ -302,6 +304,42 @@ func (r *Reporter) doNetworkStats() {
 	}
 }
 
+type diskSpaceSample struct {
+	hasData    bool
+	sampleTime time.Time
+	total      uint64
+	used       uint64
+	available  uint64
+}
+
+func (r *Reporter) doDiskSpaceStats() {
+	s := syscall.Statfs_t{}
+	err := syscall.Statfs("/tmp", &s)
+	if err != nil {
+		return
+	}
+	bs := uint64(s.Bsize)
+	nextSample := diskSpaceSample{
+		hasData:    true,
+		sampleTime: time.Now(),
+		total:      s.Blocks * bs,
+		used:       (s.Blocks - s.Bavail) * bs,
+		available:  s.Bavail * bs,
+	}
+
+	var delta string
+	if r.lastDiskSpaceSample.hasData {
+		prev := r.lastDiskSpaceSample
+		interval := nextSample.sampleTime.Sub(prev.sampleTime).Seconds()
+		delta = fmt.Sprintf(" -- interval %.4f seconds %d used",
+			interval,
+			int64(nextSample.used-prev.used))
+	}
+	r.Logger.Printf("tmpdir available:%d used:%d total:%d%s\n",
+		nextSample.available, nextSample.used, nextSample.total, delta)
+	r.lastDiskSpaceSample = nextSample
+}
+
 type cpuSample struct {
 	hasData    bool // to distinguish the zero value from real data
 	sampleTime time.Time
@@ -382,7 +420,7 @@ func (r *Reporter) run() {
 	}
 
 	r.lastNetSample = make(map[string]ioSample)
-	r.lastDiskSample = make(map[string]ioSample)
+	r.lastDiskIOSample = make(map[string]ioSample)
 
 	ticker := time.NewTicker(r.PollPeriod)
 	for {
@@ -390,6 +428,7 @@ func (r *Reporter) run() {
 		r.doCPUStats()
 		r.doBlkIOStats()
 		r.doNetworkStats()
+		r.doDiskSpaceStats()
 		select {
 		case <-r.done:
 			return
diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index ad433bb3b..7e2dc0127 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -107,7 +107,7 @@ func runCommand(argv []string, logger *log.Logger) error {
 	}
 
 	// Funnel stderr through our channel
-	stderr_pipe, err := cmd.StderrPipe()
+	stderrPipe, err := cmd.StderrPipe()
 	if err != nil {
 		logger.Fatalln("error in StderrPipe:", err)
 	}
@@ -121,7 +121,7 @@ func runCommand(argv []string, logger *log.Logger) error {
 	os.Stdin.Close()
 	os.Stdout.Close()
 
-	copyPipeToChildLog(stderr_pipe, log.New(os.Stderr, "", 0))
+	copyPipeToChildLog(stderrPipe, log.New(os.Stderr, "", 0))
 
 	return cmd.Wait()
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list