summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/prometheus/procfs/xfs
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-03-13 12:54:22 -0400
committerGitHub <noreply@github.com>2017-03-13 12:54:22 -0400
commitc281ee3b61e8ab53ff118866d72618ae8cce582b (patch)
tree776e7bdf6c8bfbb9a1dee5976496ab065959991f /vendor/github.com/prometheus/procfs/xfs
parent3ada7a41a7fb13abef19dd63dc56b720900dbaa9 (diff)
downloadchat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.gz
chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.tar.bz2
chat-c281ee3b61e8ab53ff118866d72618ae8cce582b.zip
Updating server dependancies. Also adding github.com/jaytaylor/html2text and gopkg.in/gomail.v2 (#5748)
Diffstat (limited to 'vendor/github.com/prometheus/procfs/xfs')
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/parse.go361
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/parse_test.go446
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/xfs.go158
3 files changed, 965 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/procfs/xfs/parse.go b/vendor/github.com/prometheus/procfs/xfs/parse.go
new file mode 100644
index 000000000..d1285fa6c
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/xfs/parse.go
@@ -0,0 +1,361 @@
+// Copyright 2017 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package xfs
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "log"
+ "strconv"
+ "strings"
+)
+
+// ParseStats parses a Stats from an input io.Reader, using the format
+// found in /proc/fs/xfs/stat.
+func ParseStats(r io.Reader) (*Stats, error) {
+ const (
+ // Fields parsed into stats structures.
+ fieldExtentAlloc = "extent_alloc"
+ fieldAbt = "abt"
+ fieldBlkMap = "blk_map"
+ fieldBmbt = "bmbt"
+ fieldDir = "dir"
+ fieldTrans = "trans"
+ fieldIg = "ig"
+ fieldLog = "log"
+ fieldRw = "rw"
+ fieldAttr = "attr"
+ fieldIcluster = "icluster"
+ fieldVnodes = "vnodes"
+ fieldBuf = "buf"
+ fieldXpc = "xpc"
+
+ // Unimplemented at this time due to lack of documentation.
+ fieldPushAil = "push_ail"
+ fieldXstrat = "xstrat"
+ fieldAbtb2 = "abtb2"
+ fieldAbtc2 = "abtc2"
+ fieldBmbt2 = "bmbt2"
+ fieldIbt2 = "ibt2"
+ fieldFibt2 = "fibt2"
+ fieldQm = "qm"
+ fieldDebug = "debug"
+ )
+
+ var xfss Stats
+
+ s := bufio.NewScanner(r)
+ for s.Scan() {
+ // Expect at least a string label and a single integer value, ex:
+ // - abt 0
+ // - rw 1 2
+ ss := strings.Fields(string(s.Bytes()))
+ if len(ss) < 2 {
+ continue
+ }
+ label := ss[0]
+
+ // Extended precision counters are uint64 values.
+ if label == fieldXpc {
+ us, err := parseUint64s(ss[1:])
+ if err != nil {
+ return nil, err
+ }
+
+ xfss.ExtendedPrecision, err = extendedPrecisionStats(us)
+ if err != nil {
+ return nil, err
+ }
+
+ continue
+ }
+
+ // All other counters are uint32 values.
+ us, err := parseUint32s(ss[1:])
+ if err != nil {
+ return nil, err
+ }
+
+ switch label {
+ case fieldExtentAlloc:
+ xfss.ExtentAllocation, err = extentAllocationStats(us)
+ case fieldAbt:
+ xfss.AllocationBTree, err = btreeStats(us)
+ case fieldBlkMap:
+ xfss.BlockMapping, err = blockMappingStats(us)
+ case fieldBmbt:
+ xfss.BlockMapBTree, err = btreeStats(us)
+ case fieldDir:
+ xfss.DirectoryOperation, err = directoryOperationStats(us)
+ case fieldTrans:
+ xfss.Transaction, err = transactionStats(us)
+ case fieldIg:
+ xfss.InodeOperation, err = inodeOperationStats(us)
+ case fieldLog:
+ xfss.LogOperation, err = logOperationStats(us)
+ case fieldRw:
+ xfss.ReadWrite, err = readWriteStats(us)
+ case fieldAttr:
+ xfss.AttributeOperation, err = attributeOperationStats(us)
+ case fieldIcluster:
+ xfss.InodeClustering, err = inodeClusteringStats(us)
+ case fieldVnodes:
+ xfss.Vnode, err = vnodeStats(us)
+ case fieldBuf:
+ xfss.Buffer, err = bufferStats(us)
+ }
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return &xfss, s.Err()
+}
+
+// extentAllocationStats builds an ExtentAllocationStats from a slice of uint32s.
+func extentAllocationStats(us []uint32) (ExtentAllocationStats, error) {
+ if l := len(us); l != 4 {
+ return ExtentAllocationStats{}, fmt.Errorf("incorrect number of values for XFS extent allocation stats: %d", l)
+ }
+
+ return ExtentAllocationStats{
+ ExtentsAllocated: us[0],
+ BlocksAllocated: us[1],
+ ExtentsFreed: us[2],
+ BlocksFreed: us[3],
+ }, nil
+}
+
+// btreeStats builds a BTreeStats from a slice of uint32s.
+func btreeStats(us []uint32) (BTreeStats, error) {
+ if l := len(us); l != 4 {
+ return BTreeStats{}, fmt.Errorf("incorrect number of values for XFS btree stats: %d", l)
+ }
+
+ return BTreeStats{
+ Lookups: us[0],
+ Compares: us[1],
+ RecordsInserted: us[2],
+ RecordsDeleted: us[3],
+ }, nil
+}
+
+// BlockMappingStat builds a BlockMappingStats from a slice of uint32s.
+func blockMappingStats(us []uint32) (BlockMappingStats, error) {
+ if l := len(us); l != 7 {
+ return BlockMappingStats{}, fmt.Errorf("incorrect number of values for XFS block mapping stats: %d", l)
+ }
+
+ return BlockMappingStats{
+ Reads: us[0],
+ Writes: us[1],
+ Unmaps: us[2],
+ ExtentListInsertions: us[3],
+ ExtentListDeletions: us[4],
+ ExtentListLookups: us[5],
+ ExtentListCompares: us[6],
+ }, nil
+}
+
+// DirectoryOperationStats builds a DirectoryOperationStats from a slice of uint32s.
+func directoryOperationStats(us []uint32) (DirectoryOperationStats, error) {
+ if l := len(us); l != 4 {
+ return DirectoryOperationStats{}, fmt.Errorf("incorrect number of values for XFS directory operation stats: %d", l)
+ }
+
+ return DirectoryOperationStats{
+ Lookups: us[0],
+ Creates: us[1],
+ Removes: us[2],
+ Getdents: us[3],
+ }, nil
+}
+
+// TransactionStats builds a TransactionStats from a slice of uint32s.
+func transactionStats(us []uint32) (TransactionStats, error) {
+ if l := len(us); l != 3 {
+ return TransactionStats{}, fmt.Errorf("incorrect number of values for XFS transaction stats: %d", l)
+ }
+
+ return TransactionStats{
+ Sync: us[0],
+ Async: us[1],
+ Empty: us[2],
+ }, nil
+}
+
+// InodeOperationStats builds an InodeOperationStats from a slice of uint32s.
+func inodeOperationStats(us []uint32) (InodeOperationStats, error) {
+ if l := len(us); l != 7 {
+ return InodeOperationStats{}, fmt.Errorf("incorrect number of values for XFS inode operation stats: %d", l)
+ }
+
+ return InodeOperationStats{
+ Attempts: us[0],
+ Found: us[1],
+ Recycle: us[2],
+ Missed: us[3],
+ Duplicate: us[4],
+ Reclaims: us[5],
+ AttributeChange: us[6],
+ }, nil
+}
+
+// LogOperationStats builds a LogOperationStats from a slice of uint32s.
+func logOperationStats(us []uint32) (LogOperationStats, error) {
+ if l := len(us); l != 5 {
+ return LogOperationStats{}, fmt.Errorf("incorrect number of values for XFS log operation stats: %d", l)
+ }
+
+ return LogOperationStats{
+ Writes: us[0],
+ Blocks: us[1],
+ NoInternalBuffers: us[2],
+ Force: us[3],
+ ForceSleep: us[4],
+ }, nil
+}
+
+// ReadWriteStats builds a ReadWriteStats from a slice of uint32s.
+func readWriteStats(us []uint32) (ReadWriteStats, error) {
+ if l := len(us); l != 2 {
+ return ReadWriteStats{}, fmt.Errorf("incorrect number of values for XFS read write stats: %d", l)
+ }
+
+ return ReadWriteStats{
+ Read: us[0],
+ Write: us[1],
+ }, nil
+}
+
+// AttributeOperationStats builds an AttributeOperationStats from a slice of uint32s.
+func attributeOperationStats(us []uint32) (AttributeOperationStats, error) {
+ if l := len(us); l != 4 {
+ return AttributeOperationStats{}, fmt.Errorf("incorrect number of values for XFS attribute operation stats: %d", l)
+ }
+
+ return AttributeOperationStats{
+ Get: us[0],
+ Set: us[1],
+ Remove: us[2],
+ List: us[3],
+ }, nil
+}
+
+// InodeClusteringStats builds an InodeClusteringStats from a slice of uint32s.
+func inodeClusteringStats(us []uint32) (InodeClusteringStats, error) {
+ if l := len(us); l != 3 {
+ return InodeClusteringStats{}, fmt.Errorf("incorrect number of values for XFS inode clustering stats: %d", l)
+ }
+
+ return InodeClusteringStats{
+ Iflush: us[0],
+ Flush: us[1],
+ FlushInode: us[2],
+ }, nil
+}
+
+// VnodeStats builds a VnodeStats from a slice of uint32s.
+func vnodeStats(us []uint32) (VnodeStats, error) {
+ // The attribute "Free" appears to not be available on older XFS
+ // stats versions. Therefore, 7 or 8 elements may appear in
+ // this slice.
+ l := len(us)
+ log.Println(l)
+ if l != 7 && l != 8 {
+ return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l)
+ }
+
+ s := VnodeStats{
+ Active: us[0],
+ Allocate: us[1],
+ Get: us[2],
+ Hold: us[3],
+ Release: us[4],
+ Reclaim: us[5],
+ Remove: us[6],
+ }
+
+ // Skip adding free, unless it is present. The zero value will
+ // be used in place of an actual count.
+ if l == 7 {
+ return s, nil
+ }
+
+ s.Free = us[7]
+ return s, nil
+}
+
+// BufferStats builds a BufferStats from a slice of uint32s.
+func bufferStats(us []uint32) (BufferStats, error) {
+ if l := len(us); l != 9 {
+ return BufferStats{}, fmt.Errorf("incorrect number of values for XFS buffer stats: %d", l)
+ }
+
+ return BufferStats{
+ Get: us[0],
+ Create: us[1],
+ GetLocked: us[2],
+ GetLockedWaited: us[3],
+ BusyLocked: us[4],
+ MissLocked: us[5],
+ PageRetries: us[6],
+ PageFound: us[7],
+ GetRead: us[8],
+ }, nil
+}
+
+// ExtendedPrecisionStats builds an ExtendedPrecisionStats from a slice of uint32s.
+func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) {
+ if l := len(us); l != 3 {
+ return ExtendedPrecisionStats{}, fmt.Errorf("incorrect number of values for XFS extended precision stats: %d", l)
+ }
+
+ return ExtendedPrecisionStats{
+ FlushBytes: us[0],
+ WriteBytes: us[1],
+ ReadBytes: us[2],
+ }, nil
+}
+
+// parseUint32s parses a slice of strings into a slice of uint32s.
+func parseUint32s(ss []string) ([]uint32, error) {
+ us := make([]uint32, 0, len(ss))
+ for _, s := range ss {
+ u, err := strconv.ParseUint(s, 10, 32)
+ if err != nil {
+ return nil, err
+ }
+
+ us = append(us, uint32(u))
+ }
+
+ return us, nil
+}
+
+// parseUint64s parses a slice of strings into a slice of uint64s.
+func parseUint64s(ss []string) ([]uint64, error) {
+ us := make([]uint64, 0, len(ss))
+ for _, s := range ss {
+ u, err := strconv.ParseUint(s, 10, 64)
+ if err != nil {
+ return nil, err
+ }
+
+ us = append(us, u)
+ }
+
+ return us, nil
+}
diff --git a/vendor/github.com/prometheus/procfs/xfs/parse_test.go b/vendor/github.com/prometheus/procfs/xfs/parse_test.go
new file mode 100644
index 000000000..11ddb7425
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/xfs/parse_test.go
@@ -0,0 +1,446 @@
+// Copyright 2017 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package xfs_test
+
+import (
+ "log"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/prometheus/procfs"
+ "github.com/prometheus/procfs/xfs"
+)
+
+func TestParseStats(t *testing.T) {
+ tests := []struct {
+ name string
+ s string
+ fs bool
+ stats *xfs.Stats
+ invalid bool
+ }{
+ {
+ name: "empty file OK",
+ },
+ {
+ name: "short or empty lines and unknown labels ignored",
+ s: "one\n\ntwo 1 2 3\n",
+ stats: &xfs.Stats{},
+ },
+ {
+ name: "bad uint32",
+ s: "extent_alloc XXX",
+ invalid: true,
+ },
+ {
+ name: "bad uint64",
+ s: "xpc XXX",
+ invalid: true,
+ },
+ {
+ name: "extent_alloc bad",
+ s: "extent_alloc 1",
+ invalid: true,
+ },
+ {
+ name: "extent_alloc OK",
+ s: "extent_alloc 1 2 3 4",
+ stats: &xfs.Stats{
+ ExtentAllocation: xfs.ExtentAllocationStats{
+ ExtentsAllocated: 1,
+ BlocksAllocated: 2,
+ ExtentsFreed: 3,
+ BlocksFreed: 4,
+ },
+ },
+ },
+ {
+ name: "abt bad",
+ s: "abt 1",
+ invalid: true,
+ },
+ {
+ name: "abt OK",
+ s: "abt 1 2 3 4",
+ stats: &xfs.Stats{
+ AllocationBTree: xfs.BTreeStats{
+ Lookups: 1,
+ Compares: 2,
+ RecordsInserted: 3,
+ RecordsDeleted: 4,
+ },
+ },
+ },
+ {
+ name: "blk_map bad",
+ s: "blk_map 1",
+ invalid: true,
+ },
+ {
+ name: "blk_map OK",
+ s: "blk_map 1 2 3 4 5 6 7",
+ stats: &xfs.Stats{
+ BlockMapping: xfs.BlockMappingStats{
+ Reads: 1,
+ Writes: 2,
+ Unmaps: 3,
+ ExtentListInsertions: 4,
+ ExtentListDeletions: 5,
+ ExtentListLookups: 6,
+ ExtentListCompares: 7,
+ },
+ },
+ },
+ {
+ name: "bmbt bad",
+ s: "bmbt 1",
+ invalid: true,
+ },
+ {
+ name: "bmbt OK",
+ s: "bmbt 1 2 3 4",
+ stats: &xfs.Stats{
+ BlockMapBTree: xfs.BTreeStats{
+ Lookups: 1,
+ Compares: 2,
+ RecordsInserted: 3,
+ RecordsDeleted: 4,
+ },
+ },
+ },
+ {
+ name: "dir bad",
+ s: "dir 1",
+ invalid: true,
+ },
+ {
+ name: "dir OK",
+ s: "dir 1 2 3 4",
+ stats: &xfs.Stats{
+ DirectoryOperation: xfs.DirectoryOperationStats{
+ Lookups: 1,
+ Creates: 2,
+ Removes: 3,
+ Getdents: 4,
+ },
+ },
+ },
+ {
+ name: "trans bad",
+ s: "trans 1",
+ invalid: true,
+ },
+ {
+ name: "trans OK",
+ s: "trans 1 2 3",
+ stats: &xfs.Stats{
+ Transaction: xfs.TransactionStats{
+ Sync: 1,
+ Async: 2,
+ Empty: 3,
+ },
+ },
+ },
+ {
+ name: "ig bad",
+ s: "ig 1",
+ invalid: true,
+ },
+ {
+ name: "ig OK",
+ s: "ig 1 2 3 4 5 6 7",
+ stats: &xfs.Stats{
+ InodeOperation: xfs.InodeOperationStats{
+ Attempts: 1,
+ Found: 2,
+ Recycle: 3,
+ Missed: 4,
+ Duplicate: 5,
+ Reclaims: 6,
+ AttributeChange: 7,
+ },
+ },
+ },
+ {
+ name: "log bad",
+ s: "log 1",
+ invalid: true,
+ },
+ {
+ name: "log OK",
+ s: "log 1 2 3 4 5",
+ stats: &xfs.Stats{
+ LogOperation: xfs.LogOperationStats{
+ Writes: 1,
+ Blocks: 2,
+ NoInternalBuffers: 3,
+ Force: 4,
+ ForceSleep: 5,
+ },
+ },
+ },
+ {
+ name: "rw bad",
+ s: "rw 1",
+ invalid: true,
+ },
+ {
+ name: "rw OK",
+ s: "rw 1 2",
+ stats: &xfs.Stats{
+ ReadWrite: xfs.ReadWriteStats{
+ Read: 1,
+ Write: 2,
+ },
+ },
+ },
+ {
+ name: "attr bad",
+ s: "attr 1",
+ invalid: true,
+ },
+ {
+ name: "attr OK",
+ s: "attr 1 2 3 4",
+ stats: &xfs.Stats{
+ AttributeOperation: xfs.AttributeOperationStats{
+ Get: 1,
+ Set: 2,
+ Remove: 3,
+ List: 4,
+ },
+ },
+ },
+ {
+ name: "icluster bad",
+ s: "icluster 1",
+ invalid: true,
+ },
+ {
+ name: "icluster OK",
+ s: "icluster 1 2 3",
+ stats: &xfs.Stats{
+ InodeClustering: xfs.InodeClusteringStats{
+ Iflush: 1,
+ Flush: 2,
+ FlushInode: 3,
+ },
+ },
+ },
+ {
+ name: "vnodes bad",
+ s: "vnodes 1",
+ invalid: true,
+ },
+ {
+ name: "vnodes (missing free) OK",
+ s: "vnodes 1 2 3 4 5 6 7",
+ stats: &xfs.Stats{
+ Vnode: xfs.VnodeStats{
+ Active: 1,
+ Allocate: 2,
+ Get: 3,
+ Hold: 4,
+ Release: 5,
+ Reclaim: 6,
+ Remove: 7,
+ },
+ },
+ },
+ {
+ name: "vnodes (with free) OK",
+ s: "vnodes 1 2 3 4 5 6 7 8",
+ stats: &xfs.Stats{
+ Vnode: xfs.VnodeStats{
+ Active: 1,
+ Allocate: 2,
+ Get: 3,
+ Hold: 4,
+ Release: 5,
+ Reclaim: 6,
+ Remove: 7,
+ Free: 8,
+ },
+ },
+ },
+ {
+ name: "buf bad",
+ s: "buf 1",
+ invalid: true,
+ },
+ {
+ name: "buf OK",
+ s: "buf 1 2 3 4 5 6 7 8 9",
+ stats: &xfs.Stats{
+ Buffer: xfs.BufferStats{
+ Get: 1,
+ Create: 2,
+ GetLocked: 3,
+ GetLockedWaited: 4,
+ BusyLocked: 5,
+ MissLocked: 6,
+ PageRetries: 7,
+ PageFound: 8,
+ GetRead: 9,
+ },
+ },
+ },
+ {
+ name: "xpc bad",
+ s: "xpc 1",
+ invalid: true,
+ },
+ {
+ name: "xpc OK",
+ s: "xpc 1 2 3",
+ stats: &xfs.Stats{
+ ExtendedPrecision: xfs.ExtendedPrecisionStats{
+ FlushBytes: 1,
+ WriteBytes: 2,
+ ReadBytes: 3,
+ },
+ },
+ },
+ {
+ name: "fixtures OK",
+ fs: true,
+ stats: &xfs.Stats{
+ ExtentAllocation: xfs.ExtentAllocationStats{
+ ExtentsAllocated: 92447,
+ BlocksAllocated: 97589,
+ ExtentsFreed: 92448,
+ BlocksFreed: 93751,
+ },
+ AllocationBTree: xfs.BTreeStats{
+ Lookups: 0,
+ Compares: 0,
+ RecordsInserted: 0,
+ RecordsDeleted: 0,
+ },
+ BlockMapping: xfs.BlockMappingStats{
+ Reads: 1767055,
+ Writes: 188820,
+ Unmaps: 184891,
+ ExtentListInsertions: 92447,
+ ExtentListDeletions: 92448,
+ ExtentListLookups: 2140766,
+ ExtentListCompares: 0,
+ },
+ BlockMapBTree: xfs.BTreeStats{
+ Lookups: 0,
+ Compares: 0,
+ RecordsInserted: 0,
+ RecordsDeleted: 0,
+ },
+ DirectoryOperation: xfs.DirectoryOperationStats{
+ Lookups: 185039,
+ Creates: 92447,
+ Removes: 92444,
+ Getdents: 136422,
+ },
+ Transaction: xfs.TransactionStats{
+ Sync: 706,
+ Async: 944304,
+ Empty: 0,
+ },
+ InodeOperation: xfs.InodeOperationStats{
+ Attempts: 185045,
+ Found: 58807,
+ Recycle: 0,
+ Missed: 126238,
+ Duplicate: 0,
+ Reclaims: 33637,
+ AttributeChange: 22,
+ },
+ LogOperation: xfs.LogOperationStats{
+ Writes: 2883,
+ Blocks: 113448,
+ NoInternalBuffers: 9,
+ Force: 17360,
+ ForceSleep: 739,
+ },
+ ReadWrite: xfs.ReadWriteStats{
+ Read: 107739,
+ Write: 94045,
+ },
+ AttributeOperation: xfs.AttributeOperationStats{
+ Get: 4,
+ Set: 0,
+ Remove: 0,
+ List: 0,
+ },
+ InodeClustering: xfs.InodeClusteringStats{
+ Iflush: 8677,
+ Flush: 7849,
+ FlushInode: 135802,
+ },
+ Vnode: xfs.VnodeStats{
+ Active: 92601,
+ Allocate: 0,
+ Get: 0,
+ Hold: 0,
+ Release: 92444,
+ Reclaim: 92444,
+ Remove: 92444,
+ Free: 0,
+ },
+ Buffer: xfs.BufferStats{
+ Get: 2666287,
+ Create: 7122,
+ GetLocked: 2659202,
+ GetLockedWaited: 3599,
+ BusyLocked: 2,
+ MissLocked: 7085,
+ PageRetries: 0,
+ PageFound: 10297,
+ GetRead: 7085,
+ },
+ ExtendedPrecision: xfs.ExtendedPrecisionStats{
+ FlushBytes: 399724544,
+ WriteBytes: 92823103,
+ ReadBytes: 86219234,
+ },
+ },
+ },
+ }
+
+ for i, tt := range tests {
+ t.Logf("[%02d] test %q", i, tt.name)
+
+ var (
+ stats *xfs.Stats
+ err error
+ )
+
+ if tt.s != "" {
+ stats, err = xfs.ParseStats(strings.NewReader(tt.s))
+ }
+ if tt.fs {
+ stats, err = procfs.FS("../fixtures").XFSStats()
+ }
+
+ if tt.invalid && err == nil {
+ t.Error("expected an error, but none occurred")
+ }
+ if !tt.invalid && err != nil {
+ t.Errorf("unexpected error: %v", err)
+ }
+
+ if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
+ log.Printf("stats: %#v", have)
+ t.Errorf("unexpected XFS stats:\nwant:\n%v\nhave:\n%v", want, have)
+ }
+ }
+}
diff --git a/vendor/github.com/prometheus/procfs/xfs/xfs.go b/vendor/github.com/prometheus/procfs/xfs/xfs.go
new file mode 100644
index 000000000..ed77d907a
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/xfs/xfs.go
@@ -0,0 +1,158 @@
+// Copyright 2017 The Prometheus Authors
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package xfs provides access to statistics exposed by the XFS filesystem.
+package xfs
+
+// Stats contains XFS filesystem runtime statistics, parsed from
+// /proc/fs/xfs/stat.
+//
+// The names and meanings of each statistic were taken from
+// http://xfs.org/index.php/Runtime_Stats and xfs_stats.h in the Linux
+// kernel source. Most counters are uint32s (same data types used in
+// xfs_stats.h), but some of the "extended precision stats" are uint64s.
+type Stats struct {
+ ExtentAllocation ExtentAllocationStats
+ AllocationBTree BTreeStats
+ BlockMapping BlockMappingStats
+ BlockMapBTree BTreeStats
+ DirectoryOperation DirectoryOperationStats
+ Transaction TransactionStats
+ InodeOperation InodeOperationStats
+ LogOperation LogOperationStats
+ ReadWrite ReadWriteStats
+ AttributeOperation AttributeOperationStats
+ InodeClustering InodeClusteringStats
+ Vnode VnodeStats
+ Buffer BufferStats
+ ExtendedPrecision ExtendedPrecisionStats
+}
+
+// ExtentAllocationStats contains statistics regarding XFS extent allocations.
+type ExtentAllocationStats struct {
+ ExtentsAllocated uint32
+ BlocksAllocated uint32
+ ExtentsFreed uint32
+ BlocksFreed uint32
+}
+
+// BTreeStats contains statistics regarding an XFS internal B-tree.
+type BTreeStats struct {
+ Lookups uint32
+ Compares uint32
+ RecordsInserted uint32
+ RecordsDeleted uint32
+}
+
+// BlockMappingStats contains statistics regarding XFS block maps.
+type BlockMappingStats struct {
+ Reads uint32
+ Writes uint32
+ Unmaps uint32
+ ExtentListInsertions uint32
+ ExtentListDeletions uint32
+ ExtentListLookups uint32
+ ExtentListCompares uint32
+}
+
+// DirectoryOperationStats contains statistics regarding XFS directory entries.
+type DirectoryOperationStats struct {
+ Lookups uint32
+ Creates uint32
+ Removes uint32
+ Getdents uint32
+}
+
+// TransactionStats contains statistics regarding XFS metadata transactions.
+type TransactionStats struct {
+ Sync uint32
+ Async uint32
+ Empty uint32
+}
+
+// InodeOperationStats contains statistics regarding XFS inode operations.
+type InodeOperationStats struct {
+ Attempts uint32
+ Found uint32
+ Recycle uint32
+ Missed uint32
+ Duplicate uint32
+ Reclaims uint32
+ AttributeChange uint32
+}
+
+// LogOperationStats contains statistics regarding the XFS log buffer.
+type LogOperationStats struct {
+ Writes uint32
+ Blocks uint32
+ NoInternalBuffers uint32
+ Force uint32
+ ForceSleep uint32
+}
+
+// ReadWriteStats contains statistics regarding the number of read and write
+// system calls for XFS filesystems.
+type ReadWriteStats struct {
+ Read uint32
+ Write uint32
+}
+
+// AttributeOperationStats contains statistics regarding manipulation of
+// XFS extended file attributes.
+type AttributeOperationStats struct {
+ Get uint32
+ Set uint32
+ Remove uint32
+ List uint32
+}
+
+// InodeClusteringStats contains statistics regarding XFS inode clustering
+// operations.
+type InodeClusteringStats struct {
+ Iflush uint32
+ Flush uint32
+ FlushInode uint32
+}
+
+// VnodeStats contains statistics regarding XFS vnode operations.
+type VnodeStats struct {
+ Active uint32
+ Allocate uint32
+ Get uint32
+ Hold uint32
+ Release uint32
+ Reclaim uint32
+ Remove uint32
+ Free uint32
+}
+
+// BufferStats contains statistics regarding XFS read/write I/O buffers.
+type BufferStats struct {
+ Get uint32
+ Create uint32
+ GetLocked uint32
+ GetLockedWaited uint32
+ BusyLocked uint32
+ MissLocked uint32
+ PageRetries uint32
+ PageFound uint32
+ GetRead uint32
+}
+
+// ExtendedPrecisionStats contains high precision counters used to track the
+// total number of bytes read, written, or flushed, during XFS operations.
+type ExtendedPrecisionStats struct {
+ FlushBytes uint64
+ WriteBytes uint64
+ ReadBytes uint64
+}