Ved-vampir | f0089e5 | 2015-03-16 15:52:54 +0300 | [diff] [blame] | 1 | from discover import provides |
| 2 | from utils import SensorInfo, is_dev_accepted |
| 3 | |
| 4 | |
| 5 | # return this values or setted in allowed |
| 6 | ram_fields = [ |
| 7 | 'MemTotal', |
| 8 | 'MemFree', |
| 9 | 'Buffers', |
| 10 | 'Cached', |
| 11 | 'SwapCached', |
| 12 | 'Dirty', |
| 13 | 'Writeback', |
| 14 | 'SwapTotal', |
| 15 | 'SwapFree' |
| 16 | ] |
| 17 | |
| 18 | |
| 19 | @provides("system-ram") |
| 20 | def sysram_stat(disallowed_prefixes=None, allowed_prefixes=None): |
| 21 | if allowed_prefixes is None: |
| 22 | allowed_prefixes = ram_fields |
| 23 | results = {} |
| 24 | for line in open('/proc/meminfo'): |
| 25 | vals = line.split() |
| 26 | dev_name = vals[0] |
| 27 | |
| 28 | dev_ok = is_dev_accepted(dev_name, |
| 29 | disallowed_prefixes, |
| 30 | allowed_prefixes) |
| 31 | |
| 32 | if dev_ok: |
| 33 | results[dev_name] = SensorInfo(int(vals[1]), False) |
| 34 | return results |