'Update RAM memory stats using the input method.'

@GlancesPlugin._check_decorator
@GlancesPlugin._log_result_decorator
def update(self):

    self.reset()
    if (self.input_method == 'local'):
        vm_stats = psutil.virtual_memory()
        self.reset()
        for mem in ['total', 'available', 'percent', 'used', 'free', 'active', 'inactive', 'buffers', 'cached', 'wired', 'shared']:
            if hasattr(vm_stats, mem):
                self.stats[mem] = getattr(vm_stats, mem)
        self.stats['free'] = self.stats['available']
        if hasattr(self.stats, 'buffers'):
            self.stats['free'] += self.stats['buffers']
        if hasattr(self.stats, 'cached'):
            self.stats['free'] += self.stats['cached']
        self.stats['used'] = (self.stats['total'] - self.stats['free'])
    elif (self.input_method == 'snmp'):
        if (self.short_system_name in ('windows', 'esxi')):
            try:
                fs_stat = self.get_stats_snmp(snmp_oid=snmp_oid[self.short_system_name], bulk=True)
            except KeyError:
                self.reset()
            else:
                for fs in fs_stat:
                    if (fs in ('Physical    Memory', 'Real    Memory')):
                        self.stats['total'] = (int(fs_stat[fs]['size']) * int(fs_stat[fs]['alloc_unit']))
                        self.stats['used'] = (int(fs_stat[fs]['used']) * int(fs_stat[fs]['alloc_unit']))
                        self.stats['percent'] = float(((self.stats['used'] * 100) / self.stats['total']))
                        self.stats['free'] = (self.stats['total'] - self.stats['used'])
                        break
        else:
            self.stats = self.get_stats_snmp(snmp_oid=snmp_oid['default'])
            if (self.stats['total'] == ''):
                self.reset()
                return self.stats
            for key in iterkeys(self.stats):
                if (self.stats[key] != ''):
                    self.stats[key] = (float(self.stats[key]) * 1024)
            self.stats['free'] = ((self.stats['free'] - self.stats['total']) + (self.stats['buffers'] + self.stats['cached']))
            self.stats['used'] = (self.stats['total'] - self.stats['free'])
            self.stats['percent'] = float((((self.stats['total'] - self.stats['free']) / self.stats['total']) * 100))
    return self.stats
