Skip to content

Commit cc1aa3c

Browse files
committed
Add metrics for btrfs commit statistics
Signed-off-by: Maarten van den Berg <[email protected]>
1 parent 2ecbe97 commit cc1aa3c

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

collector/btrfs_linux.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,30 @@ func (c *btrfsCollector) getMetrics(s *btrfs.Stats, ioctlStats *btrfsIoctlFsStat
275275
metricType: prometheus.GaugeValue,
276276
value: float64(s.Allocation.GlobalRsvSize),
277277
},
278+
{
279+
name: "commits_total",
280+
desc: "The total number of commits that have occurred.",
281+
metricType: prometheus.CounterValue,
282+
value: float64(s.CommitStats.Commits),
283+
},
284+
{
285+
name: "last_commit_seconds",
286+
desc: "Duration of the most recent commit, in seconds.",
287+
metricType: prometheus.GaugeValue,
288+
value: float64(s.CommitStats.LastCommitMs) / 1000,
289+
},
290+
{
291+
name: "max_commit_seconds",
292+
desc: "Duration of the slowest commit, in seconds.",
293+
metricType: prometheus.GaugeValue,
294+
value: float64(s.CommitStats.MaxCommitMs) / 1000,
295+
},
296+
{
297+
name: "commit_seconds_total",
298+
desc: "Sum of the duration of all commits, in seconds.",
299+
metricType: prometheus.CounterValue,
300+
value: float64(s.CommitStats.TotalCommitMs) / 1000,
301+
},
278302
}
279303

280304
// Information about data, metadata and system data.

