????

Your IP : 3.149.237.146


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/main.cpython-36.opt-1.pyc

3

Eo�c�n�@s�dZddlZddlZddlZddlmZmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZGd	d
�d
e�ZdS)zGlances main class.�N)�__version__�psutil_version)�input�disable�enable�PY3)�Config)�WINDOWS)�sort_processes_key_list)�logger�LOG_FILENAMEc@s�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd%d d!�Zd&d"d#�Zd$S)'�GlancesMainz&Main class to manage Glances instance.��Fi�i��glances�a�
Examples of use:
  Monitor local machine (standalone mode):
    $ glances

  Display all Glances modules (plugins and exporters) and exit:
    $ glances --module-list

  Monitor local machine with the Web interface and start RESTful server:
    $ glances -w
    Glances web server started on http://0.0.0.0:61208/

  Only start RESTful API (without the WebUI):
    $ glances -w --disable-webui
    Glances API available on http://0.0.0.0:61208/api/

  Monitor local machine and export stats to a CSV file (standalone mode):
    $ glances --export csv --export-csv-file /tmp/glances.csv

  Monitor local machine and export stats to a InfluxDB server with 5s refresh rate (standalone mode):
    $ glances -t 5 --export influxdb

  Start a Glances XML-RPC server (server mode):
    $ glances -s

  Connect Glances to a Glances XML-RPC server (client mode):
    $ glances -c <ip_server>

  Connect Glances to a Glances server and export stats to a StatsD server (client mode):
    $ glances -c <ip_server> --export statsd

  Start the client browser (browser mode):
    $ glances --browser

  Display stats to stdout (one stat per line, possible to go inside stats using plugin.attribute):
    $ glances --stdout now,cpu.user,mem.used,load

  Display JSON stats to stdout (one stats per line):
    $ glances --stdout-json now,cpu,mem,load

  Display CSV stats to stdout (all stats in one line):
    $ glances --stdout-csv now,cpu.user,mem.used,load

  Enable some plugins disabled by default (comma separated list):
    $ glances --enable-plugin sensors

  Disable some plugins (comma separated list):
    $ glances --disable-plugin network,ports

  Disable all plugins except some (comma separated list):
    $ glances --disable-plugin all --enable-plugin cpu,mem,load

