main.py 25.1 KB
Newer Older
N
Nicolas Hennion 已提交
1 2
# -*- coding: utf-8 -*-
#
3
# This file is part of Glances.
N
Nicolas Hennion 已提交
4
#
A
Alessio Sergi 已提交
5
# Copyright (C) 2017 Nicolargo <nicolas@nicolargo.com>
N
Nicolas Hennion 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18
#
# Glances is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Glances is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
A
PEP 257  
Alessio Sergi 已提交
19 20

"""Glances main class."""
N
Nicolas Hennion 已提交
21

N
Nicolas Hennion 已提交
22
import argparse
23
import os
24
import sys
25
import tempfile
N
Nicolas Hennion 已提交
26

A
Alessio Sergi 已提交
27
from glances import __version__, psutil_version
N
nicolargo 已提交
28
from glances.compat import input
29
from glances.config import Config
30
from glances.globals import LINUX, WINDOWS
31
from glances.logger import logger
N
Nicolas Hennion 已提交
32

N
Nicolas Hennion 已提交
33

34
class GlancesMain(object):
A
PEP 257  
Alessio Sergi 已提交
35
    """Main class to manage Glances instance."""
N
Nicolas Hennion 已提交
36

N
Nicolas Hennion 已提交
37 38
    # Default stats' refresh time is 3 seconds
    refresh_time = 3
N
Nicolas Hennion 已提交
39
    # Set the default cache lifetime to 1 second (only for server)
A
Alessio Sergi 已提交
40
    cached_time = 1
N
Nicolas Hennion 已提交
41 42 43 44
    # By default, Glances is ran in standalone mode (no client/server)
    client_tag = False
    # Server TCP port number (default is 61209)
    server_port = 61209
N
Nicolas Hennion 已提交
45 46
    # Web Server TCP port number (default is 61208)
    web_server_port = 61208
N
Nicolas Hennion 已提交
47 48 49 50
    # Default username/password for client/server mode
    username = "glances"
    password = ""

51 52 53 54 55 56
    # Examples of use
    example_of_use = """
Examples of use:
  Monitor local machine (standalone mode):
    $ glances

57
  Monitor local machine with the Web interface and start Restful server:
58 59 60
    $ glances -w
    Glances web server started on http://0.0.0.0:61208/

61 62 63 64
  Only start Restful API (without the WebUI):
    $ glances -w --disable-webui
    Glances API available on http://0.0.0.0:61208/api/

65 66 67 68 69 70
  Monitor local machine and export stats to a CSV file (standalone mode):
    $ glances --export-csv /tmp/glances.csv

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

71
  Start a Glances XML/RCP server (server mode):
72 73
    $ glances -s

74
  Connect Glances to a Glances XML/RCP server (client mode):
75 76 77 78 79 80 81 82
    $ 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
"""
N
Nicolargo 已提交
83

N
Nicolas Hennion 已提交
84
    def __init__(self):
A
Alessio Sergi 已提交
85
        """Manage the command line arguments."""
86
        # Read the command line arguments
A
Alessio Sergi 已提交
87 88 89 90
        self.args = self.parse_args()

    def init_args(self):
        """Init all the command line arguments."""
91
        version = "Glances v" + __version__ + " with psutil v" + psutil_version
92
        parser = argparse.ArgumentParser(
A
Alessio Sergi 已提交
93
            prog='glances',
N
Nicolargo 已提交
94 95 96
            conflict_handler='resolve',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            epilog=self.example_of_use)
97
        parser.add_argument(
98
            '-V', '--version', action='version', version=version)
N
Nicolas Hennion 已提交
99
        parser.add_argument('-d', '--debug', action='store_true', default=False,
A
Alessio Sergi 已提交
100
                            dest='debug', help='enable debug mode')
A
Alessio Sergi 已提交
101
        parser.add_argument('-C', '--config', dest='conf_file',
A
Alessio Sergi 已提交
102
                            help='path to the configuration file')
N
Nicolargo 已提交
103
        # Enable or disable option on startup
N
nicolargo 已提交
104 105 106 107
        parser.add_argument('--disable-alert', action='store_true', default=False,
                            dest='disable_alert', help='disable alert module')
        parser.add_argument('--disable-amps', action='store_true', default=False,
                            dest='disable_amps', help='disable applications monitoring process (AMP) module')
108 109
        parser.add_argument('--disable-cloud', action='store_true', default=False,
                            dest='disable_cloud', help='disable Cloud module')
