From da75b970473d0844a9f604d6b51ab773ff39d6e5 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Mon, 2 Apr 2018 14:07:23 +0200 Subject: [PATCH] Add auto generation refresh time function --- conf/glances.conf | 4 ++++ docs/_static/graph-load.svg | 4 ++++ docs/gw/cassandra.rst | 2 +- docs/gw/couchdb.rst | 2 +- docs/gw/csv.rst | 2 +- docs/gw/elastic.rst | 2 +- docs/gw/graph.rst | 34 ++++++++++++++++++++++++++++++++ docs/gw/index.rst | 1 + docs/gw/influxdb.rst | 2 +- docs/gw/json.rst | 2 +- docs/gw/kafka.rst | 2 +- docs/gw/opentsdb.rst | 2 +- docs/gw/prometheus.rst | 2 +- docs/gw/rabbitmq.rst | 2 +- docs/gw/restful.rst | 2 +- docs/gw/riemann.rst | 2 +- docs/gw/statsd.rst | 2 +- docs/gw/zeromq.rst | 2 +- docs/man/glances.1 | 2 +- glances/exports/glances_graph.py | 18 +++++++++++++++-- 20 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 docs/_static/graph-load.svg create mode 100644 docs/gw/graph.rst diff --git a/conf/glances.conf b/conf/glances.conf index f7d30f41..21cbf027 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -320,6 +320,10 @@ all=False # Set the path where the graph (.svg files) will be created # Can be overwrite by the --graph-path command line option path=/tmp +# It is possible to generate the graphs automatically by setting the +# generate_every to a non zero value corresponding to the seconds between +# two generation. Set it to 0 to disable graph auto generation. +generate_every=60 # See followings configuration keys definitions in the Pygal lib documentation # http://pygal.org/en/stable/documentation/index.html width=800 diff --git a/docs/_static/graph-load.svg b/docs/_static/graph-load.svg new file mode 100644 index 00000000..d351dadd --- /dev/null +++ b/docs/_static/graph-load.svg @@ -0,0 +1,4 @@ + +Load0.20.20.40.40.60.60.80.8111.21.21.41.41.61.62018/04/02 11:03:202018/04/02 11:03:202018/04/02 11:20:002018/04/02 11:20:002018/04/02 11:36:402018/04/02 11:36:402018/04/02 11:53:202018/04/02 11:53:202018/04/02 12:10:002018/04/02 12:10:002018/04/02 12:26:402018/04/02 12:26:402018/04/02 12:43:202018/04/02 12:43:202018/04/02 13:00:002018/04/02 13:00:00Loadmin1min5min15 \ No newline at end of file diff --git a/docs/gw/cassandra.rst b/docs/gw/cassandra.rst index be684e56..fb603b95 100644 --- a/docs/gw/cassandra.rst +++ b/docs/gw/cassandra.rst @@ -21,7 +21,7 @@ and run Glances with: .. code-block:: console - $ glances --export-cassandra + $ glances --export cassandra The data model is the following: diff --git a/docs/gw/couchdb.rst b/docs/gw/couchdb.rst index 8501ff1b..66c547ba 100644 --- a/docs/gw/couchdb.rst +++ b/docs/gw/couchdb.rst @@ -20,7 +20,7 @@ and run Glances with: .. code-block:: console - $ glances --export-couchdb + $ glances --export couchdb Documents are stored in native ``JSON`` format. Glances adds ``"type"`` and ``"time"`` entries: diff --git a/docs/gw/csv.rst b/docs/gw/csv.rst index 2b025195..3e766e0a 100644 --- a/docs/gw/csv.rst +++ b/docs/gw/csv.rst @@ -7,7 +7,7 @@ It's possible to export stats to a CSV file. .. code-block:: console - $ glances --export-csv /tmp/glances.csv + $ glances --export csv --export-csv-file /tmp/glances.csv CSV file description: diff --git a/docs/gw/elastic.rst b/docs/gw/elastic.rst index 06c70c9a..f0897f02 100644 --- a/docs/gw/elastic.rst +++ b/docs/gw/elastic.rst @@ -17,7 +17,7 @@ and run Glances with: .. code-block:: console - $ glances --export-elasticsearch + $ glances --export elasticsearch The stats are available through the elasticsearch API. For example, to get the CPU system stats: diff --git a/docs/gw/graph.rst b/docs/gw/graph.rst new file mode 100644 index 00000000..f4a742bc --- /dev/null +++ b/docs/gw/graph.rst @@ -0,0 +1,34 @@ +.. _graph: + +Graph +====== + +You can generate dynamic graphs (SVG format) in a target folder. The generation +starts every time the 'g' key is pressed in the CLI interface. + +.. code-block:: ini + + [graph] + # Configuration for the --export graph option + # Set the path where the graph (.svg files) will be created + # Can be overwrite by the --graph-path command line option + path=/tmp + # It is possible to generate the graphs automatically by setting the + # generate_every to a non zero value corresponding to the seconds between + # two generation. Set it to 0 to disable graph auto generation. + generate_every=60 + # See followings configuration keys definitions in the Pygal lib documentation + # http://pygal.org/en/stable/documentation/index.html + width=800 + height=600 + style=DarkStyle + +and run Glances with: + +.. code-block:: console + + $ glances --export graph --export-graph-path /tmp + +Example of output (load graph) + +.. image:: ../_static/graph-load.svg diff --git a/docs/gw/index.rst b/docs/gw/index.rst index 26041717..7f587a4f 100644 --- a/docs/gw/index.rst +++ b/docs/gw/index.rst @@ -14,6 +14,7 @@ to providing stats to multiple services (see list below). cassandra couchdb elastic + graph influxdb json kafka diff --git a/docs/gw/influxdb.rst b/docs/gw/influxdb.rst index f7fe3376..3c7025a5 100644 --- a/docs/gw/influxdb.rst +++ b/docs/gw/influxdb.rst @@ -21,7 +21,7 @@ and run Glances with: .. code-block:: console - $ glances --export-influxdb + $ glances --export influxdb Glances generates a lot of columns, e.g., if you have many running Docker containers, so you should use the ``tsm1`` engine in the InfluxDB diff --git a/docs/gw/json.rst b/docs/gw/json.rst index 4bffccc6..0b086c7d 100644 --- a/docs/gw/json.rst +++ b/docs/gw/json.rst @@ -7,4 +7,4 @@ It's possible to export stats to a JSON file. .. code-block:: console - $ glances --export-json /tmp/glances.json + $ glances --export json --export-json-file json /tmp/glances.json diff --git a/docs/gw/kafka.rst b/docs/gw/kafka.rst index 1b25ec68..2bfe532a 100644 --- a/docs/gw/kafka.rst +++ b/docs/gw/kafka.rst @@ -21,7 +21,7 @@ and run Glances with: .. code-block:: console - $ glances --export-kafka + $ glances --export kafka Stats are sent in native ``JSON`` format to the topic: diff --git a/docs/gw/opentsdb.rst b/docs/gw/opentsdb.rst index d0857b07..554dc7d6 100644 --- a/docs/gw/opentsdb.rst +++ b/docs/gw/opentsdb.rst @@ -19,4 +19,4 @@ and run Glances with: .. code-block:: console - $ glances --export-opentsdb + $ glances --export opentsdb diff --git a/docs/gw/prometheus.rst b/docs/gw/prometheus.rst index bf486ea2..655c4c6a 100644 --- a/docs/gw/prometheus.rst +++ b/docs/gw/prometheus.rst @@ -18,7 +18,7 @@ and run Glances with: .. code-block:: console - $ glances --export-prometheus + $ glances --export prometheus You can check that Glances exports the stats using this URL: http://localhost:9091 diff --git a/docs/gw/rabbitmq.rst b/docs/gw/rabbitmq.rst index 151d45f4..173b9b3c 100644 --- a/docs/gw/rabbitmq.rst +++ b/docs/gw/rabbitmq.rst @@ -20,4 +20,4 @@ and run Glances with: .. code-block:: console - $ glances --export-rabbitmq + $ glances --export rabbitmq diff --git a/docs/gw/restful.rst b/docs/gw/restful.rst index d314cf59..6a748564 100644 --- a/docs/gw/restful.rst +++ b/docs/gw/restful.rst @@ -34,7 +34,7 @@ and run Glances with: .. code-block:: console - $ glances --export-restful + $ glances --export restful Glances will generate stats as a big JSON dictionary (see example `here`_). diff --git a/docs/gw/riemann.rst b/docs/gw/riemann.rst index 690fb9a0..abb920f6 100644 --- a/docs/gw/riemann.rst +++ b/docs/gw/riemann.rst @@ -17,4 +17,4 @@ and run Glances with: .. code-block:: console - $ glances --export-riemann + $ glances --export riemann diff --git a/docs/gw/statsd.rst b/docs/gw/statsd.rst index 8b55ba6f..6cc681e6 100644 --- a/docs/gw/statsd.rst +++ b/docs/gw/statsd.rst @@ -20,7 +20,7 @@ and run Glances with: .. code-block:: console - $ glances --export-statsd + $ glances --export statsd Glances will generate stats as: diff --git a/docs/gw/zeromq.rst b/docs/gw/zeromq.rst index 168ecbcf..3af4b710 100644 --- a/docs/gw/zeromq.rst +++ b/docs/gw/zeromq.rst @@ -26,7 +26,7 @@ Run Glances with: .. code-block:: console - $ glances --export-zeromq -C /glances.conf + $ glances --export zeromq Following is a simple Python client to subscribe to the Glances stats: diff --git a/docs/man/glances.1 b/docs/man/glances.1 index c68e572f..0e5a4d36 100644 --- a/docs/man/glances.1 +++ b/docs/man/glances.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH "GLANCES" "1" "Feb 11, 2018" "3.0.dev0" "Glances" +.TH "GLANCES" "1" "Apr 02, 2018" "3.0.rc1" "Glances" .SH NAME glances \- An eye on your system . diff --git a/glances/exports/glances_graph.py b/glances/exports/glances_graph.py index a4dd839b..e2a2af38 100644 --- a/glances/exports/glances_graph.py +++ b/glances/exports/glances_graph.py @@ -27,6 +27,7 @@ import tempfile import errno from glances.logger import logger +from glances.timer import Timer from glances.compat import iteritems, time_serie_subsample from glances.exports.glances_export import GlancesExport @@ -42,12 +43,14 @@ class Export(GlancesExport): # Load the Graph configuration file section (is exists) self.export_enable = self.load_conf('graph', options=['path', + 'generate_every', 'width', 'height', 'style']) # Manage options (command line arguments overwrite configuration file) self.path = args.export_graph_path or self.path + self.generate_every = int(getattr(self, 'generate_every', 0)) self.width = int(getattr(self, 'width', 800)) self.height = int(getattr(self, 'height', 600)) self.style = getattr(pygal.style, @@ -69,8 +72,14 @@ class Export(GlancesExport): logger.critical("Graph output folder {} is not writeable".format(self.path)) sys.exit(2) - logger.info("Graphs will be created in the folder {}".format(self.path)) - logger.info("Graphs are created when 'g' key is pressed") + logger.info("Graphs will be created in the {} folder".format(self.path)) + logger.info("Graphs will be created when 'g' key is pressed (in the CLI interface)") + if self.generate_every != 0: + logger.info("Graphs will be created automatically every {} seconds".format(self.generate_every)) + # Start the timer + self._timer = Timer(self.generate_every) + else: + self._timer = None def exit(self): """Close the files.""" @@ -78,6 +87,11 @@ class Export(GlancesExport): def update(self, stats): """Generate Graph file in the output folder.""" + + if self.generate_every != 0 and self._timer.finished(): + self.args.generate_graph = True + self._timer.reset() + if not self.args.generate_graph: return