cCs|j�|_dS)z"Manage the command line arguments.N)�
parse_args�args)�self�r�/usr/lib/python3.6/main.py�__init__`szGlancesMain.__init__cCs�djttt�}tjddtj|jd�}|jddd|d�|jd	d
ddd
dd�|jddddd�|jddddddd�|jddddd�|jdddd d�|jd!ddd"d#d�|jd$ddd%d&d�|jd'd(ddd)d*d�|jd+d,ddd-d.d�|jd/d0ddd1d2d�|jd3d4ddd5d6d�|jd7d8ddd9d:d�|jd;d<ddd=d>d�|jd?d@dddAdBd�|jdCdDdddEdFd�|jdGdddHdId�|jdJdddKdLd�|jdMdddNdOd�|jdPdddQdRd�f|jdSdddTdUd�|jdVdWdddXdYd�f|jdZd[t	d\jd]j
t	��d^�|jd_d`dddadbd�|jdcddded�|jdfdgdhdidj�|jdkdddldmd�|jdndodpdqdj�|jdrtj�dsdtdj�|jdudvdwdxd�|jdydzddd{d|d�|jd}ddd~dd�|jd�ddd�d�d�|jd�d�d�t
d�d�j|j�d��|jd�d�d�d�d�dj�|jd�ddd�d�d�|jd�ddd�d�d�|jd�d�d�d�|jd�d�d�d�dj�|jd�d�t
d�d�d��|jd�d�d�d�dj�|jd�d�d�d�dj�|jd�d�d�d�dj�|jd�ddd�d�d�|jd�d�|jtd�d�j|j�d��|jd�d�ddd�d�d�|jd�|jt
d�d�j|j�d��|jd�d�t
d�d�d��|jd�ddd�d�d�|jd�d�ddd�d�dÍ|jd�d�d�td�d�d��|jd�dd�d�d�d�|jd�d�dd�d�d�|jd�d�d�d�dj�|jd�d�d�d�dj�|jd�d�d�d�dj�|jd�d�dd�d�dÍ|jd�ddd�d�dÍ|jd�ddd�d�dÍ|jd�d�dd�d�dÍt�s|jd�ddd�d�d�|jd�d�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|jd�ddd�d�d�|j�ddd�d�dd�|j�d�d�d�d�d�|S(z$Init all the command line arguments.z(Glances v{} with PsUtil v{}
Log file: {}rZresolve)�progZconflict_handlerZformatter_classZepilogz-Vz	--version�version)�actionrz-dz--debug�
store_trueF�debugzenable debug mode)r�default�dest�helpz-Cz--config�	conf_filezpath to the configuration file)rrz--modules-listz
--module-listZmodules_listz1display modules (plugins & exports) list and exitz--disable-pluginz--disable-plugins�disable_pluginzidisable plugin (comma separated list or all). If all is used, then you need to configure --enable-plugin.z--enable-pluginz--enable-plugins�
enable_pluginz$enable plugin (comma separated list)z--disable-processZdisable_processzdisable process modulez--disable-webuiZ
disable_webuizdisable the Web Interfacez--lightz--enable-light�enable_lightz3light mode for Curses UI (disable all but top menu)z-0z--disable-irixZdisable_irixz<task's cpu usage will be divided by the total number of CPUsz-1z--percpuZpercpuzstart Glances in per CPU modez-2z--disable-left-sidebar�disable_left_sidebarz1disable network, disk I/O, FS and sensors modulesz-3z--disable-quicklookZdisable_quicklookzdisable quick look modulez-4z--full-quicklook�full_quicklookz#disable all but quick look and loadz-5z
--disable-top�disable_topz.disable top menu (QL, CPU, MEM, SWAP and LOAD)z-6z	--meangpuZmeangpuzstart Glances in mean GPU modez--disable-history�disable_historyzdisable stats historyz--disable-boldZdisable_boldz!disable bold mode in the terminalz--disable-bgZ
disable_bgz)disable background colors in the terminalz--enable-irqZ
enable_irqzenable IRQ modulez--enable-process-extendedZenable_process_extendedz$enable extended stats on top processz--separatorz--enable-separatorZenable_separatorzenable separator in the UIz--sort-processesZsort_processes_keyzSort processes by: {}z, )r�choicesrz
--programsz	--programZprogramszAccumulate processes by programz--export�exportz+enable export module (comma separated list)z--export-csv-filez
./glances.csvZexport_csv_filezfile path for CSV exporter)rrrz--export-csv-overwriteZexport_csv_overwritezoverwrite existing CSV filez--export-json-filez./glances.jsonZexport_json_filezfile path for JSON exporterz--export-graph-pathZexport_graph_pathzFolder for Graph exporterz-cz--client�clientz<connect to a Glances server by IPv4/IPv6 address or hostnamez-sz--server�serverzrun Glances in server modez	--browser�browserz*start the client browser (list of servers)z--disable-autodiscover�disable_autodiscoverzdisable autodiscover featurez-pz--portN�portz/define the client/server TCP port [default: {}])r�typerrz-Bz--bindz0.0.0.0Zbind_addressz6bind server to the given IPv4/IPv6 address or hostnamez
--username�username_promptzdefine a client/server usernamez
--password�password_promptzdefine a client/server passwordz-u�
username_usedz$use the given client/server usernamez--snmp-communityZpublicZsnmp_communityzSNMP communityz--snmp-port�Z	snmp_portz	SNMP portz--snmp-versionZ2cZsnmp_versionzSNMP version (1, 2c or 3)z--snmp-userZprivateZ	snmp_userzSNMP username (only for SNMPv3)z--snmp-auth�passwordZ	snmp_authz)SNMP authentication key (only for SNMPv3)z--snmp-forceZ
snmp_forcezforce SNMP modez-tz--time�timez5set minimum refresh rate in seconds [default: {} sec]z-wz--webserver�	webserverz.run Glances in web server mode (bottle needed)z
--cached-time�cached_timez+set the server cache time [default: {} sec]z--stop-after�
stop_afterzstop Glances after n refreshz--open-web-browserZopen_web_browserz1try to open the Web UI in the default Web browserz-qz--quiet�quietz#do not display the curses interface)rrrrz-fz--process-filter�process_filterz3set the process filter pattern (regular expression)z--process-short-nameT�process_short_namez#force short name for processes namez--process-long-nameZstore_falsez"force long name for processes namez--stdout�stdoutz^display stats to stdout, one stat per line (comma separated list of plugins/plugins.attribute)z
--stdout-jsonZstdout_jsonzXdisplay stats to stdout, JSON format (comma separated list of plugins/plugins.attribute)z--stdout-csvZ
stdout_csvzWdisplay stats to stdout, CSV format (comma separated list of plugins/plugins.attribute)z--issueZstdout_issuezMtest all plugins and exit (please copy/paste the output if you open an issue)z--trace-malloc�trace_mallocz^trace memory allocation and display it at the end of the process (python 3.4 or higher needed)z
--memory-leak�memory_leakz.test memory leak (python 3.4 or higher needed)z	--api-docZ
stdout_apidoczdisplay fields descriptionsz--hide-kernel-threadsZno_kernel_threadsz>hide kernel threads in process list (not available on Windows)z-bz--byteZbytez'display network rate in byte per secondz--diskio-show-ramfsZdiskio_show_ramfsz show RAM Fs in the DiskIO pluginz
--diskio-iopsZdiskio_iopsz'show IO per second in the DiskIO pluginz--fahrenheitZ
fahrenheitz6display temperature in Fahrenheit (default is Celsius)z--fs-free-spaceZ
fs_free_spacez%display FS free space instead of usedz--sparklineZ	sparklinez9display sparklines instead of bar in the curses interfacez--disable-unicodeZdisable_unicodez2disable unicode characters in the curses interfacez
--theme-whiteZtheme_whitez,optimize display colors for white backgroundz--disable-check-updateZdisable_check_updatez$disable online Glances version ckeckz
--strftimeZstrftime_formatrzEstrftime format string for displaying current date in standalone mode)rrr)�formatrrr�argparse�ArgumentParserZRawDescriptionHelpFormatter�example_of_use�add_argumentr
�join�tempfileZ
gettempdir�int�server_port�DEFAULT_REFRESH_TIME�floatr7�strr	)rr�parserrrr�	init_argses�


