python/psutil/examples/meminfo.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rwxr-xr-x

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 #!/usr/bin/env python
     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.
     7 """
     8 Print system memory information.
     9 """
    11 import psutil
    12 from psutil._compat import print_
    14 def to_meg(n):
    15     return str(int(n / 1024 / 1024)) + "M"
    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))
    24 def main():
    25     print_('MEMORY\n------')
    26     pprint_ntuple(psutil.virtual_memory())
    27     print_('\nSWAP\n----')
    28     pprint_ntuple(psutil.swap_memory())
    30 if __name__ == '__main__':
    31     main()

mercurial