110 111
        parser.add_argument('--disable-cpu', action='store_true', default=False,
                            dest='disable_cpu', help='disable CPU module')
A
Alessio Sergi 已提交
112
        parser.add_argument('--disable-diskio', action='store_true', default=False,
A
Alessio Sergi 已提交
113
                            dest='disable_diskio', help='disable disk I/O module')
N
nicolargo 已提交
114 115 116 117
        parser.add_argument('--disable-docker', action='store_true', default=False,
                            dest='disable_docker', help='disable Docker module')
        parser.add_argument('--disable-folders', action='store_true', default=False,
                            dest='disable_folders', help='disable folder module')
A
Alessio Sergi 已提交
118
        parser.add_argument('--disable-fs', action='store_true', default=False,
A
Alessio Sergi 已提交
119
                            dest='disable_fs', help='disable filesystem module')
120 121
        parser.add_argument('--disable-gpu', action='store_true', default=False,
                            dest='disable_gpu', help='disable GPU module')
122
        parser.add_argument('--disable-hddtemp', action='store_true', default=False,
A
Alessio Sergi 已提交
123
                            dest='disable_hddtemp', help='disable HD temperature module')
N
nicolargo 已提交
124 125 126 127 128 129 130 131 132 133
        parser.add_argument('--disable-ip', action='store_true', default=False,
                            dest='disable_ip', help='disable IP module')
        parser.add_argument('--disable-load', action='store_true', default=False,
                            dest='disable_load', help='disable load module')
        parser.add_argument('--disable-mem', action='store_true', default=False,
                            dest='disable_mem', help='disable memory module')
        parser.add_argument('--disable-memswap', action='store_true', default=False,
                            dest='disable_memswap', help='disable memory swap module')
        parser.add_argument('--disable-network', action='store_true', default=False,
                            dest='disable_network', help='disable network module')
N
nicolargo 已提交
134 135
        parser.add_argument('--disable-now', action='store_true', default=False,
                            dest='disable_now', help='disable current time module')
N
nicolargo 已提交
136 137 138 139
        parser.add_argument('--disable-ports', action='store_true', default=False,
                            dest='disable_ports', help='disable ports scanner module')
        parser.add_argument('--disable-process', action='store_true', default=False,
                            dest='disable_process', help='disable process module')
N
Nicolargo 已提交
140
        parser.add_argument('--disable-raid', action='store_true', default=False,
A
Alessio Sergi 已提交
141
                            dest='disable_raid', help='disable RAID module')
N
nicolargo 已提交
142 143
        parser.add_argument('--disable-sensors', action='store_true', default=False,
                            dest='disable_sensors', help='disable sensors module')
144 145
        parser.add_argument('--disable-webui', action='store_true', default=False,
                            dest='disable_webui', help='disable the Web Interface')
N
nicolargo 已提交
146 147
        parser.add_argument('--disable-wifi', action='store_true', default=False,
                            dest='disable_wifi', help='disable wifi module')
148 149 150
        parser.add_argument('--light', '--enable-light', action='store_true',
                            default=False, dest='enable_light',
                            help='light mode for Curses UI (disable all but top menu)')
N
nicolargo 已提交
151 152 153 154
        parser.add_argument('-0', '--disable-irix', action='store_true', default=False,
                            dest='disable_irix', help='task\'s cpu usage will be divided by the total number of CPUs')
        parser.add_argument('-1', '--percpu', action='store_true', default=False,
                            dest='percpu', help='start Glances in per CPU mode')
155
        parser.add_argument('-2', '--disable-left-sidebar', action='store_true',
A
Alessio Sergi 已提交
156
                            default=False, dest='disable_left_sidebar',
157
                            help='disable network, disk I/O, FS and sensors modules')
N
nicolargo 已提交
158 159 160 161 162 163 164
        parser.add_argument('-3', '--disable-quicklook', action='store_true', default=False,
                            dest='disable_quicklook', help='disable quick look module')
        parser.add_argument('-4', '--full-quicklook', action='store_true', default=False,
                            dest='full_quicklook', help='disable all but quick look and load')
        parser.add_argument('-5', '--disable-top', action='store_true',
                            default=False, dest='disable_top',
                            help='disable top menu (QL, CPU, MEM, SWAP and LOAD)')
165 166
        parser.add_argument('-6', '--meangpu', action='store_true', default=False,
                            dest='meangpu', help='start Glances in mean GPU mode')
