[ARVADOS] updated: c83d732301d7f192895db6c112e0bee29614e314
git at public.curoverse.com
git at public.curoverse.com
Tue Oct 14 10:07:00 EDT 2014
Summary of changes:
services/crunchstat/crunchstat.go | 51 +++++++++++++++++-----------------
services/crunchstat/crunchstat_test.go | 39 ++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 25 deletions(-)
create mode 100644 services/crunchstat/crunchstat_test.go
via c83d732301d7f192895db6c112e0bee29614e314 (commit)
via 41270a7c0897f2183b6e58674c450a34b65818e9 (commit)
via d7e558d103f5620c3c0243c0590dd80b470226ed (commit)
via 548683db5343421b9abf3ad629054c6da6237928 (commit)
via d12f645c2be4e9fd6f89689852efe668bc7d1d83 (commit)
from 4be40a40a509d1eaad11c442d137f5ecdeb45e25 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit c83d732301d7f192895db6c112e0bee29614e314
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 14 10:06:11 2014 -0400
3826: Add a couple of easy unit tests.
diff --git a/services/crunchstat/crunchstat_test.go b/services/crunchstat/crunchstat_test.go
new file mode 100644
index 0000000..00cd4d8
--- /dev/null
+++ b/services/crunchstat/crunchstat_test.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "regexp"
+ "testing"
+)
+
+func TestOpenAndReadAllFail(t *testing.T) {
+ log_chan := make(chan string)
+ go func() {
+ defer close(log_chan)
+ if x, err := OpenAndReadAll("/nonexistent/file", log_chan); err == nil {
+ t.Fatalf("Expected error, got %v", x)
+ }
+ }()
+ if _, ok := <-log_chan; !ok {
+ t.Fatalf("Expected error message about nonexistent file")
+ }
+ if msg, ok := <-log_chan; ok {
+ t.Fatalf("Expected channel to close, got %s", msg)
+ }
+}
+
+func TestOpenAndReadAllSuccess(t *testing.T) {
+ log_chan := make(chan string)
+ go func() {
+ defer close(log_chan)
+ data, err := OpenAndReadAll("./crunchstat_test.go", log_chan)
+ if err != nil {
+ t.Fatalf("got error %s", err)
+ }
+ if matched, err := regexp.MatchString("^package main\n", string(data)); err != nil || !matched {
+ t.Fatalf("data failed regexp: %s", err)
+ }
+ }()
+ if msg, ok := <-log_chan; ok {
+ t.Fatalf("Expected channel to close, got %s", msg)
+ }
+}
commit 41270a7c0897f2183b6e58674c450a34b65818e9
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 14 09:13:25 2014 -0400
3826: Change cpu time logging format to match net traffic.
diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index 080b95c..517a209 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -241,23 +241,18 @@ func PollCgroupStats(cgroup Cgroup, stderr chan string, poll int64, stop_poll_ch
var next_sys int64
fmt.Sscanf(string(b), "user %d\nsystem %d", &next_user, &next_sys)
+ delta := ""
if elapsed > 0 && last_user != -1 {
- user_diff := next_user - last_user
- sys_diff := next_sys - last_sys
- // {*_diff} == {1/user_hz}-second
- // ticks of CPU core consumed in an
- // {elapsed}-second interval.
- //
- // We report this as CPU core usage
- // (i.e., 1.0 == one pegged core). We
- // also report the number of cores
- // (maximum possible usage).
- user := float64(user_diff) / elapsed / user_hz
- sys := float64(sys_diff) / elapsed / user_hz
-
- stderr <- fmt.Sprintf("crunchstat: cpuacct.stat user %.4f sys %.4f cpus %d interval %.4f", user, sys, last_cpucount, elapsed)
+ delta = fmt.Sprintf(" -- interval %.4f seconds %.4f user %.4f sys",
+ elapsed,
+ float64(next_user - last_user) / user_hz,
+ float64(next_sys - last_sys) / user_hz)
}
-
+ stderr <- fmt.Sprintf("crunchstat: cpu %.4f user %.4f sys %d cpus%s",
+ float64(next_user) / user_hz,
+ float64(next_sys) / user_hz,
+ last_cpucount,
+ delta)
last_user = next_user
last_sys = next_sys
}
commit d7e558d103f5620c3c0243c0590dd80b470226ed
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 14 09:12:28 2014 -0400
3826: Skip net/dev lines with unexpected # tokens.
diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index d02af56..080b95c 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -143,7 +143,10 @@ func DoNetworkStats(stderr chan<- string, cgroup Cgroup, lastStat map[string]Net
}
wordIndex++
}
- if ifName == "lo" || ifName == "" { continue }
+ if ifName == "lo" || ifName == "" || wordIndex != 17 {
+ // Skip loopback interface and lines with wrong format
+ continue
+ }
nextSample := NetSample{}
nextSample.sampleTime = sampleTime
nextSample.txBytes = tx
commit 548683db5343421b9abf3ad629054c6da6237928
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 14 08:54:13 2014 -0400
3826: Remove duplicate log message, add missing crunchstat: log prefix.
diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index 26b8bb3..d02af56 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -49,7 +49,7 @@ func OpenAndReadAll(filename string, log_chan chan<- string) ([]byte, error) {
in, err := os.Open(filename)
if err != nil {
if log_chan != nil {
- log_chan <- fmt.Sprintf("open %s: %s", filename, err)
+ log_chan <- fmt.Sprintf("crunchstat: open %s: %s", filename, err)
}
return nil, err
}
@@ -57,7 +57,7 @@ func OpenAndReadAll(filename string, log_chan chan<- string) ([]byte, error) {
{
content, err := ioutil.ReadAll(in)
if err != nil && log_chan != nil {
- log_chan <- fmt.Sprintf("read %s: %s", filename, err)
+ log_chan <- fmt.Sprintf("crunchstat: read %s: %s", filename, err)
}
return content, err
}
@@ -99,7 +99,6 @@ func GetContainerNetStats(stderr chan<- string, cgroup Cgroup) (io.Reader, error
statsFilename := fmt.Sprintf("/proc/%s/net/dev", taskPid)
stats, err := OpenAndReadAll(statsFilename, stderr)
if err != nil {
- stderr <- fmt.Sprintf("crunchstat: open %s: %s", statsFilename, err)
continue
}
return strings.NewReader(string(stats)), nil
commit d12f645c2be4e9fd6f89689852efe668bc7d1d83
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Oct 14 09:17:20 2014 -0400
3826: Tweak log format.
diff --git a/services/crunchstat/crunchstat.go b/services/crunchstat/crunchstat.go
index d47b039..26b8bb3 100644
--- a/services/crunchstat/crunchstat.go
+++ b/services/crunchstat/crunchstat.go
@@ -114,6 +114,7 @@ type NetSample struct {
}
func DoNetworkStats(stderr chan<- string, cgroup Cgroup, lastStat map[string]NetSample) (map[string]NetSample) {
+ sampleTime := time.Now()
stats, err := GetContainerNetStats(stderr, cgroup)
if err != nil { return lastStat }
@@ -145,16 +146,19 @@ func DoNetworkStats(stderr chan<- string, cgroup Cgroup, lastStat map[string]Net
}
if ifName == "lo" || ifName == "" { continue }
nextSample := NetSample{}
- nextSample.sampleTime = time.Now()
+ nextSample.sampleTime = sampleTime
nextSample.txBytes = tx
nextSample.rxBytes = rx
+ var delta string
if lastSample, ok := lastStat[ifName]; ok {
- stderr <- fmt.Sprintf("crunchstat: net %s tx %d +%d rx %d +%d interval %.4f",
- ifName,
- tx, tx - lastSample.txBytes,
- rx, rx - lastSample.rxBytes,
- nextSample.sampleTime.Sub(lastSample.sampleTime).Seconds())
+ interval := nextSample.sampleTime.Sub(lastSample.sampleTime).Seconds()
+ delta = fmt.Sprintf(" -- interval %.4f seconds %d tx %d rx",
+ interval,
+ tx - lastSample.txBytes,
+ rx - lastSample.rxBytes)
}
+ stderr <- fmt.Sprintf("crunchstat: net:%s %d tx %d rx%s",
+ ifName, tx, rx, delta)
lastStat[ifName] = nextSample
}
return lastStat
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list