I'd like to parse the btrfs scrub statistics that btrfs places in a file named /var/lib/btrfs/scrub.status.<uuid>
. The file effectively consists of key/value pairs where key and value are separated by semicolons and tuples are separated by a pipe ("|") character:
scrub status:1
b5872f47-c87e-47ac-b036-4f2725cf6dc6:1|data_extents_scrubbed:4996799|tree_extents_scrubbed:1436139|data_bytes_scrubbed:156663988224|tree_bytes_scrubbed:23529701376|read_errors:0|csum_errors:0|verify_errors:0|no_csum:733729|csum_discards:0|super_errors:0|malloc_errors:0|uncorrectable_errors:0|corrected_errors:0|last_physical:202959224832|t_start:1597847400|t_resumed:0|duration:67|canceled:0|finished:1
In the end I'd like to emit each key/value pair on a separate line such as (this will serve as Prometheus metrics):
scrub status 1
data_extents_scrubbed 4996799
tree_extents_scrubbed 1436139
[...]
I have made various attempts to accomplish this nested parsing using sed
/awk
, but have failed so far.
Any hints how to accomplish this are much appreciated!
sed -r 's/^(([^:]*):([^|]*)[|]?)+$/\2 \3\n/g' scrub.status.<uid>
. But this only emits the last key/value pair of a line. – Thilo-Alexander Ginkel Aug 19 '20 at 22:02