N
Nicolargo 已提交
167 168
        parser.add_argument('--disable-history', action='store_true', default=False,
                            dest='disable_history', help='disable stats history')
169
        parser.add_argument('--disable-bold', action='store_true', default=False,
A
Alessio Sergi 已提交
170
                            dest='disable_bold', help='disable bold mode in the terminal')
171
        parser.add_argument('--disable-bg', action='store_true', default=False,
172
                            dest='disable_bg', help='disable background colors in the terminal')
173 174
        parser.add_argument('--enable-irq', action='store_true', default=False,
                            dest='enable_irq', help='enable IRQ module'),
N
Nicolargo 已提交
175
        parser.add_argument('--enable-process-extended', action='store_true', default=False,
A
Alessio Sergi 已提交
176
                            dest='enable_process_extended', help='enable extended stats on top process')
177
        # Export modules feature
N
Nicolargo 已提交
178
        parser.add_argument('--export-graph', action='store_true', default=None,
N
nicolargo 已提交
179
                            dest='export_graph', help='export stats to graphs')
N
Nicolargo 已提交
180
        parser.add_argument('--path-graph', default=tempfile.gettempdir(),
181
                            dest='path_graph', help='set the export path for graphs (default is {})'.format(tempfile.gettempdir()))
182
        parser.add_argument('--export-csv', default=None,
A
Alessio Sergi 已提交
183
                            dest='export_csv', help='export stats to a CSV file')
J
Jude 已提交
184 185
        parser.add_argument('--export-json', default=None,
                            dest='export_json', help='export stats to a JSON file')
186 187
        parser.add_argument('--export-cassandra', action='store_true', default=False,
                            dest='export_cassandra', help='export stats to a Cassandra or Scylla server (cassandra lib needed)')
188 189
        parser.add_argument('--export-couchdb', action='store_true', default=False,
                            dest='export_couchdb', help='export stats to a CouchDB server (couch lib needed)')
190 191
        parser.add_argument('--export-elasticsearch', action='store_true', default=False,
                            dest='export_elasticsearch', help='export stats to an ElasticSearch server (elasticsearch lib needed)')
192 193
        parser.add_argument('--export-influxdb', action='store_true', default=False,
                            dest='export_influxdb', help='export stats to an InfluxDB server (influxdb lib needed)')
N
nicolargo 已提交
194 195
        parser.add_argument('--export-kafka', action='store_true', default=False,
                            dest='export_kafka', help='export stats to a Kafka server (kafka-python lib needed)')
196 197 198 199
        parser.add_argument('--export-opentsdb', action='store_true', default=False,
                            dest='export_opentsdb', help='export stats to an OpenTSDB server (potsdb lib needed)')
        parser.add_argument('--export-prometheus', action='store_true', default=False,
                            dest='export_prometheus', help='export stats to a Prometheus exporter (prometheus_client lib needed)')
A
Alessio Sergi 已提交
200
        parser.add_argument('--export-rabbitmq', action='store_true', default=False,
201
                            dest='export_rabbitmq', help='export stats to rabbitmq broker (pika lib needed)')
N
nicolargo 已提交
202 203
        parser.add_argument('--export-restful', action='store_true', default=False,
                            dest='export_restful', help='export stats to a Restful endpoint (requests lib needed)')
204 205
        parser.add_argument('--export-riemann', action='store_true', default=False,
                            dest='export_riemann', help='export stats to riemann broker (bernhard lib needed)')
206 207
        parser.add_argument('--export-statsd', action='store_true', default=False,
                            dest='export_statsd', help='export stats to a StatsD server (statsd lib needed)')
N
nicolargo 已提交
208 209
        parser.add_argument('--export-zeromq', action='store_true', default=False,
                            dest='export_zeromq', help='export stats to a ZeroMQ server (pyzmq lib needed)')
N
Nicolargo 已提交
210 211
        # Client/Server option
        parser.add_argument('-c', '--client', dest='client',
A
Alessio Sergi 已提交
212
                            help='connect to a Glances server by IPv4/IPv6 address or hostname')
N
Nicolargo 已提交
213
        parser.add_argument('-s', '--server', action='store_true', default=False,
A
Alessio Sergi 已提交
214
                            dest='server', help='run Glances in server mode')
215
        parser.add_argument('--browser', action='store_true', default=False,
A
Alessio Sergi 已提交
216
                            dest='browser', help='start the client browser (list of servers)')
