Skip to content

Commit

Permalink
btrfs_stats.py: Precompiled regular expressions improve performance (#…
Browse files Browse the repository at this point in the history
…210)

* btrfs_stats.py: Precompiled regular expressions improve performance

Signed-off-by: wangqing <wangqing@uniontech.com>
  • Loading branch information
wangqingfree committed Apr 23, 2024
1 parent ef8c077 commit bfc8aa9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion btrfs_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from prometheus_client import CollectorRegistry, Gauge, generate_latest


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


def get_btrfs_mount_points():
"""List all btrfs mount points.
Expand Down Expand Up @@ -47,7 +50,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 bfc8aa9

Please sign in to comment.