def meminfo():
 def linux_meminfo():
  '\n        linux specific implementation of meminfo\n        '
  ret = {}
  try:
   with salt.utils.fopen('/proc/meminfo', 'r') as fp_:
    stats = fp_.read()
  except IOError:
   pass
  else:
   for line in stats.splitlines():
    if (not line):
     continue
    comps = line.split()
    comps[0] = comps[0].replace(':', '')
    ret[comps[0]] = {'value': comps[1]}
    if (len(comps) > 2):
     ret[comps[0]]['unit'] = comps[2]
  return ret
 def freebsd_meminfo():
  '\n        freebsd specific implementation of meminfo\n        '
  sysctlvm = __salt__['cmd.run']('sysctl vm').splitlines()
  sysctlvm = [x for x in sysctlvm if x.startswith('vm')]
  sysctlvm = [x.split(':') for x in sysctlvm]
  sysctlvm = [[y.strip() for y in x] for x in sysctlvm]
  sysctlvm = [x for x in sysctlvm if x[1]]
  ret = {}
  for line in sysctlvm:
   ret[line[0]] = line[1]
  sysctlvmtot = __salt__['cmd.run']('sysctl -n vm.vmtotal').splitlines()
  sysctlvmtot = [x for x in sysctlvmtot if x]
  ret['vm.vmtotal'] = sysctlvmtot
  return ret
 get_version = {'Linux': linux_meminfo, 'FreeBSD': freebsd_meminfo}
 errmsg = 'This method is unsupported on the current operating system!'
 return get_version.get(__grains__['kernel'], (lambda : errmsg))()

def meminfo ( ) : def linux_meminfo ( ) : ret = { } try : with salt . utils . fopen ( '/proc/meminfo' , 'r' ) as fp_ : stats = fp_ . read ( ) except IOError : pass else : for line in stats . splitlines ( ) : if ( not line ) : continue comps = line . split ( ) comps [ 0 ] = comps [ 0 ] . replace ( ':' , '' ) ret [ comps [ 0 ] ] = { 'value' : comps [ 1 ] } if ( len ( comps ) > 2 ) : ret [ comps [ 0 ] ] [ 'unit' ] = comps [ 2 ] return ret def freebsd_meminfo ( ) : sysctlvm = __salt__ [ 'cmd.run' ] ( 'sysctl vm' ) . splitlines ( ) sysctlvm = [ x for x in sysctlvm if x . startswith ( 'vm' ) ] sysctlvm = [ x . split ( ':' ) for x in sysctlvm ] sysctlvm = [ [ y . strip ( ) for y in x ] for x in sysctlvm ] sysctlvm = [ x for x in sysctlvm if x [ 1 ] ] ret = { } for line in sysctlvm : ret [ line [ 0 ] ] = line [ 1 ] sysctlvmtot = __salt__ [ 'cmd.run' ] ( 'sysctl -n vm.vmtotal' ) . splitlines ( ) sysctlvmtot = [ x for x in sysctlvmtot if x ] ret [ 'vm.vmtotal' ] = sysctlvmtot return ret get_version = { 'Linux' : linux_meminfo , 'FreeBSD' : freebsd_meminfo } errmsg = 'This method is unsupported on the current operating system!' return get_version . get ( __grains__ [ 'kernel' ] , ( lambda : errmsg ) ) ( )
get memory information from /proc/meminfo .