Sending output to external processes

General interface

Sending a message to bunch of output sockets

Output sockets are only expected to implement send() and flush() methods.

  • send(message) will be called with a dictionary representing a message for every message to send (message serializes clearly to JSON)
  • flush() will be called in regular intervals, to give output sockets the chance to repair connection and send pending messages

Connectivity problems are not handled at Writer level. It is assumed that the socket spools messages in case of errors.

Example implementation of output socket that ignores all the messages:

class NullOutput:
    def send(self, message):
        pass
    def flush(self):
        pass
class seismometer.output.Writer

Write a message to all added output sockets at once.

add(output)
Parameters:output – output socket to add

Add output socket to the list.

Spoolers for data that needs to be sent in case of network connectivity problems.

class seismometer.spool.MemorySpooler(max=20971520)

Spooler that keeps data in memory.

Parameters:max – maximum number of bytes to keep in queue (defaults to 20M)
drop_one()

Drop the oldest line from spool.

peek()

Retrieve the oldest line from spool. The line will not be removed from spool.

spool(line)
Parameters:line – line to spool
Returns:number of messages dropped to keep the queue under its limit

Spool single line. If spool limit was set, oldest entries will be dropped.

Specific output modules

STDOUT message writer

class seismometer.output.stdout.STDOUT

Sender printing message to STDOUT.

Network output sockets

class seismometer.output.inet.TCP(host, port, spooler=None)

Sender passing message to another messenger (or anything accepting raw JSON lines through TCP).

Parameters:
  • host – address to send data to
  • port – address to send data to
  • spooler – spooler object
class seismometer.output.inet.SSL(host, port, ca_file=None, spooler=None)

Sender passing message to an SSL-enabled service that accepts raw JSON lines.

Parameters:
  • host – address to send data to
  • port – address to send data to
  • ca_file – file with CA certificates to verify server cert
  • spooler – spooler object
class seismometer.output.inet.UDP(host, port)

Sender passing message to another messenger (or anything accepting raw JSON lines through UDP).

Parameters:
  • host – address to send data to
  • port – address to send data to

UNIX domain socket writer

class seismometer.output.unix.UNIX(path, spooler=None)

Sender passing message to another messenger through UNIX sockets.

Parameters:
  • path – socket path to send data to
  • spooler – spooler object