aboutsummaryrefslogtreecommitdiffstats
path: root/sos/plugins/filesys.py
blob: 06be7058d604158381c12fd51d3b64201f06de4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
### This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin
import os
import re
from itertools import *

class Filesys(Plugin, RedHatPlugin, UbuntuPlugin):
    """information on filesystems
    """

    plugin_name = 'filesys'

    option_list = [("lsof", 'gathers information on all open files', 'slow', False),
                   ("dumpe2fs", 'dump filesystem information', 'slow', False)]

    def setup(self):
        self.add_copy_specs([
            "/proc/filesystems",
            "/etc/fstab",
            "/proc/self/mounts",
            "/proc/mounts",
            "/proc/mdstat",
            "/etc/raidtab",
            "/etc/mdadm.conf"])
        mounts = self.get_cmd_output_now("mount -l", root_symlink = "mount")

        self.add_cmd_output("findmnt")
        self.add_cmd_output("df -al", root_symlink = "df")
        self.add_cmd_output("df -ali")
        if self.get_option('lsof'):
            self.add_cmd_output("lsof -b +M -n -l -P", root_symlink = "lsof")
        self.add_cmd_output("blkid -c /dev/null")
        self.add_cmd_output("lsblk")

        part_titlep = re.compile("^major")
        blankp = re.compile("^$")
        partlist = []
        devlist = []
        try:
            for line in open('/proc/partitions'):
                if((bool(part_titlep.match(line))) | (bool(blankp.match(line)))):
                    continue
                partlist.append('/dev/' + line.split()[-1])
        except IOError:
            exit(1)
        if os.path.exists("hdparm"):
            for dev in partlist:
                ret, hdparm, time = self.call_ext_prog('hdparm -g %s' %(dev))
                if(ret == 0):
                    start_geo = hdparm.strip().split("\n")[-1].strip().split()[-1]
                    if(start_geo == "0"):
      	                devlist.append(dev)
        else:
            # Cheaper heuristic as RHEL* does not ship hdparm for S390(x)
            # Skips least dm-.* correctly
            part_in_disk = re.compile("^/dev/[a-z]+$")
            for dev in partlist:
                if bool(part_in_disk.match(dev)):
                    devlist.append(dev)

        for i in devlist:
            self.add_cmd_output("parted -s %s print" % (i))

        if self.get_option('dumpe2fs'):
            for extfs in izip(self.do_regex_find_all(r"^(/dev/.+) on .+ type ext.\s+", mounts)):
                self.add_cmd_output("dumpe2fs %s" % (extfs))