Add a configuration key to set the gaph ouput folder --output-history - issue #428

This commit is contained in:
Nicolargo 2014-10-12 15:53:16 +02:00
parent 7edcd3e467
commit 94614e1f18
3 changed files with 25 additions and 19 deletions

View File

@ -22,6 +22,8 @@
# Import system libs
import argparse
import sys
import os
import tempfile
# Import Glances libs
from glances.core.glances_config import Config
@ -34,6 +36,7 @@ class GlancesMain(object):
# Default stats' refresh time is 3 seconds
refresh_time = 3
# Set the default cache lifetime to 1 second (only for server)
# !!! Todo: configuration from the command line
cached_time = 1
@ -61,10 +64,6 @@ class GlancesMain(object):
parser.add_argument('-C', '--config', dest='conf_file',
help=_('path to the configuration file'))
# Enable or disable option on startup
parser.add_argument('--enable-history', action='store_true', default=False,
dest='enable_history', help=_('enable the history mode'))
parser.add_argument('--disable-bold', action='store_false', default=True,
dest='disable_bold', help=_('disable bold mode in the terminal'))
parser.add_argument('--disable-network', action='store_true', default=False,
dest='disable_network', help=_('disable network module'))
parser.add_argument('--disable-diskio', action='store_true', default=False,
@ -81,6 +80,12 @@ class GlancesMain(object):
dest='disable_process_extended', help=_('disable extended stats on top process'))
parser.add_argument('--disable-log', action='store_true', default=False,
dest='disable_log', help=_('disable log module'))
parser.add_argument('--disable-bold', action='store_false', default=True,
dest='disable_bold', help=_('disable bold mode in the terminal'))
parser.add_argument('--enable-history', action='store_true', default=False,
dest='enable_history', help=_('enable the history mode'))
parser.add_argument('--path-history', default=tempfile.gettempdir(),
dest='path_history', help=_('Set the export path for graph history'))
# CSV output feature
parser.add_argument('--output-csv', default=None,
dest='output_csv', help=_('export stats to a CSV file'))
@ -187,6 +192,13 @@ class GlancesMain(object):
logger.critical(_("Process filter is only available in standalone mode"))
sys.exit(2)
# Check graph output path
if args.enable_history and args.path_history is not None:
if not os.access(args.path_history, os.W_OK):
logger.critical(_("History output path (%s) do not exist or is not writable") % args.path_history)
sys.exit(2)
logger.info(_("History output path is %s") % args.path_history)
return args
def __hash_password(self, plain_password):

View File

@ -184,12 +184,12 @@ class GlancesCurses(object):
self.reset_history_tag = False
self.history_tag = False
if args.enable_history:
logger.info('Stats history enabled')
logger.info('Stats history enabled with output path %s' % args.path_history)
from glances.outputs.glances_history import GlancesHistory
self.glances_history = GlancesHistory()
self.glances_history = GlancesHistory(args.path_history)
if not self.glances_history.graph_enabled():
args.enable_history = False
logger.error('Stats history disabled because graph lib is not available')
logger.error('Stats history disabled because MatPlotLib is not installed')
def set_cursor(self, value):
"""Configure the cursor

View File

@ -21,7 +21,6 @@
# Import system lib
import os
import tempfile
# Import Glances lib
from glances.core.glances_globals import logger
@ -43,12 +42,7 @@ class GlancesHistory(object):
"""This class define the object to manage stats history"""
def __init__(self, output_folder=tempfile.gettempdir()):
# !!! MINUS: matplotlib footprint (mem/cpu) => Fork process ?
# !!! MINUS: Mem used to store history
# !!! TODO: sampling before graph => Usefull ?
# !!! TODO: do not display first two point (glances is running)
# !!! TODO: replace /tmp by a cross platform way to get /tmp folder
def __init__(self, output_folder):
self.output_folder = output_folder
def get_output_folder(self):
@ -87,21 +81,21 @@ class GlancesHistory(object):
# Label
plt.title("%s stats" % p)
handles = []
for i in stats.get_plugin(p).get_items_history_list():
handles.append(plt.Rectangle((0, 0), 1, 1, fc=i['color'], ec=i['color'], linewidth=1))
labels = [i['name'] for i in stats.get_plugin(p).get_items_history_list()]
plt.legend(handles, labels, loc=1, prop={'size':9})
plt.legend(handles, labels, loc=1, prop={'size': 9})
formatter = dates.DateFormatter('%H:%M:%S')
ax.xaxis.set_major_formatter(formatter)
# ax.set_ylabel('%')
# Draw the stats
for i in stats.get_plugin(p).get_items_history_list():
ax.plot_date(h['date'], h[i['name']],
i['color'],
label='%s' % i['name'],
ax.plot_date(h['date'], h[i['name']],
i['color'],
label='%s' % i['name'],
xdate=True, ydate=False)
# Save and display