1 """
2 @copyright: 2011 Mark LaPerriere
3
4 @license:
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 U{http://www.apache.org/licenses/LICENSE-2.0}
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 @summary:
18 A memory auditing plugin that should work on most Redhat-like distros
19
20 @author: Mark LaPerriere
21 @contact: pyhai@mindmind.com
22 @organization: Mind Squared Design / www.mindmind.com
23 @version: 0.1.3
24 @date: Jan 19, 2012
25 """
26 from pyhai.plugins import AuditorPlugin
27 import logging
28
29
30 _logger = logging.getLogger(__name__)
31 _logger.addHandler(logging.NullHandler())
32
34 - def run(self, *args, **kwargs):
35 memory_info = {}
36
37 with open('/proc/meminfo') as fp:
38 for line in fp.read().splitlines():
39 name_value = map(str.strip, str.split(line, ':', 1))
40 if len(name_value) != 2:
41 continue
42 name, value = name_value
43
44 if name == 'MemFree':
45 memory_info['available_bytes'] = long(value.split()[0])
46 elif name == 'MemTotal':
47 memory_info['total_bytes'] = long(value.split()[0])
48 if name == 'SwapFree':
49 memory_info['available_swap_bytes'] = long(value.split()[0])
50 elif name == 'SwapTotal':
51 memory_info['total_swap_bytes'] = long(value.split()[0])
52 if name == 'VmallocFree':
53 memory_info['available_virtual_bytes'] = long(value.split()[0])
54 if name == 'VmallocTotal':
55 memory_info['total_virtual_bytes'] = long(value.split()[0])
56
57 return memory_info
58