mirror of https://github.com/nicolargo/glances.git
Make --stdout (csv and json) compliant with client/server mode #3235
This commit is contained in:
parent
e46eb765ff
commit
c1d67556c7
|
|
@ -17,6 +17,9 @@ from glances import __version__
|
|||
from glances.globals import json_loads
|
||||
from glances.logger import logger
|
||||
from glances.outputs.glances_curses import GlancesCursesClient
|
||||
from glances.outputs.glances_stdout import GlancesStdout
|
||||
from glances.outputs.glances_stdout_csv import GlancesStdoutCsv
|
||||
from glances.outputs.glances_stdout_json import GlancesStdoutJson
|
||||
from glances.stats_client import GlancesStatsClient
|
||||
from glances.timer import Counter
|
||||
|
||||
|
|
@ -172,6 +175,18 @@ class GlancesClient:
|
|||
if self.quiet:
|
||||
# In quiet mode, nothing is displayed
|
||||
logger.info("Quiet mode is ON: Nothing will be displayed")
|
||||
elif self.args.stdout:
|
||||
logger.info(f"Stdout mode is ON, following stats will be displayed: {self.args.stdout}")
|
||||
# Init screen
|
||||
self.screen = GlancesStdout(config=self.config, args=self.args)
|
||||
elif self.args.stdout_json:
|
||||
logger.info(f"Stdout JSON mode is ON, following stats will be displayed: {self.args.stdout_json}")
|
||||
# Init screen
|
||||
self.screen = GlancesStdoutJson(config=self.config, args=self.args)
|
||||
elif self.args.stdout_csv:
|
||||
logger.info(f"Stdout CSV mode is ON, following stats will be displayed: {self.args.stdout_csv}")
|
||||
# Init screen
|
||||
self.screen = GlancesStdoutCsv(config=self.config, args=self.args)
|
||||
else:
|
||||
self.screen = GlancesCursesClient(config=self.config, args=self.args)
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class GlancesStdout:
|
|||
def end(self):
|
||||
pass
|
||||
|
||||
def update(self, stats, duration=3):
|
||||
def update(self, stats, duration=3, cs_status=None, return_to_browser=False):
|
||||
"""Display stats to stdout.
|
||||
|
||||
Refresh every duration second.
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class GlancesStdoutCsv:
|
|||
|
||||
return line
|
||||
|
||||
def update(self, stats, duration=3):
|
||||
def update(self, stats, duration=3, cs_status=None, return_to_browser=False):
|
||||
"""Display stats to stdout.
|
||||
|
||||
Refresh every duration second.
|
||||
|
|
|
|||
|
|
@ -34,19 +34,25 @@ class GlancesStdoutJson:
|
|||
def end(self):
|
||||
pass
|
||||
|
||||
def update(self, stats, duration=3):
|
||||
def update(self, stats, duration=3, cs_status=None, return_to_browser=False):
|
||||
"""Display stats in JSON format to stdout.
|
||||
|
||||
Refresh every duration second.
|
||||
"""
|
||||
all_in_json = '{'
|
||||
plugins_list_json = []
|
||||
for plugin in self.plugins_list:
|
||||
# Check if the plugin exist and is enable
|
||||
if plugin in stats.getPluginsList() and stats.get_plugin(plugin).is_enabled():
|
||||
stat = stats.get_plugin(plugin).get_json()
|
||||
plugins_list_json.append(f'"{plugin}": {stats.get_plugin(plugin).get_json().decode("utf-8")}')
|
||||
else:
|
||||
continue
|
||||
# Display stats
|
||||
printandflush(f'{plugin}: {stat.decode()}')
|
||||
# Join all plugins in a single JSON object
|
||||
all_in_json += ', '.join(plugins_list_json)
|
||||
all_in_json += '}'
|
||||
|
||||
# Display stats
|
||||
printandflush(all_in_json)
|
||||
|
||||
# Wait until next refresh
|
||||
if duration > 0:
|
||||
|
|
|
|||
Loading…
Reference in New Issue