Ok but too high CPU consumption

This commit is contained in:
nicolargo
2018-03-24 17:09:10 +01:00
parent 23f44c34e8
commit 08af7718ba
6 changed files with 92 additions and 1 deletions

1
NEWS
View File

@@ -9,6 +9,7 @@ Enhancements and new features:
* Make the left side bar width dynamic in the Curse UI #1177
* A way to have only REST API available and disable WEB GUI access #1149
* Replace Matplolib by Pygal #697
* Docker module doesn't export details about stopped containers #1152
* Add dynamic fields in all sections of the configuration file #1204
* Make plugins disable and export CLI option dynamical #1173

View File

@@ -71,6 +71,7 @@ Optional dependencies:
- ``potsdb`` (for the OpenTSDB export module)
- ``prometheus_client`` (for the Prometheus export module)
- ``py-cpuinfo`` (for the Quicklook CPU info module)
- ``pygal`` (for the graph export module)
- ``pymdstat`` (for RAID support) [Linux-only]
- ``pysnmp`` (for SNMP support)
- ``pystache`` (for the action script feature)

View File

@@ -146,7 +146,7 @@ class GlancesExport(object):
The method builds two lists: names and values
and calls the export method to export the stats.
Be aware that CSV export overwrite this class and use a specific one.
Note: this class can be overwrite (for example in CSV and Graph).
"""
if not self.export_enable:
return False

View File

@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
# Copyright (C) 2018 Nicolargo <nicolas@nicolargo.com>
#
# 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/>.
"""Graph exporter interface class."""
from pygal import DateTimeLine
import sys
import os
from glances.logger import logger
from glances.compat import iteritems
from glances.exports.glances_export import GlancesExport
class Export(GlancesExport):
"""This class manages the Graph export module."""
def __init__(self, config=None, args=None):
"""Init the export IF."""
super(Export, self).__init__(config=config, args=args)
# Graph export folder path
self._graph_path = args.export_graph_path
# TODO: Test if the folder exist. Overwise, create it.
try:
pass
except IOError as e:
logger.critical("Cannot create the CSV file: {}".format(e))
sys.exit(2)
logger.info("Graph will be created in folder:: {}".format(self._graph_path))
self.export_enable = True
def exit(self):
"""Close the files."""
logger.debug("Finalise export interface %s" % self.export_name)
def update(self, stats):
"""Generate Graph file in the output folder."""
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())
def export(self, title, data):
"""Generate one graph per item from the data.
Example for the mem plugin:
{'percent': [
(datetime.datetime(2018, 3, 24, 16, 27, 47, 282070), 51.8),
(datetime.datetime(2018, 3, 24, 16, 27, 47, 540999), 51.9),
(datetime.datetime(2018, 3, 24, 16, 27, 50, 653390), 52.0),
(datetime.datetime(2018, 3, 24, 16, 27, 53, 749702), 52.0),
(datetime.datetime(2018, 3, 24, 16, 27, 56, 825660), 52.0),
...
]
}
"""
for k, v in iteritems(data):
chart = DateTimeLine(x_label_rotation=20,
x_value_formatter=lambda dt: dt.strftime('%d, %b %Y at %I:%M:%S %p'))
chart.add(k, v)
chart.render_to_file(os.path.join(self._graph_path,
title + '.svg'))

View File

@@ -169,6 +169,10 @@ Examples of use:
default='./glances.json',
dest='export_json_file',
help='file path for JSON exporter')
parser.add_argument('--export-graph-path',
default='/tmp',
dest='export_graph_path',
help='Folder for Graph exporter')
# Client/Server option
parser.add_argument('-c', '--client', dest='client',
help='connect to a Glances server by IPv4/IPv6 address or hostname')

View File

@@ -12,6 +12,7 @@ pika
potsdb
prometheus_client
py-cpuinfo
pygal
pymdstat
pysnmp
pystache