zGlancesMain.init_argscCs�|j�j�}t|j�|_|jr6ddlm}tj	|�nddl
m}|d�|jjd�rj|jj
dd|jd�}|j|jkr|||_tjdj|j��xH|jj�D]:}|jj|�r�|jj|d	d
�r�t||�tjdj|��q�W|o�|jo�d|jjd
�k�r|j�stjd�tjd�n
tjd�|jdk	�rJx |jjd
�D]}t||��q6W|jdk	�rxx |jjd
�D]}t||��qdW|jdk	�r�x&|jjd
�D]}t|d|d��q�W|jdk�r�|j�r�|j |_n|j!|_|j"dk	�rdd�t#|j"j$d�ddd�|j"|jf�D�\|_"|_|j%�r&tjd�|j�r4d|_&|j'�r�d|_(|j)�rZ|j*dd�|_+n.|j�rr|j*dd�|_+n|j"�r�|j*dd�|_+n|j,�r�|j,|_+n|j+|_+|j(�s�|j,�r&|j)�r�|j-dj|j+�d|j+d�|_.nJ|j�r|j-dj|j+�d|j+d�|_.n$|j"�r.|j-dj|j+�d|j+d �|_.n|j.|_.d
|_/d
|_0d
|_1|j2�r�tjd!�d|_3t|d"�t|d#�t|d$�t|d%�|j4�r�tjd&�t|d'�t|d(�t|d)�t|d*�t|d+�|j5�rtjd,�t|d'�t|d(�t|d)�t|d*�t|d+�d
|_6||_7|j7jdk	�o,t8|j7j�}t9�rV|�rVtjd-�d|j7_:d
|j7_n0|j;��pf|j<��r�|�r�tjd.�tjd�|j=dk	�r�|j;��r�tjd/�tjd�t>|j7d0d
��r�t|j7d1�tjd2�t>|j7d3d��rt?�p�|j;��rtjd4�tjd�t>|j7d5d��rFt?�p*|j;��rFtjd6�tjd�nTt>|j7d5d��r�t?�sf|j;��r�tjd7�d|j7_:|j7j@�s�d8|j7_@d9|j7_d|j7_A|j;�|j7_;|j<�|j7_<|jB�|j7_B|jC�|j7_C|jD�|j7_D|S):zParse command line arguments.r)�DEBUG)�simplefilter�ignore�globalZrefresh)rz(Global refresh rate is set to {} secondsrFz%{} disabled by the configuration file�all�,zC'all' key in --disable-plugin needs to be used with --enable-pluginrzZ'all' key in --disable-plugin, only plugins defined with --enable-plugin will be availableNZexport_Tcss|]\}}|r|n|VqdS)Nr)�.0�x�yrrr�	<genexpr>Osz)GlancesMain.parse_args.<locals>.<genexpr>�:zAuto discover mode is disabledz$Define the Glances server username: )�descriptionz'Define the Glances webserver username: z#Enter the Glances server username: z2Define the Glances server password ({} username): )rX�confirm�usernamez5Define the Glances webserver password ({} username): z1Enter the Glances server password ({} username): )rX�clearrZzLight mode is onZprocessZalertZampsZdockerzFull quicklook modeZ	quicklookZcpuZmemZmemswap�loadzDisable top menuz/On Windows OS, export disable the Web interfacez5Export is only available in standalone or client modez3Process filter is only available in standalone modeZdisable_sensorsZhddtempz Sensors and HDDTemp are disabledr=zGOption --trace-malloc is only available with Python 3 and terminal moder>zFOption --memory-leak is only available with Python 3 and terminal modezMemory leak detection enabled�<r)ErLrrr �configrZloggingrMrZsetLevel�warningsrNZhas_sectionZget_float_valuerHr5r?ZsectionsZget_bool_valuerr!�splitr"Zcritical�sys�exit�inforr)�setattrr.r6�web_server_portrGr*�zip�	partitionr-r;r0r1r+�_GlancesMain__get_usernamerZr2�_GlancesMain__get_passwordr4Zhelp_tagZnetwork_sumZ
network_cumulr#r$r%r&Zgenerate_graphr�anyr	r9�
is_standalone�	is_clientr:�getattrrr8r'�is_client_browser�	is_server�is_webserver)rrrMrNZglobal_refresh�s�pZ
export_tagrrrrs


