Skip to content

Commit

Permalink
btrfs_stats.py: Precompiled regular expressions improve performance
Browse files Browse the repository at this point in the history
Signed-off-by: wangqing <[email protected]>
  • Loading branch information
wangqing committed Apr 18, 2024
1 parent ef8c077 commit edd3766
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion btrfs_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from prometheus_client import CollectorRegistry, Gauge, generate_latest


DEVICE_PATTERN = re.compile(r"^\[([^\]]+)\]\.(\S+)\s+(\d+)$", re.MULTILINE)

def get_btrfs_mount_points():
"""List all btrfs mount points.
Expand Down Expand Up @@ -47,7 +49,7 @@ def get_btrfs_errors(mountpoint):
continue
# Sample line:
# [/dev/vdb1].flush_io_errs 0
m = re.search(r"^\[([^\]]+)\]\.(\S+)\s+(\d+)$", line.decode("utf-8"))
m = DEVICE_PATTERN.match(line.decode("utf-8"))
if not m:
raise RuntimeError("unexpected output from btrfs: '%s'" % line)
yield m.group(1), m.group(2), int(m.group(3))
Expand Down

0 comments on commit edd3766

Please sign in to comment.