mirror of
https://github.com/nicolargo/glances.git
synced 2024-09-20 00:58:03 +03:00
Export to graphite #1854
This commit is contained in:
parent
4c4b2f319e
commit
6bceeef43f
@ -75,6 +75,7 @@ Optional dependencies:
|
||||
- ``couchdb`` (for the CouchDB export module)
|
||||
- ``docker`` (for the Docker monitoring support) [Linux/macOS-only]
|
||||
- ``elasticsearch`` (for the Elastic Search export module)
|
||||
- ``graphyte`` (For the Graphite export module)
|
||||
- ``hddtemp`` (for HDD temperature monitoring support) [Linux-only]
|
||||
- ``influxdb`` (for the InfluxDB version 1 export module)
|
||||
- ``influxdb-client`` (for the InfluxDB version 2 export module) [Only for Python >= 3.6]
|
||||
@ -409,7 +410,7 @@ Gateway to other services
|
||||
|
||||
Glances can export stats to: ``CSV`` file, ``JSON`` file, ``InfluxDB``, ``Cassandra``, ``CouchDB``,
|
||||
``OpenTSDB``, ``Prometheus``, ``StatsD``, ``ElasticSearch``, ``RabbitMQ/ActiveMQ``,
|
||||
``ZeroMQ``, ``Kafka``, ``Riemann`` and ``RESTful`` server.
|
||||
``ZeroMQ``, ``Kafka``, ``Riemann``, ``Graphite`` and ``RESTful`` server.
|
||||
|
||||
How to contribute ?
|
||||
===================
|
||||
|
@ -586,6 +586,21 @@ port=6789
|
||||
protocol=http
|
||||
path=/
|
||||
|
||||
[graphite]
|
||||
# Configuration for the --export graphite option
|
||||
# https://graphiteapp.org/
|
||||
host=localhost
|
||||
port=2003
|
||||
protocol=tcp
|
||||
batch_size=1000
|
||||
# Prefix will be added for all measurement name
|
||||
# Ex: prefix=foo
|
||||
# => foo.cpu
|
||||
# => foo.mem
|
||||
# You can also use dynamic values
|
||||
#prefix=`hostname`
|
||||
prefix=glances
|
||||
|
||||
##############################################################################
|
||||
# AMPS
|
||||
# * enable: Enable (true) or disable (false) the AMP
|
||||
|
33
docs/gw/graphite.rst
Normal file
33
docs/gw/graphite.rst
Normal file
@ -0,0 +1,33 @@
|
||||
.. _graphite:
|
||||
|
||||
Graphite
|
||||
========
|
||||
|
||||
You can export statistics to a ``Graphite`` server (time series server).
|
||||
|
||||
The connection should be defined in the Glances configuration file as
|
||||
following:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[graphite]
|
||||
host=localhost
|
||||
port=2003
|
||||
protocol=udp
|
||||
batch_size=1000
|
||||
# Prefix will be added for all measurement name
|
||||
# Ex: prefix=foo
|
||||
# => foo.cpu
|
||||
# => foo.mem
|
||||
# You can also use dynamic values
|
||||
#prefix=`hostname`
|
||||
prefix=glances
|
||||
|
||||
and run Glances with:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ glances --export graphite
|
||||
|
||||
|
||||
Note: Only integer and float are supported in the Graphite datamodel.
|
112
glances/exports/glances_graphite.py
Normal file
112
glances/exports/glances_graphite.py
Normal file
@ -0,0 +1,112 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Glances.
|
||||
#
|
||||
# Copyright (C) 2021 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/>.
|
||||
|
||||
"""Graphite interface class."""
|
||||
|
||||
import sys
|
||||
from numbers import Number
|
||||
|
||||
from glances.compat import range
|
||||
from glances.logger import logger
|
||||
from glances.exports.glances_export import GlancesExport
|
||||
|
||||
import graphyte
|
||||
|
||||
|
||||
class Export(GlancesExport):
|
||||
|
||||
"""This class manages the Graphite export module."""
|
||||
|
||||
def __init__(self, config=None, args=None):
|
||||
"""Init the Graphite export IF."""
|
||||
super(Export, self).__init__(config=config, args=args)
|
||||
|
||||
# Mandatories configuration keys (additional to host and port)
|
||||
# N/A
|
||||
|
||||
# Optionals configuration keys
|
||||
self.prefix = None
|
||||
self.protocol = None
|
||||
self.batch_size = None
|
||||
|
||||
# Load the configuration file
|
||||
self.export_enable = self.load_conf('graphite',
|
||||
mandatories=['host',
|
||||
'port'],
|
||||
options=['prefix',
|
||||
'protocol',
|
||||
'batch_size'])
|
||||
if not self.export_enable:
|
||||
sys.exit(2)
|
||||
|
||||
# Default prefix for stats is 'glances'
|
||||
if self.prefix is None:
|
||||
self.prefix = 'glances'
|
||||
|
||||
if self.protocol is None:
|
||||
self.protocol = 'tcp'
|
||||
|
||||
if self.batch_size is None:
|
||||
self.batch_size = 1000
|
||||
|
||||
# Convert config option type
|
||||
self.port = int(self.port)
|
||||
self.batch_size = int(self.batch_size)
|
||||
|
||||
# Init the Graphite client
|
||||
self.client = self.init()
|
||||
|
||||
def init(self):
|
||||
"""Init the connection to the Graphite server."""
|
||||
if not self.export_enable:
|
||||
return None
|
||||
logger.info(
|
||||
"Stats will be exported to Graphite server: {}:{}/{}".format(self.host,
|
||||
self.port,
|
||||
self.protocol))
|
||||
|
||||
return graphyte.Sender(self.host,
|
||||
port=self.port,
|
||||
prefix=self.prefix,
|
||||
protocol=self.protocol,
|
||||
batch_size=self.batch_size)
|
||||
|
||||
def export(self, name, columns, points):
|
||||
"""Export the stats to the Graphite server."""
|
||||
for i in range(len(columns)):
|
||||
if not isinstance(points[i], Number):
|
||||
# Only Int and Float are supported in the Graphite datamodel
|
||||
continue
|
||||
stat_name = '{}.{}'.format(name, columns[i])
|
||||
stat_value = points[i]
|
||||
try:
|
||||
self.client.send(normalize(stat_name),
|
||||
stat_value)
|
||||
except Exception as e:
|
||||
logger.error("Can not export stats to Graphite (%s)" % e)
|
||||
logger.debug("Export {} stats to Graphite".format(name))
|
||||
|
||||
|
||||
def normalize(name):
|
||||
"""Normalize name for the Graphite convention"""
|
||||
|
||||
# Name should not contain space
|
||||
ret = name.replace(' ', '_')
|
||||
|
||||
return ret
|
@ -44,7 +44,7 @@ class Export(GlancesExport):
|
||||
self.prefix = None
|
||||
self.tags = None
|
||||
|
||||
# Load the InfluxDB configuration file
|
||||
# Load the configuration file
|
||||
self.export_enable = self.load_conf('opentsdb',
|
||||
mandatories=['host', 'port'],
|
||||
options=['prefix', 'tags'])
|
||||
|
@ -43,7 +43,7 @@ class Export(GlancesExport):
|
||||
# Optionals configuration keys
|
||||
self.prefix = None
|
||||
|
||||
# Load the InfluxDB configuration file
|
||||
# Load the configuration file
|
||||
self.export_enable = self.load_conf('statsd',
|
||||
mandatories=['host', 'port'],
|
||||
options=['prefix'])
|
||||
|
@ -8,6 +8,7 @@ chevron
|
||||
couchdb
|
||||
docker>=2.0.0
|
||||
elasticsearch
|
||||
graphyte
|
||||
hddtemp
|
||||
influxdb
|
||||
influxdb-client; python_version >= "3.6"
|
||||
|
6
setup.py
6
setup.py
@ -52,14 +52,14 @@ def get_install_requires():
|
||||
def get_install_extras_require():
|
||||
extras_require = {
|
||||
'action': ['chevron'],
|
||||
# Zeroconf 0.19.1 is the latest one compatible with Python 2 (issue #1293)
|
||||
'browser': ['zeroconf==0.19.1' if PY2 else 'zeroconf>=0.19.1'],
|
||||
'cloud': ['requests'],
|
||||
'cpuinfo': ['py-cpuinfo<=4.0.0'],
|
||||
'docker': ['docker>=2.0.0'],
|
||||
'export': ['bernhard', 'cassandra-driver', 'couchdb', 'elasticsearch',
|
||||
'influxdb>=1.0.0', 'kafka-python', 'pika', 'paho-mqtt', 'potsdb',
|
||||
'prometheus_client', 'pyzmq', 'statsd'],
|
||||
'graphyte', 'influxdb>=1.0.0', 'kafka-python', 'pika',
|
||||
'paho-mqtt', 'potsdb', 'prometheus_client', 'pyzmq',
|
||||
'statsd'],
|
||||
'folders': ['scandir'], # python_version<"3.5"
|
||||
'gpu': ['py3nvml'],
|
||||
'graph': ['pygal'],
|
||||
|
Loading…
Reference in New Issue
Block a user