217
        parser.add_argument('--disable-autodiscover', action='store_true', default=False,
A
Alessio Sergi 已提交
218
                            dest='disable_autodiscover', help='disable autodiscover feature')
219
        parser.add_argument('-p', '--port', default=None, type=int, dest='port',
220
                            help='define the client/server TCP port [default: {}]'.format(self.server_port))
N
Nicolargo 已提交
221
        parser.add_argument('-B', '--bind', default='0.0.0.0', dest='bind_address',
A
Alessio Sergi 已提交
222
                            help='bind server to the given IPv4/IPv6 address or hostname')
223 224
        parser.add_argument('--username', action='store_true', default=False, dest='username_prompt',
                            help='define a client/server username')
A
Alessio Sergi 已提交
225
        parser.add_argument('--password', action='store_true', default=False, dest='password_prompt',
A
Alessio Sergi 已提交
226
                            help='define a client/server password')
227
        parser.add_argument('--snmp-community', default='public', dest='snmp_community',
A
Alessio Sergi 已提交
228
                            help='SNMP community')
A
Alessio Sergi 已提交
229
        parser.add_argument('--snmp-port', default=161, type=int,
A
Alessio Sergi 已提交
230
                            dest='snmp_port', help='SNMP port')
N
Nicolargo 已提交
231
        parser.add_argument('--snmp-version', default='2c', dest='snmp_version',
A
Alessio Sergi 已提交
232
                            help='SNMP version (1, 2c or 3)')
N
Nicolargo 已提交
233
        parser.add_argument('--snmp-user', default='private', dest='snmp_user',
A
Alessio Sergi 已提交
234
                            help='SNMP username (only for SNMPv3)')
N
Nicolargo 已提交
235
        parser.add_argument('--snmp-auth', default='password', dest='snmp_auth',
A
Alessio Sergi 已提交
236
                            help='SNMP authentication key (only for SNMPv3)')
237
        parser.add_argument('--snmp-force', action='store_true', default=False,
A
Alessio Sergi 已提交
238
                            dest='snmp_force', help='force SNMP mode')
239
        parser.add_argument('-t', '--time', default=self.refresh_time, type=float,
240
                            dest='time', help='set refresh time in seconds [default: {} sec]'.format(self.refresh_time))
A
Alessio Sergi 已提交
241
        parser.add_argument('-w', '--webserver', action='store_true', default=False,
A
Alessio Sergi 已提交
242
                            dest='webserver', help='run Glances in web server mode (bottle needed)')
243 244
        parser.add_argument('--cached-time', default=self.cached_time, type=int,
                            dest='cached_time', help='set the server cache time [default: {} sec]'.format(self.cached_time))
N
nicolargo 已提交
245 246
        parser.add_argument('--open-web-browser', action='store_true', default=False,
                            dest='open_web_browser', help='try to open the Web UI in the default Web browser')
247
        # Display options
N
nicolargo 已提交
248 249
        parser.add_argument('-q', '--quiet', default=False, action='store_true',
                            dest='quiet', help='do not display the curses interface')
N
Nicolargo 已提交
250
        parser.add_argument('-f', '--process-filter', default=None, type=str,
A
Alessio Sergi 已提交
251
                            dest='process_filter', help='set the process filter pattern (regular expression)')
252
        parser.add_argument('--process-short-name', action='store_true', default=False,
A
Alessio Sergi 已提交
253
                            dest='process_short_name', help='force short name for processes name')
A
Alessio Sergi 已提交
254
        if not WINDOWS:
255
            parser.add_argument('--hide-kernel-threads', action='store_true', default=False,
256
                                dest='no_kernel_threads', help='hide kernel threads in process list (not available on Windows)')
A
Alessio Sergi 已提交
257
        if LINUX:
258
            parser.add_argument('--tree', action='store_true', default=False,
259
                                dest='process_tree', help='display processes as a tree (Linux only)')
N
Nicolargo 已提交
260
        parser.add_argument('-b', '--byte', action='store_true', default=False,
A
Alessio Sergi 已提交
261
                            dest='byte', help='display network rate in byte per second')
262 263
        parser.add_argument('--diskio-show-ramfs', action='store_true', default=False,
                            dest='diskio_show_ramfs', help='show RAM Fs in the DiskIO plugin')
264 265
        parser.add_argument('--diskio-iops', action='store_true', default=False,
                            dest='diskio_iops', help='show IO per second in the DiskIO plugin')
