From 584181f8e7015e8fbd319be9a5a9341d8f3d64df Mon Sep 17 00:00:00 2001 From: Steven Kreuzer Date: Fri, 13 Dec 2019 22:15:45 -0500 Subject: [PATCH] Expose xs_qm_dquot_unused XFS counter Add support for exposing the xs_qm_dquot_unused XFS statistic which appears in Linux 4.20 and later. Signed-off-by: Steven Kreuzer --- xfs/parse.go | 18 ++++++++++++++---- xfs/parse_test.go | 22 ++++++++++++++++++++++ xfs/xfs.go | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/xfs/parse.go b/xfs/parse.go index f3f30d7c9..ba3afea3e 100644 --- a/xfs/parse.go +++ b/xfs/parse.go @@ -381,11 +381,15 @@ func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) { } func quotaManagerStats(us []uint32) (QuotaManagerStats, error) { - if l := len(us); l < 8 { - return QuotaManagerStats{}, fmt.Errorf("insufficient number of values for XFS quota stats expecting at least 8, got: %d", l) + // The "Unused" attribute first appears in Linux 4.20 + // As a result either 8 or 9 elements may appear in this slice depending on + // the kernel version. + l := len(us) + if l != 8 && l != 9 { + return QuotaManagerStats{}, fmt.Errorf("incorrect number of values for XFS quota stats: %d", l) } - return QuotaManagerStats{ + s := QuotaManagerStats{ Reclaims: us[0], ReclaimMisses: us[1], DquoteDups: us[2], @@ -394,7 +398,13 @@ func quotaManagerStats(us []uint32) (QuotaManagerStats, error) { Wants: us[5], ShakeReclaims: us[6], InactReclaims: us[7], - }, nil + } + + if l > 8 { + s.Unused = us[8] + } + + return s, nil } func debugStats(us []uint32) (DebugStats, error) { diff --git a/xfs/parse_test.go b/xfs/parse_test.go index 1774665af..b799f4b2c 100644 --- a/xfs/parse_test.go +++ b/xfs/parse_test.go @@ -368,6 +368,11 @@ func TestParseStats(t *testing.T) { s: "qm 1 2 3 4 5 6 7", invalid: true, }, + { + name: "qm bad", + s: "qm 1 2 3 4 5 6 7 8 9 10", + invalid: true, + }, { name: "qm OK", s: "qm 1 2 3 4 5 6 7 8", @@ -384,6 +389,23 @@ func TestParseStats(t *testing.T) { }, }, }, + { + name: "qm OK", + s: "qm 1 2 3 4 5 6 7 8 9", + stats: &xfs.Stats{ + QuotaManager: xfs.QuotaManagerStats{ + Reclaims: 1, + ReclaimMisses: 2, + DquoteDups: 3, + CacheMisses: 4, + CacheHits: 5, + Wants: 6, + ShakeReclaims: 7, + InactReclaims: 8, + Unused: 9, + }, + }, + }, { name: "abtb2 bad", s: "abtb2 1 2 3 4 5 6", diff --git a/xfs/xfs.go b/xfs/xfs.go index 018a0b89c..cc8b36bed 100644 --- a/xfs/xfs.go +++ b/xfs/xfs.go @@ -202,6 +202,7 @@ type QuotaManagerStats struct { Wants uint32 ShakeReclaims uint32 InactReclaims uint32 + Unused uint32 } // XstratStats contains statistics regarding bytes processed by the XFS daemon.