Skip to content

Commit

Permalink
Merge pull request kubernetes#444 from arkadijs/btrfs
Browse files Browse the repository at this point in the history
Process BTRFS and whole-disk filesystem stats
  • Loading branch information
vmarmol committed Feb 6, 2015
2 parents 238a761 + 02fc9da commit f2efed3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"github.com/golang/glog"
)

var partitionRegex = regexp.MustCompile("(:?s|xv)d[a-z]+\\d")
var partitionRegex = regexp.MustCompile("^(:?(:?s|xv)d[a-z]+\\d*|dm-\\d+)$")

type partition struct {
mountpoint string
Expand All @@ -58,7 +58,7 @@ func NewFsInfo() (FsInfo, error) {
}
partitions := make(map[string]partition, 0)
for _, mount := range mounts {
if !strings.HasPrefix(mount.Fstype, "ext") {
if !strings.HasPrefix(mount.Fstype, "ext") && mount.Fstype != "btrfs" {
continue
}
// Avoid bind mounts.
Expand Down
12 changes: 11 additions & 1 deletion fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ func TestGetDiskStatsMap(t *testing.T) {
if err != nil {
t.Errorf("Error calling getDiskStatMap %s", err)
}
if len(diskStatsMap) != 20 {
if len(diskStatsMap) != 30 {
t.Errorf("diskStatsMap %+v not valid", diskStatsMap)
}
keySet := map[string]string{
"/dev/sda": "/dev/sda",
"/dev/sdb": "/dev/sdb",
"/dev/sdc": "/dev/sdc",
"/dev/sdd": "/dev/sdd",
"/dev/sde": "/dev/sde",
"/dev/sdf": "/dev/sdf",
"/dev/sdg": "/dev/sdg",
"/dev/sdh": "/dev/sdh",
"/dev/sdb1": "/dev/sdb1",
"/dev/sdb2": "/dev/sdb2",
"/dev/sda1": "/dev/sda1",
Expand All @@ -47,6 +55,8 @@ func TestGetDiskStatsMap(t *testing.T) {
"/dev/sdg2": "/dev/sdg2",
"/dev/sdh1": "/dev/sdh1",
"/dev/sdh2": "/dev/sdh2",
"/dev/dm-0": "/dev/dm-0",
"/dev/dm-1": "/dev/dm-1",
}

for device := range diskStatsMap {
Expand Down
4 changes: 3 additions & 1 deletion fs/test_resources/diskstats
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@
8 98 sdg2 395 0 3154 299 1 0 8 0 0 299 299
8 112 sdh 931 1157 7601 895 2 0 16 0 0 841 895
8 113 sdh1 477 1147 3895 264 1 0 8 0 0 264 264
8 114 sdh2 395 0 3154 311 1 0 8 0 0 311 311
8 114 sdh2 395 0 3154 311 1 0 8 0 0 311 311
252 0 dm-0 1251094 0 108121362 21287644 111848 0 52908472 22236936 0 4838500 43524784
252 1 dm-1 58415638 0 2682446960 1719953592 20048040 0 543988240 1975572544 0 262085340 3695556828

0 comments on commit f2efed3

Please sign in to comment.