From 42f28ab8e374137fe3f5d25424489d879d4724f8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 21 Jun 2017 19:06:17 -0700 Subject: Updating server dependancies (#6712) --- .../github.com/prometheus/procfs/sysfs/.gitignore | 1 + .../prometheus/procfs/sysfs/fixtures.tar.gz | Bin 0 -> 2865 bytes .../procfs/sysfs/fixtures/fs/xfs/sda1/stats/stats | 1 - .../procfs/sysfs/fixtures/fs/xfs/sdb1/stats/stats | 1 - vendor/github.com/prometheus/procfs/sysfs/fs.go | 26 +++++++++++++ .../github.com/prometheus/procfs/sysfs/fs_test.go | 42 +++++++++++++++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 vendor/github.com/prometheus/procfs/sysfs/.gitignore create mode 100644 vendor/github.com/prometheus/procfs/sysfs/fixtures.tar.gz delete mode 100644 vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sda1/stats/stats delete mode 100644 vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sdb1/stats/stats (limited to 'vendor/github.com/prometheus/procfs/sysfs') diff --git a/vendor/github.com/prometheus/procfs/sysfs/.gitignore b/vendor/github.com/prometheus/procfs/sysfs/.gitignore new file mode 100644 index 000000000..67fc140b9 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/sysfs/.gitignore @@ -0,0 +1 @@ +fixtures/ diff --git a/vendor/github.com/prometheus/procfs/sysfs/fixtures.tar.gz b/vendor/github.com/prometheus/procfs/sysfs/fixtures.tar.gz new file mode 100644 index 000000000..88035b7ce Binary files /dev/null and b/vendor/github.com/prometheus/procfs/sysfs/fixtures.tar.gz differ diff --git a/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sda1/stats/stats b/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sda1/stats/stats deleted file mode 100644 index 0db7520bf..000000000 --- a/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sda1/stats/stats +++ /dev/null @@ -1 +0,0 @@ -extent_alloc 1 0 0 0 diff --git a/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sdb1/stats/stats b/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sdb1/stats/stats deleted file mode 100644 index 85a038402..000000000 --- a/vendor/github.com/prometheus/procfs/sysfs/fixtures/fs/xfs/sdb1/stats/stats +++ /dev/null @@ -1 +0,0 @@ -extent_alloc 2 0 0 0 diff --git a/vendor/github.com/prometheus/procfs/sysfs/fs.go b/vendor/github.com/prometheus/procfs/sysfs/fs.go index 8e8380083..fb15d438a 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/fs.go +++ b/vendor/github.com/prometheus/procfs/sysfs/fs.go @@ -18,6 +18,7 @@ import ( "os" "path/filepath" + "github.com/prometheus/procfs/bcache" "github.com/prometheus/procfs/xfs" ) @@ -80,3 +81,28 @@ func (fs FS) XFSStats() ([]*xfs.Stats, error) { return stats, nil } + +// BcacheStats retrieves bcache runtime statistics for each bcache. +func (fs FS) BcacheStats() ([]*bcache.Stats, error) { + matches, err := filepath.Glob(fs.Path("fs/bcache/*-*")) + if err != nil { + return nil, err + } + + stats := make([]*bcache.Stats, 0, len(matches)) + for _, uuidPath := range matches { + // "*-*" in glob above indicates the name of the bcache. + name := filepath.Base(uuidPath) + + // stats + s, err := bcache.GetStats(uuidPath) + if err != nil { + return nil, err + } + + s.Name = name + stats = append(stats, s) + } + + return stats, nil +} diff --git a/vendor/github.com/prometheus/procfs/sysfs/fs_test.go b/vendor/github.com/prometheus/procfs/sysfs/fs_test.go index d7f2b736b..2b7402eca 100644 --- a/vendor/github.com/prometheus/procfs/sysfs/fs_test.go +++ b/vendor/github.com/prometheus/procfs/sysfs/fs_test.go @@ -64,3 +64,45 @@ func TestFSXFSStats(t *testing.T) { } } } + +func TestFSBcacheStats(t *testing.T) { + stats, err := FS("fixtures").BcacheStats() + if err != nil { + t.Fatalf("failed to parse bcache stats: %v", err) + } + + tests := []struct { + name string + bdevs int + caches int + }{ + { + name: "deaddd54-c735-46d5-868e-f331c5fd7c74", + bdevs: 1, + caches: 1, + }, + } + + const expect = 1 + + if l := len(stats); l != expect { + t.Fatalf("unexpected number of bcache stats: %d", l) + } + if l := len(tests); l != expect { + t.Fatalf("unexpected number of tests: %d", l) + } + + for i, tt := range tests { + if want, got := tt.name, stats[i].Name; want != got { + t.Errorf("unexpected stats name:\nwant: %q\nhave: %q", want, got) + } + + if want, got := tt.bdevs, len(stats[i].Bdevs); want != got { + t.Errorf("unexpected value allocated:\nwant: %d\nhave: %d", want, got) + } + + if want, got := tt.caches, len(stats[i].Caches); want != got { + t.Errorf("unexpected value allocated:\nwant: %d\nhave: %d", want, got) + } + } +} -- cgit v1.2.3-1-g7c22