75d414eccbe59c031dd31bfab43084b7d26ca643
1#
2# zfs.py
3#
4# Look through ZFS logs to find latest scrub and its output.
5# Note that ZFS doesn't normally produce logs in /var/log, so for this to
6# work, we must set up a cron job to dump `zpool iostat` into a file (hourly
7# is best):
8#
9# zpool iostat > /var/log/zpool.log && zpool status >> /var/log/zpool.log
10#
11# The file gets overwritten every hour, so if more than one scrub occurs
12# between logparse runs, it will only get the latest one.
13#
14# TODO: add feature to specify pools to check in config file
15# TODO: set critical value for scrub data repair
16#
17
18import re
19import sys, traceback
20
21from formatting import *
22from logparse.util import readlog
23from logparse.config import prefs
24
25import logging
26logger = logging.getLogger(__name__)
27
28def parse_log():
29
30 logger.debug("Starting zfs section")
31 section = Section("zfs")
32
33 zfslog = readlog(prefs.get("logs", "zfs"))
34
35 logger.debug("Analysing zpool log")
36 pool = re.search('.*---\n(\w*)', zfslog).group(1)
37 scrub = re.search('.* scrub repaired (\d+\s*\w+) in .* with (\d+) errors on (\w+)\s+(\w+)\s+(\d+)\s+(\d{1,2}:\d{2}):\d+\s+(\d{4})', zfslog)
38 logger.debug("Found groups {0}".format(scrub.groups()))
39 iostat = re.search('.*---\n\w*\s*(\S*)\s*(\S*)\s', zfslog)
40 scrubrepairs = scruberrors = scrubdate = None
41 alloc = iostat.group(1)
42 free = iostat.group(2)
43
44 try:
45 scrubrepairs = scrub.group(1)
46 scruberrors = scrub.group(2)
47 scrubdate = ' '.join(scrub.groups()[2:-1])
48 except Exception as e:
49 logger.debug("Error getting scrub data: " + str(e))
50 traceback.print_exc(limit=2, file=sys.stdout)
51
52 if (scrubdate != None):
53 scrub_data = Data("Scrub of " + pool + " on " + scrubdate)
54 scrub_data.items = [scrubrepairs + " repaired", scruberrors + " errors", alloc + " used", free + " free"]
55 else:
56 scrub_data = Data(pool)
57 scrub_data.items = [alloc + " used", free + " free"]
58
59 section.append_data(scrub_data)
60
61 logger.info("Finished zfs section")
62 return section