mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-25 10:12:55 +03:00
Rename glances_history to graph
This commit is contained in:
parent
13fbad5b4c
commit
841d1156d4
2
NEWS
2
NEWS
@ -28,6 +28,8 @@ Deprecated:
|
||||
|
||||
* Drop Python 2.6 support (issue #300)
|
||||
* Monitoring process list module is replaced by AMP (see issue #780)
|
||||
* Use --export-graph instead of --enable-history (issue #696)
|
||||
* Use --path-graph instead of --path-history (issue #696)
|
||||
|
||||
Version 2.6.1
|
||||
=============
|
||||
|
@ -17,7 +17,7 @@
|
||||
# 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/>.
|
||||
|
||||
"""History class."""
|
||||
"""Graph generation class."""
|
||||
|
||||
import os
|
||||
|
||||
@ -35,9 +35,9 @@ else:
|
||||
logger.info('Load Matplotlib version %s' % matplotlib_version)
|
||||
|
||||
|
||||
class GlancesHistory(object):
|
||||
class GlancesGraph(object):
|
||||
|
||||
"""This class define the object to manage stats history."""
|
||||
"""Thanks to this class, Glances can export history to graphs."""
|
||||
|
||||
def __init__(self, output_folder):
|
||||
self.output_folder = output_folder
|
@ -148,11 +148,13 @@ Start the client browser (browser mode):\n\
|
||||
dest='disable_bg', help='disable background colors in the terminal')
|
||||
parser.add_argument('--enable-process-extended', action='store_true', default=False,
|
||||
dest='enable_process_extended', help='enable extended stats on top process')
|
||||
parser.add_argument('--enable-history', action='store_true', default=False,
|
||||
dest='enable_history', help='enable the history mode (matplotlib needed)')
|
||||
parser.add_argument('--path-history', default=tempfile.gettempdir(),
|
||||
dest='path_history', help='set the export path for graph history')
|
||||
# Export modules feature
|
||||
# --enable-history is for 2.7< version compatibility
|
||||
parser.add_argument('--export-graph', '--enable-history', action='store_true', default=None,
|
||||
dest='export_graph', help='export stats to graphs')
|
||||
# --path-history is for 2.7< version compatibility
|
||||
parser.add_argument('--path-graph', '--path-history', default=tempfile.gettempdir(),
|
||||
dest='path_graph', help='set the export path for graphs (default is {0})'.format(tempfile.gettempdir()))
|
||||
parser.add_argument('--export-csv', default=None,
|
||||
dest='export_csv', help='export stats to a CSV file')
|
||||
parser.add_argument('--export-influxdb', action='store_true', default=False,
|
||||
@ -337,11 +339,11 @@ Start the client browser (browser mode):\n\
|
||||
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 {0} do not exist or is not writable".format(args.path_history))
|
||||
if args.export_graph and args.path_graph is not None:
|
||||
if not os.access(args.path_graph, os.W_OK):
|
||||
logger.critical("Graphs output path {0} do not exist or is not writable".format(args.path_graph))
|
||||
sys.exit(2)
|
||||
logger.debug("History output path is set to {0}".format(args.path_history))
|
||||
logger.debug("Graphs output path is set to {0}".format(args.path_graph))
|
||||
|
||||
# Disable HDDTemp if sensors are disabled
|
||||
if args.disable_sensors:
|
||||
|
@ -117,16 +117,15 @@ class _GlancesCurses(object):
|
||||
'''Init the history option'''
|
||||
|
||||
self.reset_history_tag = False
|
||||
self.history_tag = False
|
||||
if self.args.enable_history:
|
||||
logger.info('Stats history enabled with output path %s' %
|
||||
self.args.path_history)
|
||||
from glances.exports.glances_history import GlancesHistory
|
||||
self.glances_history = GlancesHistory(self.args.path_history)
|
||||
if not self.glances_history.graph_enabled():
|
||||
self.args.enable_history = False
|
||||
logger.error(
|
||||
'Stats history disabled because MatPlotLib is not installed')
|
||||
self.graph_tag = False
|
||||
if self.args.export_graph:
|
||||
logger.info('Export graphs function enabled with output path %s' %
|
||||
self.args.path_graph)
|
||||
from glances.exports.graph import GlancesGraph
|
||||
self.glances_graph = GlancesGraph(self.args.path_graph)
|
||||
if not self.glances_graph.graph_enabled():
|
||||
self.args.export_graph = False
|
||||
logger.error('Export graphs disabled')
|
||||
|
||||
def _init_cursor(self):
|
||||
'''Init cursors'''
|
||||
@ -384,8 +383,8 @@ class _GlancesCurses(object):
|
||||
self.args.disable_fs = not self.args.disable_fs
|
||||
self.args.disable_folder = not self.args.disable_folder
|
||||
elif self.pressedkey == ord('g'):
|
||||
# 'g' > History
|
||||
self.history_tag = not self.history_tag
|
||||
# 'g' > Export graphs to file
|
||||
self.graph_tag = not self.graph_tag
|
||||
elif self.pressedkey == ord('h'):
|
||||
# 'h' > Show/hide help
|
||||
self.args.help_tag = not self.args.help_tag
|
||||
@ -756,25 +755,25 @@ class _GlancesCurses(object):
|
||||
|
||||
# History option
|
||||
# Generate history graph
|
||||
if self.history_tag and self.args.enable_history:
|
||||
if self.graph_tag and self.args.export_graph:
|
||||
self.display_popup(
|
||||
'Generate graphs history in {0}\nPlease wait...'.format(
|
||||
self.glances_history.get_output_folder()))
|
||||
self.glances_graph.get_output_folder()))
|
||||
self.display_popup(
|
||||
'Generate graphs history in {0}\nDone: {1} graphs generated'.format(
|
||||
self.glances_history.get_output_folder(),
|
||||
self.glances_history.generate_graph(stats)))
|
||||
elif self.reset_history_tag and self.args.enable_history:
|
||||
self.glances_graph.get_output_folder(),
|
||||
self.glances_graph.generate_graph(stats)))
|
||||
elif self.reset_history_tag and self.args.export_graph:
|
||||
self.display_popup('Reset history')
|
||||
self.glances_history.reset(stats)
|
||||
elif (self.history_tag or self.reset_history_tag) and not self.args.enable_history:
|
||||
self.glances_graph.reset(stats)
|
||||
elif (self.graph_tag or self.reset_history_tag) and not self.args.export_graph:
|
||||
try:
|
||||
self.glances_history.graph_enabled()
|
||||
self.glances_graph.graph_enabled()
|
||||
except Exception:
|
||||
self.display_popup('History disabled\nEnable it using --enable-history')
|
||||
else:
|
||||
self.display_popup('History disabled\nPlease install matplotlib')
|
||||
self.history_tag = False
|
||||
self.graph_tag = False
|
||||
self.reset_history_tag = False
|
||||
|
||||
# Display edit filter popup
|
||||
|
@ -101,14 +101,14 @@ class GlancesPlugin(object):
|
||||
def init_stats_history(self):
|
||||
"""Init the stats history (dict of GlancesAttribute)."""
|
||||
ret = {}
|
||||
if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None:
|
||||
if self.args is not None and self.args.export_graph and self.get_items_history_list() is not None:
|
||||
init_list = [a['name'] for a in self.get_items_history_list()]
|
||||
logger.debug("Stats history activated for plugin {0} (items: {1})".format(self.plugin_name, init_list))
|
||||
return ret
|
||||
|
||||
def reset_stats_history(self):
|
||||
"""Reset the stats history (dict of GlancesAttribute)."""
|
||||
if self.args is not None and self.args.enable_history and self.get_items_history_list() is not None:
|
||||
if self.args is not None and self.args.export_graph and self.get_items_history_list() is not None:
|
||||
reset_list = [a['name'] for a in self.get_items_history_list()]
|
||||
logger.debug("Reset history for plugin {0} (items: {1})".format(self.plugin_name, reset_list))
|
||||
for a in self.stats_history:
|
||||
@ -117,7 +117,7 @@ class GlancesPlugin(object):
|
||||
def update_stats_history(self, item_name=''):
|
||||
"""Update stats history."""
|
||||
if (self.stats and self.args is not None and
|
||||
self.args.enable_history and
|
||||
self.args.export_graph and
|
||||
self.get_items_history_list() is not None):
|
||||
# TODO in attribute ?
|
||||
self.add_item_history('date', datetime.now())
|
||||
|
Loading…
Reference in New Issue
Block a user