N
nicolargo 已提交
266 267
        parser.add_argument('--fahrenheit', action='store_true', default=False,
                            dest='fahrenheit', help='display temperature in Fahrenheit (default is Celsius)')
A
Alessio Sergi 已提交
268
        parser.add_argument('--fs-free-space', action='store_true', default=False,
A
Alessio Sergi 已提交
269
                            dest='fs_free_space', help='display FS free space instead of used')
N
Nicolargo 已提交
270
        parser.add_argument('--theme-white', action='store_true', default=False,
A
Alessio Sergi 已提交
271
                            dest='theme_white', help='optimize display colors for white background')
272 273 274
        # Globals options
        parser.add_argument('--disable-check-update', action='store_true', default=False,
                            dest='disable_check_update', help='disable online Glances version ckeck')
A
Alessio Sergi 已提交
275 276 277 278 279 280
        return parser

    def parse_args(self):
        """Parse command line arguments."""
        args = self.init_args().parse_args()

281
        # Load the configuration file, if it exists
A
Alessio Sergi 已提交
282 283
        self.config = Config(args.conf_file)

N
Nicolas Hennion 已提交
284 285 286 287 288
        # Debug mode
        if args.debug:
            from logging import DEBUG
            logger.setLevel(DEBUG)

289
        # Client/server Port
290 291 292 293
        if args.port is None:
            if args.webserver:
                args.port = self.web_server_port
            else:
294
                args.port = self.server_port
N
nicolargo 已提交
295
        # Port in the -c URI #996
296 297
        if args.client is not None:
            args.client, args.port = (x if x else y for (x, y) in zip(args.client.partition(':')[::2], (args.client, args.port)))
298

299 300 301 302
        # Autodiscover
        if args.disable_autodiscover:
            logger.info("Auto discover mode is disabled")

303 304 305 306
        # By default Windows is started in Web mode
        if WINDOWS:
            args.webserver = True

307
        # In web server mode, defaul refresh time: 5 sec
A
Alessio Sergi 已提交
308
        if args.webserver:
309
            args.time = 5
310
            args.process_short_name = True
N
Nicolas Hennion 已提交
311 312

        # Server or client login/password
313 314 315 316 317
        if args.username_prompt:
            # Every username needs a password
            args.password_prompt = True
            # Prompt username
            if args.server:
N
nicolargo 已提交
318 319
                args.username = self.__get_username(
                    description='Define the Glances server username: ')
320
            elif args.webserver:
N
nicolargo 已提交
321 322
                args.username = self.__get_username(
                    description='Define the Glances webserver username: ')
323
            elif args.client:
N
nicolargo 已提交
324 325
                args.username = self.__get_username(
                    description='Enter the Glances server username: ')
326 327
        else:
            # Default user name is 'glances'
328
            args.username = self.username
329

330
        if args.password_prompt:
N
Nicolargo 已提交
331
            # Interactive or file password
A
Alessio Sergi 已提交
332
            if args.server:
N
Nicolas Hennion 已提交
333
                args.password = self.__get_password(
N
nicolargo 已提交
334 335
                    description='Define the Glances server password ({} username): '.format(
                        args.username),
336 337
                    confirm=True,
                    username=args.username)
338 339
            elif args.webserver:
                args.password = self.__get_password(
N
nicolargo 已提交
340 341
                    description='Define the Glances webserver password ({} username): '.format(
                        args.username),
342 343
                    confirm=True,
                    username=args.username)
A
Alessio Sergi 已提交
344
            elif args.client:
N
Nicolas Hennion 已提交
345
                args.password = self.__get_password(
N
nicolargo 已提交
346 347
                    description='Enter the Glances server password ({} username): '.format(
                        args.username),
348 349
                    clear=True,
                    username=args.username)
N
Nicolas Hennion 已提交
350 351 352 353
        else:
            # Default is no password
            args.password = self.password

A
Alessio Sergi 已提交
354 355 356 357 358 359 360
        # By default help is hidden
        args.help_tag = False

        # Display Rx and Tx, not the sum for the network
        args.network_sum = False
        args.network_cumul = False

361 362 363 364 365 366 367 368 369
        # Manage light mode
        if args.enable_light:
            logger.info("Light mode is on")
            args.disable_left_sidebar = True
            args.disable_process = True
            args.disable_alert = True
            args.disable_amps = True
            args.disable_docker = True

370 371
        # Manage full quicklook option
        if args.full_quicklook:
372
            logger.info("Disable QuickLook menu")
373 374 375
            args.disable_quicklook = False
            args.disable_cpu = True
            args.disable_mem = True
B
Beau Hastings 已提交
376
            args.disable_memswap = True
377
            args.disable_load = False
378 379 380 381 382 383 384

        # Manage disable_top option
        if args.disable_top:
            logger.info("Disable top menu")
            args.disable_quicklook = True
            args.disable_cpu = True
            args.disable_mem = True
B
Beau Hastings 已提交
385
            args.disable_memswap = True
386
            args.disable_load = True
387

388 389 390
        # Control parameter and exit if it is not OK
        self.args = args

391
        # Export is only available in standalone or client mode (issue #614)
392
        export_tag = any([getattr(args, a) for a in args.__dict__ if a.startswith('export_')])
393 394 395
        if WINDOWS and export_tag:
            # On Windows, export is possible but only in quiet mode
            # See issue #1038
396
            logger.info("On Windows OS, export disable the Web interface")
397 398
            self.args.quiet = True
            self.args.webserver = False
399 400
        elif not (self.is_standalone() or self.is_client()) and export_tag:
            logger.critical("Export is only available in standalone or client mode")
401 402
            sys.exit(2)

403
        # Filter is only available in standalone mode
404
        if args.process_filter is not None and not self.is_standalone():
N
nicolargo 已提交
405 406
            logger.critical(
                "Process filter is only available in standalone mode")
407 408
            sys.exit(2)

409
        # Check graph output path
N
nicolargo 已提交
410 411
        if args.export_graph and args.path_graph is not None:
            if not os.access(args.path_graph, os.W_OK):
412
                logger.critical("Graphs output path {} doesn't exist or is not writable".format(args.path_graph))
413
                sys.exit(2)
N
nicolargo 已提交
414
            logger.debug(
415
                "Graphs output path is set to {}".format(args.path_graph))
416

N
Nicolargo 已提交
417 418 419 420 421
        # For export graph, history is mandatory
        if args.export_graph and args.disable_history:
            logger.critical("Can not export graph if history is disabled")
            sys.exit(2)

422 423 424 425 426
        # Disable HDDTemp if sensors are disabled
        if args.disable_sensors:
            args.disable_hddtemp = True
            logger.debug("Sensors and HDDTemp are disabled")

N
Nicolas Hennion 已提交
427
        return args
N
Nicolas Hennion 已提交
428

N
Nicolas Hennion 已提交
429
    def is_standalone(self):
A
PEP 257  
Alessio Sergi 已提交
430
        """Return True if Glances is running in standalone mode."""
431 432 433 434
        return (not self.args.client and
                not self.args.browser and
                not self.args.server and
                not self.args.webserver)
N
Nicolas Hennion 已提交
435 436

    def is_client(self):
A
PEP 257  
Alessio Sergi 已提交
437
        """Return True if Glances is running in client mode."""
438
        return (self.args.client or self.args.browser) and not self.args.server
439

440 441
    def is_client_browser(self):
        """Return True if Glances is running in client browser mode."""
442
        return self.args.browser and not self.args.server
N
Nicolas Hennion 已提交
443 444

    def is_server(self):
A
PEP 257  
Alessio Sergi 已提交
445
        """Return True if Glances is running in server mode."""
446
        return not self.args.client and self.args.server
N
Nicolas Hennion 已提交
447

448
    def is_webserver(self):
A
PEP 257  
Alessio Sergi 已提交
449
        """Return True if Glances is running in Web server mode."""
450
        return not self.args.client and self.args.webserver
N
Nicolas Hennion 已提交
451

452
    def get_config(self):
A
PEP 257  
Alessio Sergi 已提交
453
        """Return configuration file object."""
454
        return self.config
N
Nicolas Hennion 已提交
455 456

    def get_args(self):
A
PEP 257  
Alessio Sergi 已提交
457
        """Return the arguments."""
A
Alessio Sergi 已提交
458
        return self.args
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477

    def get_mode(self):
        """Return the mode."""
        return self.mode

    def __get_username(self, description=''):
        """Read an username from the command line.
        """
        return input(description)

    def __get_password(self, description='', confirm=False, clear=False, username='glances'):
        """Read a password from the command line.

        - if confirm = True, with confirmation
        - if clear = True, plain (clear password)
        """
        from glances.password import GlancesPassword
        password = GlancesPassword(username=username)
        return password.get_password(description, confirm, clear)