collector/btrfs_linux_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var expectedBtrfsMetrics = [][]btrfsMetric{
2727
{
2828
{name: "info", value: 1, extraLabel: []string{"label"}, extraLabelValue: []string{"fixture"}},
2929
{name: "global_rsv_size_bytes", value: 1.6777216e+07},
30+
{name: "commits_total", value: 258051, metricType: 1},
31+
{name: "last_commit_seconds", value: 1.0},
32+
{name: "max_commit_seconds", value: 51.462},
33+
{name: "commit_seconds_total", value: 47836.090, metricType: 1},
3034
{name: "reserved_bytes", value: 0, extraLabel: []string{"block_group_type"}, extraLabelValue: []string{"data"}},
3135
{name: "used_bytes", value: 8.08189952e+08, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid0"}},
3236
{name: "size_bytes", value: 2.147483648e+09, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid0"}},
@@ -45,6 +49,10 @@ var expectedBtrfsMetrics = [][]btrfsMetric{
4549
{
4650
{name: "info", value: 1, extraLabel: []string{"label"}, extraLabelValue: []string{""}},
4751
{name: "global_rsv_size_bytes", value: 1.6777216e+07},
52+
{name: "commits_total", value: 0, metricType: 1},
53+
{name: "last_commit_seconds", value: 0},
54+
{name: "max_commit_seconds", value: 0},
55+
{name: "commit_seconds_total", value: 0, metricType: 1},
4856
{name: "reserved_bytes", value: 0, extraLabel: []string{"block_group_type"}, extraLabelValue: []string{"data"}},
4957
{name: "used_bytes", value: 0, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid5"}},
5058
{name: "size_bytes", value: 6.44087808e+08, extraLabel: []string{"block_group_type", "mode"}, extraLabelValue: []string{"data", "raid5"}},

collector/fixtures/e2e-64k-page-output.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid1",uuid="0abb2
161161
node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2
162162
node_btrfs_allocation_ratio{block_group_type="system",mode="raid1",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 2
163163
node_btrfs_allocation_ratio{block_group_type="system",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2
164+
# HELP node_btrfs_commit_seconds_total Sum of the duration of all commits, in seconds.
165+
# TYPE node_btrfs_commit_seconds_total counter
166+
node_btrfs_commit_seconds_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 47836.09
167+
node_btrfs_commit_seconds_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
168+
# HELP node_btrfs_commits_total The total number of commits that have occurred.
169+
# TYPE node_btrfs_commits_total counter
170+
node_btrfs_commits_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 258051
171+
node_btrfs_commits_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
164172
# HELP node_btrfs_device_size_bytes Size of a device that is part of the filesystem.
165173
# TYPE node_btrfs_device_size_bytes gauge
166174
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.
177185
# TYPE node_btrfs_info gauge
178186
node_btrfs_info{label="",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1
179187
node_btrfs_info{label="fixture",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1
188+
# HELP node_btrfs_last_commit_seconds Duration of the most recent commit, in seconds.
189+
# TYPE node_btrfs_last_commit_seconds gauge
190+
node_btrfs_last_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1
191+
node_btrfs_last_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
192+
# HELP node_btrfs_max_commit_seconds Duration of the slowest commit, in seconds.
193+
# TYPE node_btrfs_max_commit_seconds gauge
194+
node_btrfs_max_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 51.462
195+
node_btrfs_max_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
180196
# HELP node_btrfs_reserved_bytes Amount of space reserved for a data type
181197
# TYPE node_btrfs_reserved_bytes gauge
182198
node_btrfs_reserved_bytes{block_group_type="data",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 0

collector/fixtures/e2e-output.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid1",uuid="0abb2
161161
node_btrfs_allocation_ratio{block_group_type="metadata",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2
162162
node_btrfs_allocation_ratio{block_group_type="system",mode="raid1",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 2
163163
node_btrfs_allocation_ratio{block_group_type="system",mode="raid6",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 2
164+
# HELP node_btrfs_commit_seconds_total Sum of the duration of all commits, in seconds.
165+
# TYPE node_btrfs_commit_seconds_total counter
166+
node_btrfs_commit_seconds_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 47836.09
167+
node_btrfs_commit_seconds_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
168+
# HELP node_btrfs_commits_total The total number of commits that have occurred.
169+
# TYPE node_btrfs_commits_total counter
170+
node_btrfs_commits_total{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 258051
171+
node_btrfs_commits_total{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
164172
# HELP node_btrfs_device_size_bytes Size of a device that is part of the filesystem.
165173
# TYPE node_btrfs_device_size_bytes gauge
166174
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.
177185
# TYPE node_btrfs_info gauge
178186
node_btrfs_info{label="",uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 1
179187
node_btrfs_info{label="fixture",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1
188+
# HELP node_btrfs_last_commit_seconds Duration of the most recent commit, in seconds.
189+
# TYPE node_btrfs_last_commit_seconds gauge
190+
node_btrfs_last_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 1
191+
node_btrfs_last_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
192+
# HELP node_btrfs_max_commit_seconds Duration of the slowest commit, in seconds.
193+
# TYPE node_btrfs_max_commit_seconds gauge
194+
node_btrfs_max_commit_seconds{uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 51.462
195+
node_btrfs_max_commit_seconds{uuid="7f07c59f-6136-449c-ab87-e1cf2328731b"} 0
180196
# HELP node_btrfs_reserved_bytes Amount of space reserved for a data type
181197
# TYPE node_btrfs_reserved_bytes gauge
182198
node_btrfs_reserved_bytes{block_group_type="data",uuid="0abb23a9-579b-43e6-ad30-227ef47fcb9d"} 0

collector/fixtures/sys.ttar

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,14 @@ Lines: 1
44894489
4096
44904490
Mode: 444
44914491
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4492+
Path: sys/fs/btrfs/0abb23a9-579b-43e6-ad30-227ef47fcb9d/commit_stats
4493+
Lines: 4
4494+
commits 258051
4495+
last_commit_ms 1000
4496+
max_commit_ms 51462
4497+
total_commit_ms 47836090EOF
4498+
Mode: 644
4499+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44924500
Directory: sys/fs/btrfs/0abb23a9-579b-43e6-ad30-227ef47fcb9d/devices
44934501
Mode: 755
44944502
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)