6




























"

"
 

zGlancesMain.parse_argscCs(|jjo&|jjo&|jjo&|jjS)z5Return True if Glances is running in standalone mode.)rr*r,r+r6)rrrrrk�szGlancesMain.is_standalonecCs|jjs|jjo|jjS)z1Return True if Glances is running in client mode.)rr*r,r+)rrrrrl�szGlancesMain.is_clientcCs|jjo|jjS)z9Return True if Glances is running in client browser mode.)rr,r+)rrrrrn�szGlancesMain.is_client_browsercCs|jjo|jjS)z1Return True if Glances is running in server mode.)rr*r+)rrrrro�szGlancesMain.is_servercCs|jjo|jjS)z5Return True if Glances is running in Web server mode.)rr*r6)rrrrrp�szGlancesMain.is_webservercCs|jS)z!Return configuration file object.)r^)rrrr�
get_config�szGlancesMain.get_configcCs|jS)zReturn the arguments.)r)rrrr�get_args�szGlancesMain.get_argscCs|jS)zReturn the mode.)�mode)rrrr�get_mode�szGlancesMain.get_modecCst|�S)z'Read an username from the command line.)r)rrXrrrZ__get_username�szGlancesMain.__get_usernamecCs*ddlm}|||j�d�}|j|||�S)z�Read a password from the command line.

        - if confirm = True, with confirmation
        - if clear = True, plain (clear password)
        r)�GlancesPassword)rZr^)Zglances.passwordrwrsZget_password)rrXrYr[rZrwr4rrrZ__get_passwordszGlancesMain.__get_passwordN)r)rFFr)�__name__�
__module__�__qualname__�__doc__rHr7Z
client_tagrGrerZr4rBrrLrrkrlrnrorprsrtrvrhrirrrrr
s47/L
r
)r{r@rarErrrZglances.compatrrrrZglances.configrZglances.globalsr	Zglances.processesr
Zglances.loggerrr�objectr
rrrr�<module>
s