|
1 #!/usr/bin/env python |
|
2 |
|
3 # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. |
|
4 # Use of this source code is governed by a BSD-style license that can be |
|
5 # found in the LICENSE file. |
|
6 |
|
7 """ |
|
8 Print system memory information. |
|
9 """ |
|
10 |
|
11 import psutil |
|
12 from psutil._compat import print_ |
|
13 |
|
14 def to_meg(n): |
|
15 return str(int(n / 1024 / 1024)) + "M" |
|
16 |
|
17 def pprint_ntuple(nt): |
|
18 for name in nt._fields: |
|
19 value = getattr(nt, name) |
|
20 if name != 'percent': |
|
21 value = to_meg(value) |
|
22 print_('%-10s : %7s' % (name.capitalize(), value)) |
|
23 |
|
24 def main(): |
|
25 print_('MEMORY\n------') |
|
26 pprint_ntuple(psutil.virtual_memory()) |
|
27 print_('\nSWAP\n----') |
|
28 pprint_ntuple(psutil.swap_memory()) |
|
29 |
|
30 if __name__ == '__main__': |
|
31 main() |