????
Current Path : /lib/python3.6/site-packages/glances/__pycache__/ |
Current File : //lib/python3.6/site-packages/glances/__pycache__/main.cpython-36.pyc |
3 Eo�c�n � @ s� d Z ddlZddlZddlZddlmZmZ ddlmZm Z m Z mZ ddlm Z ddlmZ ddlmZ ddlmZmZ G d 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� e Zd ZdZdZdZdZdZdZdZ dZ d Zd d� Zdd � 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 c C s | j � | _dS )z"Manage the command line arguments.N)� parse_args�args)�self� r �/usr/lib/python3.6/main.py�__init__` s zGlancesMain.__init__c C s� dj ttt�}tjddtj| jd�}|jddd|d� |jd d ddd dd� |jddddd� |jddddddd� |jddddd� |jdddd d� |jd!ddd"d#d� |jd$ddd%d&d� |jd'd(ddd)d*d� |jd+d,ddd-d.d� |jd/d0ddd1d2d� |jd3d4ddd5d6d� |jd7d8ddd9d:d� |jd;d<ddd=d>d� |jd?d@dddAdBd� |jdCdDdddEdFd� |jdGdddHdId� |jdJdddKdLd� |jdMdddNdOd� |jdPdddQdRd�f |jdSdddTdUd� |jdVdWdddXdYd�f |jdZd[t d\j d]j t ��d^� |jd_d`dddadbd� |jdcddded� |jdfdgdhdidj� |jdkdddldmd� |jdndodpdqdj� |jdrtj� dsdtdj� |jdudvdwdxd� |jdydzddd{d|d� |jd}ddd~dd� |jd�ddd�d�d� |jd�d�d�t d�d�j | j�d�� |jd�d�d�d�d�dj� |jd�ddd�d�d� |jd�ddd�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�ddd�d�d� |jd�d�| jtd�d�j | j�d�� |jd�d�ddd�d�d� |jd�| jt d�d�j | j�d�� |jd�d�t d�d�d�� |jd�ddd�d�d� |jd�d�ddd�d�dÍ |jd�d�d�td�d�d�� |jd�dd�d�d�d� |jd�d�dd�d�d� |jd�d�d�d�dj� |jd�d�d�d�dj� |jd�d�d�d�dj� |jd�d�dd�d�dÍ |jd�ddd�d�dÍ |jd�ddd�d�dÍ |jd�d�dd�d�dÍ t�s|jd�ddd�d�d� |jd�d�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |jd�ddd�d�d� |j�d dd�d�dd� |j�d�d�d�d�d� |S ( z$Init all the command line arguments.z(Glances v{} with PsUtil v{} Log file: {}r Zresolve)�progZconflict_handlerZformatter_classZepilogz-Vz --version�version)�actionr z-dz--debug� store_trueF�debugzenable debug mode)r �default�dest�helpz-Cz--config� conf_filezpath to the configuration file)r r z--modules-listz --module-listZmodules_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-irixZdisable_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-boldZdisable_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 �choicesr z --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)r r r z--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 �typer r z-Bz--bindz0.0.0.0Zbind_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-versionZ2cZsnmp_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)r r r r z-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--issueZstdout_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_formatr zEstrftime format string for displaying current date in standalone mode)r r r )�formatr r r �argparse�ArgumentParserZRawDescriptionHelpFormatter�example_of_use�add_argumentr �join�tempfileZ gettempdir�int�server_port�DEFAULT_REFRESH_TIME�floatr7 �strr )r r �parserr r r � init_argse s� zGlancesMain.init_argsc C s� | j � j� }t|j�| _|jr6ddlm} tj |� nddl m} |d� | jjd�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)r z(Global refresh rate is set to {} secondsr Fz%{} disabled by the configuration file�all�,zC'all' key in --disable-plugin needs to be used with --enable-pluginr zZ'all' key in --disable-plugin, only plugins defined with --enable-plugin will be availableNZexport_Tc s s | ]\}}|r|n|V qd S )Nr )�.0�x�yr r r � <genexpr>O s z)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 �clearrZ zLight 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>