Added Graphite integration - closes #96

This commit is contained in:
Fabio Manganiello 2020-01-06 15:24:52 +01:00
parent d73df1454e
commit e880f00498
6 changed files with 66 additions and 2 deletions

View file

@ -233,8 +233,9 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers',
'trello',
'telegram',
'telegram.ext',
'pyfirmata2'
'cups'
'pyfirmata2',
'cups',
'graphyte',
]
sys.path.insert(0, os.path.abspath('../..'))

View file

@ -0,0 +1,5 @@
``platypush.plugins.graphite``
==============================
.. automodule:: platypush.plugins.graphite
:members:

View file

@ -44,6 +44,7 @@ Plugins
platypush/plugins/gpio.sensor.mcp3008.rst
platypush/plugins/gpio.sensor.motion.pwm3901.rst
platypush/plugins/gpio.zeroborg.rst
platypush/plugins/graphite.rst
platypush/plugins/homeseer.rst
platypush/plugins/http.request.rst
platypush/plugins/http.request.ota.booking.rst
@ -84,6 +85,7 @@ Plugins
platypush/plugins/sound.rst
platypush/plugins/switch.rst
platypush/plugins/switch.switchbot.rst
platypush/plugins/switch.tplink.rst
platypush/plugins/switch.wemo.rst
platypush/plugins/tcp.rst
platypush/plugins/todoist.rst

View file

@ -0,0 +1,51 @@
from typing import Optional, Dict
from platypush.plugins import Plugin, action
class GraphitePlugin(Plugin):
"""
Plugin for sending data to a Graphite instance.
"""
def __init__(self, host: str = 'localhost', port: int = 2003, **kwargs):
"""
:param host: Default Graphite host (default: 'localhost').
:param port: Default Graphite port (default: 2003).
"""
super().__init__(**kwargs)
self.host = host
self.port = port
@action
def send(self,
metric: str,
value,
host: Optional[str] = None,
port: Optional[int] = None,
tags: Optional[Dict[str, str]] = None,
prefix: str = '',
protocol: str = 'tcp'):
"""
Send data to a Graphite instance.
:param metric: Metric name.
:param value: Value to be sent.
:param host: Graphite host (default: default configured ``host``).
:param port: Graphite port (default: default configured ``port``).
:param tags: Map of tags for the metric.
:param prefix: Metric prefix name (default: empty string).
:param protocol: Communication protocol - possible values: 'tcp', 'udp' (default: 'tcp').
"""
import graphyte
host = host or self.host
port = port or self.port
tags = tags or {}
protocol = protocol.lower()
graphyte.init(host, port=port, prefix=prefix, protocol=protocol)
graphyte.send(metric, value, tags=tags)
# vim:sw=4:ts=4:et:

View file

@ -214,3 +214,6 @@ croniter
# Support for CUPS printers management
# pycups
# Support for Graphite integration
# graphyte

View file

@ -271,5 +271,7 @@ setup(
'arduino': ['pyserial', 'pyfirmata2'],
# Support for CUPS printers management
'cups': ['pycups'],
# Support for Graphite integration
'graphite': ['graphyte'],
},
)