summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2018-03-24 17:09:10 +0100
committernicolargo <nicolas@nicolargo.com>2018-03-24 17:09:10 +0100
commit08af7718ba76e4646e9b60ed8e312de9fa93e25e (patch)
tree4abbb1582d71300fcd88bedd7dd41fcb7ca79d6c
parent23f44c34e81caa8eb6eb0f2e1d30532e2cf99e5f (diff)
Ok but too high CPU consumption
-rw-r--r--NEWS1
-rw-r--r--README.rst1
-rw-r--r--glances/exports/glances_export.py2
-rw-r--r--glances/exports/glances_graph.py84
-rw-r--r--glances/main.py4
-rw-r--r--optional-requirements.txt1
6 files changed, 92 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index f88ca28f..772f0241 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/README.rst b/README.rst
index 385bc832..0230696d 100644
--- a/README.rst
+++ b/README.rst
@@ -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)
diff --git a/glances/exports/glances_export.py b/glances/exports/glances_export.py
index c5f72662..130abe3a 100644
--- a/glances/exports/glances_export.py
+++ b/glances/exports/glances_export.py
@@ -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
diff --git a/glances/exports/glances_graph.py b/glances/exports/glances_graph.py
new file mode 100644
index 00000000..d8a57cc5
--- /dev/null
+++ b/glances/exports/glances_graph.py
@@ -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'))
diff --git a/glances/main.py b/glances/main.py
index ab78a12b..2c8d823a 100644
--- a/glances/main.py
+++ b/glances/main.py
@@ -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')
diff --git a/optional-requirements.txt b/optional-requirements.txt
index c1ad0f73..022423ff 100644
--- a/optional-requirements.txt
+++ b/optional-requirements.txt
@@ -12,6 +12,7 @@ pika
potsdb
prometheus_client
py-cpuinfo
+pygal
pymdstat
pysnmp
pystache