mozilla

HekaClient API

class heka.client.HekaClient(stream, logger, severity=6, disabled_timers=None, filters=None, encoder='heka.encoders.ProtobufEncoder', hmc=None)[source]

Client class encapsulating heka API, and providing storage for default values for various heka call settings.

add_method(method, override=False)[source]

Add a custom method to the HekaClient instance.

Parameters:
  • method – Callable that will be used as the method.
  • override – Set this to the method name you want to override. False indicates no override will occur.
critical(msg, *args, **kwargs)[source]

Log a CRITICAL level message

debug(msg, *args, **kwargs)[source]

Log a DEBUG level message

env_version = '0.8'
error(msg, *args, **kwargs)[source]

Log an ERROR level message

exception(msg, exc_info=True, *args, **kwargs)[source]

Log an ALERT level message

gauge(name, value, logger=None, severity=None, fields=None, rate=1.0)[source]

Sends an ‘current gauge measurement’ message.

Parameters:
  • name – String label for the gauge.
  • value – Number current absolute value of the gauge.
  • logger – String token identifying the message generator.
  • severity – Numerical code (0-7) for msg severity, per RFC 5424.
  • fields – Arbitrary key/value pairs for add’l metadata.
heka(type, logger=None, severity=None, payload='', fields=None, timestamp=None)[source]

Create a single message and pass it to the sender for delivery.

Parameters:
  • type – String token identifying the type of message payload.
  • logger – String token identifying the message generator.
  • severity – Numerical code (0-7) for msg severity, per RFC 5424.
  • payload – Actual message contents.
  • fields – Arbitrary key/value pairs for add’l metadata.
  • timestamp – Custom timestamp for the message. If no timestamp is given, then current time will be used.
incr(name, count=1, logger=None, severity=None, fields=None, rate=1.0)[source]

Sends an ‘increment counter’ message.

Parameters:
  • name – String label for the counter.
  • count – Integer amount by which to increment the counter.
  • logger – String token identifying the message generator.
  • severity – Numerical code (0-7) for msg severity, per RFC 5424.
  • fields – Arbitrary key/value pairs for add’l metadata.
info(msg, *args, **kwargs)[source]

Log an INFO level message

is_active
send_message(msg)[source]
setup(stream, encoder, hmc, logger='', severity=6, disabled_timers=None, filters=None)[source]

Setup the HekaClient

Parameters:
  • logger – Default logger value for all sent messages.
  • severity – Default severity value for all sent messages.
  • disabled_timers – Sequence of string tokens identifying timers that should be deactivated.
  • filters – A sequence of filter callables.
timer(name, logger=None, severity=None, fields=None, rate=1.0)[source]

Return a timer object that can be used as a context manager or a decorator, generating a heka ‘timer’ message upon exit.

Parameters:
  • name – Required string label for the timer.
  • logger – String token identifying the message generator.
  • severity – Numerical code (0-7) for msg severity, per RFC 5424.
  • fields – Arbitrary key/value pairs for add’l metadata.
  • rate – Sample rate, btn 0 & 1, inclusive (i.e. .5 = 50%). Sample rate is enforced in this method, i.e. if a sample rate is used then some percentage of the timers will do nothing.
timer_send(name, elapsed, logger=None, severity=None, fields=None, rate=1.0)[source]

Converts timing data into a heka message for delivery.

Parameters:
  • name – Required string label for the timer.
  • elapsed – Elapsed time of the timed event, in ms.
  • logger – String token identifying the message generator.
  • severity – Numerical code (0-7) for msg severity, per RFC 5424.
  • fields – Arbitrary key/value pairs for add’l metadata.
  • rate – Sample rate, btn 0 & 1, inclusive (i.e. .5 = 50%). Sample rate is NOT enforced in this method, i.e. all messages will be sent through to heka, sample rate is purely informational at this point.
warn(msg, *args, **kwargs)[source]

Log a WARN level message

class heka.client.SEVERITY[source]

Put a namespace around RFC 3164 syslog messages

ALERT = 1
CRITICAL = 2
DEBUG = 7
EMERGENCY = 0
ERROR = 3
INFORMATIONAL = 6
NOTICE = 5
WARNING = 4