Metrics Implementations

ffwd

Gordon ships with a simple ffwd metrics implementation, which can be enabled via configuration. This module contains the SimpleFfwdRelay, and all required classes that it uses to send messsages to the ffwd daemon via UDP.

The SimpleFfwdRelay requires no configuration, but can be customized. The defaults that may be overridden are shown below.

[ffwd]
# to identify the service creating metrics
key = 'gordon-service'

# the address of the ffwd daemon (see: UDPClient)
ip = "127.0.0.9"
port = 19000

# a scaling factor for timing (see: FfwdTimer)
time_unit = 1E9
class gordon.metrics.ffwd.SimpleFfwdRelay(config)[source]

Metrics relay which sends to FFWD immediately.

The relay does no client-side aggregation and metrics are emitted immediately. The relay uses a combination of the key and attributes fields to semantically identify metrics in ffwd.

Parameters:config (dict) – Configuration with optional keys described above.
cleanup()[source]

Not used.

incr(metric_name, value=1, context=None, **kwargs)[source]

Increase a metric by 1 or a given amount.

Parameters:
  • metric_name (str) – Identifier of the metric.
  • value (int) – (optional) Value with which to increase the metric (default: 1).
  • context (dict) – (optional) Additional key-value pairs which further describe the metric, for example: {‘remote-host’: ‘1.2.3.4’}
set(metric_name, value, context=None, **kwargs)[source]

Set a metric to a given value.

Parameters:
  • metric_name (str) – Identifier of the metric.
  • value (number) – The value of the metric.
  • context (dict) – (optional) Additional key-value pairs which further describe the metric, for example: {‘app-version’: ‘1.5.3’}
timer(metric_name, context=None, **kwargs)[source]

Create a FfwdTimer.

Parameters:
  • metric_name (str) – Identifier of the metric.
  • context (dict) – (optional) Additional key-value pairs which further describe the metric, for example: {‘unit’: ‘seconds’}
class gordon.metrics.ffwd.FfwdTimer(metric, udp_client, time_unit=None)[source]

Timer which sends UDP messages to FFWD on completion.

Parameters:
  • metric (dict) – Dict representation of the metric to send.
  • udp_client (UDPClient) – A metric sending client.
  • time_unit (number) – (optional) Scale time unit for use with time.perf_counter(), for example: 1E9 to send nanoseconds.
start()[source]

Start timer.

stop()[source]

Stop timer.

class gordon.metrics.ffwd.UDPClient(ip=None, port=None, loop=None)[source]

Client for sending UDP datagrams.

Parameters:
  • ip (str) – (optional) Destination IP address (default: 127.0.0.1).
  • port (int) – (optional) Destination port (default: 9000).
  • loop (asyncio.AbstractEventLoop impl) – (optional) Event loop.
send(metric)[source]

Transform metric to JSON bytestring and send to server.

Parameters:metric (dict) – Complete metric to send as JSON.
class gordon.metrics.ffwd.UDPClientProtocol(message)[source]

Protocol for sending one-off messages via UDP.

Parameters:message (bytes) – Message for ffwd agent.
connection_made(transport)[source]

Create connection, use to send message and close.

Parameters:transport (asyncio.DatagramTransport) – Transport used for sending.