o
    va.                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlZdddd	d
ddd	ddddddd	dddd	dddd	dddd	dddd	dddd	dddd	dddd	dZdddddddddd d!dddd d!d"Z	dd#d$d%gZ
G d&d' d'eZdS )(zVirtual memory plugin.    )logger)iterkeys)GlancesPluginNz Total physical memory available.bytesK)descriptionunitZ
min_symbolaC  The actual amount of available memory that can be given instantly to processes that request more memory in bytes; this is calculated by summing different memory values depending on the platform (e.g. free + buffers + cached on Linux) and it is supposed to be used to monitor actual memory usage in a cross platform fashion.zEThe percentage usage calculated as (total - available) / total * 100.percent)r   r   zkMemory used, calculated differently depending on the platform and designed for informational purposes only.zMemory not being used at all (zeroed) that is readily available; note that this doesn't reflect the actual memory available (use 'available' instead).zM*(UNIX)*: memory currently in use or very recently used, and so it is in RAM.z,*(UNIX)*: memory that is marked as not used.z;*(Linux, BSD)*: cache for things like file system metadata.z)*(Linux, BSD)*: cache for various things.zW*(BSD, macOS)*: memory that is marked to always stay in RAM. It is never moved to disk.zJ*(BSD)*: memory that may be simultaneously accessed by multiple processes.total	availabler	   usedfreeactiveinactivebufferscachedZwiredsharedz1.3.6.1.4.1.2021.4.5.0z1.3.6.1.4.1.2021.4.11.0z1.3.6.1.4.1.2021.4.13.0z1.3.6.1.4.1.2021.4.14.0z1.3.6.1.4.1.2021.4.15.0)r   r   r   r   r   z1.3.6.1.2.1.25.2.3.1.3z1.3.6.1.2.1.25.2.3.1.4z1.3.6.1.2.1.25.2.3.1.5z1.3.6.1.2.1.25.2.3.1.6)Z	mnt_point
alloc_unitsizer   )defaultwindowsesxizRAM memory usage%)namer   Zy_unitc                       sL   e Zd ZdZd fdd	Zejejdd Z fddZ	dd	d
Z
  ZS )Pluginz1Glances' memory plugin.

    stats is a dict
    Nc                    s"   t t| j||ttd d| _dS )zInit the plugin.)argsconfigitems_history_listfields_descriptionTN)superr   __init__r   r   Zdisplay_curse)selfr   r   	__class__ =/usr/lib/python3/dist-packages/glances/plugins/glances_mem.pyr!   h   s   
zPlugin.__init__c                 C   s<  |   }| jdkrQt }|   dD ]}t||r!t||||< q|d |d< t|dr7|d  |d 7  < t|drF|d  |d 7  < |d |d  |d< n| jd	kr| jd
v rz| jt	| j dd}W n t
yu   |   Y nw |D ]D}|dv rt|| d t|| d  |d< t|| d t|| d  |d< t|d d |d  |d< |d |d  |d<  nqxnZ| jt	d d}|d dkr|   | jS t|D ]}|| dkrt|| d ||< q|d |d  |d |d   |d< |d |d  |d< t|d |d  |d  d |d< || _| jS )z/Update RAM memory stats using the input method.Zlocalr
   r   r   r   r   r   r   Zsnmp)r   r   T)snmp_oidZbulk)zPhysical MemoryzReal Memoryr   r   d   r	   r   )r'    i   )Zget_init_valueZinput_methodpsutilZvirtual_memoryresethasattrgetattrZshort_system_nameZget_stats_snmpr'   KeyErrorintfloatstatsr   )r"   r1   Zvm_statsZmemZfs_statZfskeyr%   r%   r&   updater   sZ   





$$$$zPlugin.updatec                    sX   t t|   | j| jd | jd d| jd d< dD ]}|| jv r)d| j| d< qd	S )
zUpdate stats views.r   r   )Zmaximumr	   
decoration)r   r   r   r   TZoptionalN)r    r   update_viewsZget_alert_logr1   Zviews)r"   r2   r#   r%   r&   r5      s   $
zPlugin.update_viewsc              	   C   sJ  g }| j r	|  r|S dd}|| |d d| | d}|| | d| j d d }|| || jddd	 || j	d
ddd || 
  || j	ddd || j	dddd || 
  || j	ddd || j	dddd || 
  || j	ddd || j	dddd |S )z2Return the dict to display in the curse interface.z{}ZMEMZTITLEz {:2}r	   z{:>7.1%}r(   r4   )r2   optionr      z  )widthheaderr      )r8   r   r   r   r   r   )r1   Zis_disabledformatappendZcurse_add_lineZ	trend_msgZ	get_trendZ	get_viewsextendZcurse_add_statZcurse_new_line)r"   r   Z	max_widthretmsgr%   r%   r&   	msg_curse   s,   
zPlugin.msg_curse)NN)__name__
__module____qualname____doc__r!   r   Z_check_decoratorZ_log_result_decoratorr3   r5   r@   __classcell__r%   r%   r#   r&   r   b   s    
Yr   )rD   Zglances.loggerr   Zglances.compatr   Zglances.plugins.glances_pluginr   r*   r   r'   r   r   r%   r%   r%   r&   <module>   s   0