Custom mom hook for Memory reporting

Hi,
I wanted to display information on memory on mom hosts and I could not find anything aside from the memory available as ressources so I thought I could share this hook with others. It only grab /proc/meminfo and reports as resources_available. Since all jobs are not necessarily submitted with memory requirements, it could be interesting to have status reports on memory. Freely inspired by the scratch and home size hooks.
Feel free to propose improvments.

import pbs

def get_memory():
        with open('/proc/meminfo', 'r') as mem:
                ret = {}
                for i in mem:
                        sline = i.split()
                        ret[sline[0][:-1]] = pbs.size( "%skb" % int(sline[1]) )
        return ret

mem_info = get_memory()

try:
        dyn_res = ["MemTotal", "MemFree", "MemAvailable", "SwapTotal", "SwapFree"]

        vnl = pbs.event().vnode_list
        local_node = pbs.get_local_nodename()

        for k in dyn_res:
                vnl[local_node].resources_available[k.lower()] = mem_info[k]

except SystemExit:
        pass

except:
        e = pbs.event()
        e.reject("%s hook failed with %s. Please contact Admin" % \
        (e.hook_name, sys.exc_info()[:2]))

The result is:

node
     Mom = node.localdomain
     Port = 15002
     pbs_version = 14.0.1
     ntype = PBS
     state = free
     pcpus = 24
     resources_available.arch = linux
     resources_available.home = 2928783428kb
     resources_available.host = node
     resources_available.mem = 231002988kb
     resources_available.memavailable = 228099596kb
     resources_available.memfree = 189917692kb
     resources_available.memtotal = 231002988kb
     resources_available.ncpus = 24
     resources_available.scratch = 931852512kb
     resources_available.swapfree = 20483800kb
     resources_available.swaptotal = 20496380kb
     resources_available.vnode = node
     resources_assigned.accelerator_memory = 0kb
     resources_assigned.mem = 0kb
     resources_assigned.naccelerators = 0
     resources_assigned.ncpus = 0
     resources_assigned.vmem = 0kb
     resv_enable = True
     sharing = default_shared

Of course mem and memtotal are the same.