pyignite.monitoring module

Tools to monitor client’s events.

For example, a simple query logger might be implemented like this:

import logging

from pyignite import monitoring

class QueryLogger(monitoring.QueryEventListener):

    def on_query_start(self, event):
        logging.info(f"Query {event.op_name} with query id "
                     f"{event.query_id} started on server "
                     f"{event.host}:{event.port}")

    def on_query_fail(self, event):
        logging.info(f"Query {event.op_name} with query id "
                     f"{event.query_id} on server "
                     f"{event.host}:{event.port} "
                     f"failed in {event.duration}ms "
                     f"with error {event.error_msg}")

    def on_query_success(self, event):
        logging.info(f"Query {event.op_name} with query id "
                     f"{event.query_id} on server "                          f"{event.host}:{event.port} "                          f"succeeded in {event.duration}ms")

ConnectionEventListener is also available.

Event listeners can be registered by passing parameter to Client or AioClient constructor:

client = Client(event_listeners=[QueryLogger()])
with client.connect('127.0.0.1', 10800):
    ....

Note

Events are delivered synchronously. Application threads block waiting for event handlers. Care must be taken to ensure that your event handlers are efficient enough to not adversely affect overall application performance.

Note

Debug logging is also available, standard logging is used. Just set DEBUG level to pyignite logger.

class pyignite.monitoring.HandshakeStartEvent(host, port, protocol_context=None, **kwargs)

Published when a handshake started.

Variables
  • host – Address of the node to connect,

  • port – Port number of the node to connect,

  • protocol_context – Client’s protocol context.

__init__(host, port, protocol_context=None, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.HandshakeFailedEvent(host, port, protocol_context=None, err=None, **kwargs)

Published when a handshake failed.

Variables
  • host – Address of the node to connect,

  • port – Port number of the node to connect,

  • protocol_context – Client’s protocol context,

  • error_msg – Error message.

__init__(host, port, protocol_context=None, err=None, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.AuthenticationFailedEvent(host, port, protocol_context=None, err=None, **kwargs)

Published when an authentication is failed.

Variables
  • host – Address of the node to connect,

  • port – Port number of the node to connect,

  • protocol_context – Client protocol context,

  • error_msg – Error message.

class pyignite.monitoring.HandshakeSuccessEvent(host, port, protocol_context, node_uuid, **kwargs)

Published when a handshake succeeded.

Variables
  • host – Address of the node to connect,

  • port – Port number of the node to connect,

  • protocol_context – Client’s protocol context,

  • node_uuid – Node’s uuid, string.

__init__(host, port, protocol_context, node_uuid, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.ConnectionClosedEvent(host, port, node_uuid, **kwargs)

Published when a connection to the node is expectedly closed.

Variables
  • host – Address of node to connect,

  • port – Port number of node to connect,

  • node_uuid – Node uuid, string.

__init__(host, port, node_uuid, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.ConnectionLostEvent(host, port, node_uuid, err, **kwargs)

Published when a connection to the node is lost.

Variables
  • host – Address of the node to connect,

  • port – Port number of the node to connect,

  • node_uuid – Node’s uuid, string,

  • error_msg – Error message.

__init__(host, port, node_uuid, err, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.ConnectionEventListener

Base class for connection event listeners.

on_handshake_start(event: pyignite.monitoring.HandshakeStartEvent)

Handle handshake start event.

Parameters

event – Instance of HandshakeStartEvent.

on_handshake_success(event: pyignite.monitoring.HandshakeSuccessEvent)

Handle handshake success event.

Parameters

event – Instance of HandshakeSuccessEvent.

on_handshake_fail(event: pyignite.monitoring.HandshakeFailedEvent)

Handle handshake failed event.

Parameters

event – Instance of HandshakeFailedEvent.

on_authentication_fail(event: pyignite.monitoring.AuthenticationFailedEvent)

Handle authentication failed event.

Parameters

event – Instance of AuthenticationFailedEvent.

on_connection_closed(event: pyignite.monitoring.ConnectionClosedEvent)

Handle connection closed event.

Parameters

event – Instance of ConnectionClosedEvent.

on_connection_lost(event: pyignite.monitoring.ConnectionLostEvent)

Handle connection lost event.

Parameters

event – Instance of ConnectionLostEvent.

class pyignite.monitoring.QueryStartEvent(host, port, node_uuid, query_id, op_code, op_name, **kwargs)

Published when a client’s query started.

Variables
  • host – Address of the node on which the query is executed,

  • port – Port number of the node on which the query is executed,

  • node_uuid – Node’s uuid, string,

  • query_id – Query’s id,

  • op_code – Operation’s id,

  • op_name – Operation’s name.

class pyignite.monitoring.QuerySuccessEvent(host, port, node_uuid, query_id, op_code, op_name, duration, **kwargs)

Published when a client’s query finished successfully.

Variables
  • host – Address of the node on which the query is executed,

  • port – Port number of the node on which the query is executed,

  • node_uuid – Node’s uuid, string,

  • query_id – Query’s id,

  • op_code – Operation’s id,

  • op_name – Operation’s name,

  • duration – Query’s duration in milliseconds.

__init__(host, port, node_uuid, query_id, op_code, op_name, duration, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.QueryFailEvent(host, port, node_uuid, query_id, op_code, op_name, duration, err, **kwargs)

Published when a client’s query failed.

Variables
  • host – Address of the node on which the query is executed,

  • port – Port number of the node on which the query is executed,

  • node_uuid – Node’s uuid, string,

  • query_id – Query’s id,

  • op_code – Operation’s id,

  • op_name – Operation’s name,

  • duration – Query’s duration in milliseconds,

  • error_msg – Error message.

__init__(host, port, node_uuid, query_id, op_code, op_name, duration, err, **kwargs)

This class is not supposed to be constructed by user.

class pyignite.monitoring.QueryEventListener

Base class for query event listeners.

on_query_start(event: pyignite.monitoring.QueryStartEvent)

Handle query start event.

Parameters

event – Instance of QueryStartEvent.

on_query_success(event: pyignite.monitoring.QuerySuccessEvent)

Handle query success event.

Parameters

event – Instance of QuerySuccessEvent.

on_query_fail(event: pyignite.monitoring.QueryFailEvent)

Handle query fail event.

Parameters

event – Instance of QueryFailEvent.