Add auto generation refresh time function

This commit is contained in:
nicolargo 2018-04-02 14:07:23 +02:00
parent 476d441c0e
commit da75b97047
20 changed files with 74 additions and 17 deletions

View File

@ -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

4
docs/_static/graph-load.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 183 KiB

View File

@ -21,7 +21,7 @@ and run Glances with:
.. code-block:: console
$ glances --export-cassandra
$ glances --export cassandra
The data model is the following:

View File

@ -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:

View File

@ -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:

View File

@ -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:

34
docs/gw/graph.rst Normal file
View File

@ -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

View File

@ -14,6 +14,7 @@ to providing stats to multiple services (see list below).
cassandra
couchdb
elastic
graph
influxdb
json
kafka

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -19,4 +19,4 @@ and run Glances with:
.. code-block:: console
$ glances --export-opentsdb
$ glances --export opentsdb

View File

@ -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

View File

@ -20,4 +20,4 @@ and run Glances with:
.. code-block:: console
$ glances --export-rabbitmq
$ glances --export rabbitmq

View File

@ -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`_).

View File

@ -17,4 +17,4 @@ and run Glances with:
.. code-block:: console
$ glances --export-riemann
$ glances --export riemann

View File

@ -20,7 +20,7 @@ and run Glances with:
.. code-block:: console
$ glances --export-statsd
$ glances --export statsd
Glances will generate stats as:

View File

@ -26,7 +26,7 @@ Run Glances with:
.. code-block:: console
$ glances --export-zeromq -C <path>/glances.conf
$ glances --export zeromq
Following is a simple Python client to subscribe to the Glances stats:

View File

@ -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
.

View File

@ -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