Example #1
0
    def run(self, variables):
        os_name = platform.system()
        if os_name != "Linux":
            return

        # Critical memory-in-use threshold %
        CRITICAL_THRESH = 90
        meminfo = self.get_meminfo()

        act_free = meminfo['MemFree'] + meminfo['Buffers'] + meminfo['Cached']
        used = meminfo['MemTotal'] - act_free
        perc_used = (used / meminfo['MemTotal']) * 100

        out, err, return_code = self.shell_call(
            common_path(['/usr/bin/dmesg', '/bin/dmesg']))

        if perc_used >= CRITICAL_THRESH or 'oom-killer' in out:
            res = 'High Memory Use!\nMemTotal: {0:.0f} kib\nUsed: {1:.0f} kib ({2:.0f}%)'.format(
                meminfo['MemTotal'], used, perc_used)

            if 'oom-killer' in out:
                res = res + '\n\noom-killer present in dmesg | tail!\n{}'.format(
                    self.get_ooms(out))

            return res
Example #2
0
    def _getdmesgoutput(self, start_time=None, end_time=None):
        result = []
        out, err, returncode = self.shell_call(common_path(['/usr/bin/dmesg', '/bin/dmesg']), stream=True)
        boot_time = self._get_boot_time()

        dmesg_pattern = re.compile('\[(.*?)\] (.*)')

        for line in out:
            m = dmesg_pattern.match(line)
            dmesg_time = m.group(1).strip()
            timestamp = boot_time + float(dmesg_time)
            if iswithintimerange(timestamp, start_time, end_time):
                message = m.group(2)
                dt = datetime.fromtimestamp(timestamp)
                date_str = dt.strftime('%Y/%m/%d %H:%M:%S')
                result.append(' '.join([date_str, message]))

        if result:
            result.reverse()
            return '\n'.join(result)
Example #3
0
def test_common_path_is_not_found():
    '''Assert that the binary is not present the filesystem.'''
    with patch('os.path.isfile', return_value=False):
        with pytest.raises(FileNotFoundError):
            common_path(['amiga/1200/GuruMeditationError'])
Example #4
0
def test_common_path_found():
    '''Assert that the binary is found on the filesystem.'''
    with patch('os.path.isfile', return_value=True):
        assert common_path(['/usr/bin/dmesg',
                            '/bin/dmesg']) == '/usr/bin/dmesg'