From e8aa4de7c5d0892f5775acbab527cef239ba0629 Mon Sep 17 00:00:00 2001 From: Maarten van den Berg Date: Sun, 14 Jul 2024 14:24:55 +0200 Subject: [PATCH] Add metrics for btrfs commit statistics (#3010) Signed-off-by: Maarten van den Berg --- collector/btrfs_linux.go | 24 ++++++++++++++++++++++ collector/btrfs_linux_test.go | 8 ++++++++ collector/fixtures/e2e-64k-page-output.txt | 16 +++++++++++++++ collector/fixtures/e2e-output.txt | 16 +++++++++++++++ collector/fixtures/sys.ttar | 8 ++++++++ 5 files changed, 72 insertions(+) diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index f1490541..1e5ef293 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go @@ -275,6 +275,30 @@ func (c *btrfsCollector) getMetrics(s *btrfs.Stats, ioctlStats *btrfsIoctlFsStat metricType: prometheus.GaugeValue, value: float64(s.Allocation.GlobalRsvSize), }, + { + name: "commits_total", + desc: "The total number of commits that have occurred.", + metricType: prometheus.CounterValue, + value: float64(s.CommitStats.Commits), + }, + { + name: "last_commit_seconds", + desc: "Duration of the most recent commit, in seconds.", + metricType: prometheus.GaugeValue, + value: float64(s.CommitStats.LastCommitMs) / 1000, + }, + { + name: "max_commit_seconds", + desc: "Duration of the slowest commit, in seconds.", + metricType: prometheus.GaugeValue, + value: float64(s.CommitStats.MaxCommitMs) / 1000, + }, + { + name: "commit_seconds_total", + desc: "Sum of the duration of all commits, in seconds.", + metricType: prometheus.CounterValue, + value: float64(s.CommitStats.TotalCommitMs) / 1000, + }, } // Information about data, metadata and system data. diff --git a/collector/btrfs_linux_test.go b/collector/btrfs_linux_test.go index f9bf7214..c2ed57e5 100644 --- a/collector/btrfs_linux_test.go +++ b/collector/btrfs_linux_test.go @@ -27,6 +27,10 @@ var expectedBtrfsMetrics = [][]btrfsMetric{ { {name: "info", value: 1, extraLabel: []string{"label"}, extraLabelValue: []string{"fixture"}}, {name: "global_rsv_size_bytes", value: 1.6777216e+07}, + {name: "commits_total", value: 258051, metricType: 1}, + {name: "last_commit_seconds", value: 1.0}, + {name: "max_commit_seconds", value: 51.462}, + {name: "commit_seconds_total", value: 47836.090, metricType: 1}, {name: "reserved_bytes", value: 0, extraLabel: []string{"block_group_type"}, extraLabelValue: []string{"data"}}, {name: "used_bytes", value: 8.08189952e+08, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid0"}}, {name: "size_bytes", value: 2.147483648e+09, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid0"}}, @@ -45,6 +49,10 @@ var expectedBtrfsMetrics = [][]btrfsMetric{ { {name: "info", value: 1, extraLabel: []string{"label"}, extraLabelValue: []string{""}}, {name: "global_rsv_size_bytes", value: 1.6777216e+07}, + {name: "commits_total", value: 0, metricType: 1}, + {name: "last_commit_seconds", value: 0}, + {name: "max_commit_seconds", value: 0}, + {name: "commit_seconds_total", value: 0, metricType: 1}, {name: "reserved_bytes", value: 0, extraLabel: []string{"block_group_type"}, extraLabelValue: []string{"data"}}, {name: "used_bytes", value: 0, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid5"}}, {name: "size_bytes", value: 6.44087808e+08, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid5"}}, diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index d3b48571..95d7640f 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -161,6 +161,14 @@ node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid1",uuid="0abb2 node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2 node_btrfs_allocation_ratio{block_group_type="system",mode="raid1",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 2 node_btrfs_allocation_ratio{block_group_type="system",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2 +# HELP node_btrfs_commit_seconds_total Sum of the duration of all commits, in seconds. +# TYPE node_btrfs_commit_seconds_total counter +node_btrfs_commit_seconds_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 47836.09 +node_btrfs_commit_seconds_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 +# HELP node_btrfs_commits_total The total number of commits that have occurred. +# TYPE node_btrfs_commits_total counter +node_btrfs_commits_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 258051 +node_btrfs_commits_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 # HELP node_btrfs_device_size_bytes Size of a device that is part of the filesystem. # TYPE node_btrfs_device_size_bytes gauge node_btrfs_device_size_bytes{device="loop22",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1.073741824e+10 @@ -177,6 +185,14 @@ node_btrfs_global_rsv_size_bytes{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1. # TYPE node_btrfs_info gauge node_btrfs_info{label="",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1 node_btrfs_info{label="fixture",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1 +# HELP node_btrfs_last_commit_seconds Duration of the most recent commit, in seconds. +# TYPE node_btrfs_last_commit_seconds gauge +node_btrfs_last_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1 +node_btrfs_last_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 +# HELP node_btrfs_max_commit_seconds Duration of the slowest commit, in seconds. +# TYPE node_btrfs_max_commit_seconds gauge +node_btrfs_max_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 51.462 +node_btrfs_max_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 # HELP node_btrfs_reserved_bytes Amount of space reserved for a data type # TYPE node_btrfs_reserved_bytes gauge node_btrfs_reserved_bytes{block_group_type="data",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 0 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 1a6448fb..18355b0f 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -161,6 +161,14 @@ node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid1",uuid="0abb2 node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2 node_btrfs_allocation_ratio{block_group_type="system",mode="raid1",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 2 node_btrfs_allocation_ratio{block_group_type="system",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2 +# HELP node_btrfs_commit_seconds_total Sum of the duration of all commits, in seconds. +# TYPE node_btrfs_commit_seconds_total counter +node_btrfs_commit_seconds_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 47836.09 +node_btrfs_commit_seconds_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 +# HELP node_btrfs_commits_total The total number of commits that have occurred. +# TYPE node_btrfs_commits_total counter +node_btrfs_commits_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 258051 +node_btrfs_commits_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 # HELP node_btrfs_device_size_bytes Size of a device that is part of the filesystem. # TYPE node_btrfs_device_size_bytes gauge node_btrfs_device_size_bytes{device="loop22",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1.073741824e+10 @@ -177,6 +185,14 @@ node_btrfs_global_rsv_size_bytes{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1. # TYPE node_btrfs_info gauge node_btrfs_info{label="",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1 node_btrfs_info{label="fixture",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1 +# HELP node_btrfs_last_commit_seconds Duration of the most recent commit, in seconds. +# TYPE node_btrfs_last_commit_seconds gauge +node_btrfs_last_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1 +node_btrfs_last_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 +# HELP node_btrfs_max_commit_seconds Duration of the slowest commit, in seconds. +# TYPE node_btrfs_max_commit_seconds gauge +node_btrfs_max_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 51.462 +node_btrfs_max_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0 # HELP node_btrfs_reserved_bytes Amount of space reserved for a data type # TYPE node_btrfs_reserved_bytes gauge node_btrfs_reserved_bytes{block_group_type="data",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 0 diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar index 2cac29e4..6fcf094d 100644 --- a/collector/fixtures/sys.ttar +++ b/collector/fixtures/sys.ttar @@ -4489,6 +4489,14 @@ Lines: 1 4096 Mode: 444 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/fs/btrfs/0abb23a9-579b-43e6-ad30-227ef47fcb9d/commit_stats +Lines: 4 +commits 258051 +last_commit_ms 1000 +max_commit_ms 51462 +total_commit_ms 47836090EOF +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: sys/fs/btrfs/0abb23a9-579b-43e6-ad30-227ef47fcb9d/devices Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -