Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self):
"""Init the Prometheus Exporter"""
try:
start_http_server(port=int(self.port), addr=self.host)
except Exception as e:
logger.critical("Can not start Prometheus exporter on {}:{} ({})".format(self.host, self.port, e))
sys.exit(2)
else:
logger.info("Start Prometheus exporter on {}:{}".format(self.host, self.port))
# The users dict
# username / password couple
# By default, no auth is needed
self.server.user_dict = {}
self.server.isAuth = False
# Register functions
self.server.register_introspection_functions()
self.server.register_instance(GlancesInstance(config, args))
if not self.args.disable_autodiscover:
# Note: The Zeroconf service name will be based on the hostname
# Correct issue: Zeroconf problem with zeroconf service name #889
self.autodiscover_client = GlancesAutoDiscoverClient(socket.gethostname().split('.', 1)[0], args)
else:
logger.info("Glances autodiscover announce is disabled")
def init(self):
"""Init the connection to the ES server."""
if not self.export_enable:
return None
try:
es = Elasticsearch(hosts=['{}:{}'.format(self.host, self.port)])
except Exception as e:
logger.critical("Cannot connect to ElasticSearch server %s:%s (%s)" % (self.host, self.port, e))
sys.exit(2)
else:
logger.info("Connected to the ElasticSearch server %s:%s" % (self.host, self.port))
try:
index_count = es.count(index=self.index)['count']
except Exception as e:
# Index did not exist, it will be created at the first write
# Create it...
es.indices.create(self.index)
else:
logger.info("There is already %s entries in the ElasticSearch %s index" % (index_count, self.index))
return es
"""Generate Graph file in the output folder."""
if self.generate_every != 0 and self._timer.finished():
self.args.generate_graph = True
self._timer.reset()
if not self.args.generate_graph:
return
plugins = stats.getPluginsList()
for plugin_name in plugins:
plugin = stats._plugins[plugin_name]
if plugin_name in self.plugins_to_export():
self.export(plugin_name, plugin.get_export_history())
logger.info("Graphs created in the folder {}".format(self.path))
self.args.generate_graph = False
callback=self._api_item_history)
self._app.route('/api/%s///' % self.API_VERSION, method="GET",
callback=self._api_value)
bindmsg = 'Glances RESTful API Server started on {}api/{}/'.format(self.bind_url,
self.API_VERSION)
logger.info(bindmsg)
# WEB UI
if not self.args.disable_webui:
self._app.route('/', method="GET", callback=self._index)
self._app.route('/', method=["GET"], callback=self._index)
self._app.route('/', method="GET", callback=self._resource)
bindmsg = 'Glances Web User Interface started on {}'.format(self.bind_url)
logger.info(bindmsg)
else:
logger.info('The WebUI is disable (--disable-webui)')
print(bindmsg)
def remove_service(self, zeroconf, srv_type, srv_name):
"""Remove the server from the list."""
self.servers.remove_server(srv_name)
logger.info(
"Glances server %s removed from the autodetect list" % srv_name)
def load(self, config):
"""Load the password from the configuration file."""
password_dict = {}
if config is None:
logger.warning("No configuration file available. Cannot load password list.")
elif not config.has_section(self._section):
logger.warning("No [%s] section in the configuration file. Cannot load password list." % self._section)
else:
logger.info("Start reading the [%s] section in the configuration file" % self._section)
password_dict = dict(config.items(self._section))
# Password list loaded
logger.info("%s password(s) loaded from the configuration file" % len(password_dict))
logger.debug("Password dictionary: %s" % password_dict)
return password_dict
# Initial system informations update
start_duration.reset()
self.stats.update()
logger.debug("First stats update duration: {} seconds".format(start_duration.get()))
if self.quiet:
logger.info("Quiet mode is ON, nothing will be displayed")
# In quiet mode, nothing is displayed
glances_processes.max_processes = 0
elif args.stdout:
logger.info("Stdout mode is ON, following stats will be displayed: {}".format(args.stdout))
# Init screen
self.screen = GlancesStdout(config=config, args=args)
elif args.stdout_csv:
logger.info("Stdout CSV mode is ON, following stats will be displayed: {}".format(args.stdout))
# Init screen
self.screen = GlancesStdoutCsv(config=config, args=args)
else:
# Default number of processes to displayed is set to 50
glances_processes.max_processes = 50
# Init screen
self.screen = GlancesCursesStandalone(config=config, args=args)
# Check the latest Glances version
self.outdated = Outdated(config=config, args=args)
from logging import DEBUG
logger.setLevel(DEBUG)
# Client/server Port
if args.port is None:
if args.webserver:
args.port = self.web_server_port
else:
args.port = self.server_port
# Port in the -c URI #996
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)))
# Autodiscover
if args.disable_autodiscover:
logger.info("Auto discover mode is disabled")
# By default Windows is started in Web mode
if WINDOWS:
args.webserver = True
# In web server mode
if args.webserver:
args.process_short_name = True
# Server or client login/password
if args.username_prompt:
# Every username needs a password
args.password_prompt = True
# Prompt username
if args.server:
args.username = self.__get_username(