monitor package

Submodules

monitor.config_manager module

class monitor.config_manager.ConfigManager(config_file=None)[source]

Bases: object

Class to handle all configuration items.

get_logger_settings()[source]

Get path to system log file.

Returns:List with 4 items - string path, logging level, integer maximum size of logfile and integer number of rotations kept.
get_websocket_uri()[source]

Get address for websocket server.

Returns:List with 2 items - string hostname and int port
get_zeromq_uri()[source]

Get address for zeromq server.

Returns:List with 2 items - string hostname and int port
monitor.config_manager.init_logger(logfile, level, max_size, rotations)[source]

Initialize new system logger for monitor. If arguments are invalid, empty logger will be created.

Parameters:
  • logfile – Path to file with log.
  • level – Log level as logging.<LEVEL>
  • max_size – Maximum size of log file.
  • rotations – Number of log files kept.
Returns:

Initialized logger.

monitor.main module

Script which runs the monitor - tool for resending messages from ZeroMQ to WebSockets.

monitor.main.main()[source]

Main function of monitor program.

Returns:Nothing

monitor.websocket_connections module

Classes and functions for websocket connections and message sending

class monitor.websocket_connections.ClientConnections(logger, loop)[source]

Bases: object

Container for managing connected websocket clients. Messages are passed as asyncio.Queue item values, so all methods must be called from the same thread (event loop) as main websocket connection handler. Thus this class is not thread safe.

add_client(id)[source]

Register new client which wants to receive messages to identifier ‘id’. If there are any such messages, they are sent immediately. There can be more subscribers per stream.

Parameters:id – Identifier of required stream of messages
Returns:Returns new asyncio.Queue on which can be wait for by ‘yield from’ command.
remove_all_clients()[source]

Remove all registered clients. This method could be called on app shutdown or when incoming connection is lost.

Returns:Nothing
remove_channel(id)[source]

Remove all clients listening on ‘id’ channel. This means removing all associated queues and received messages. If no such channel exists, nothing is done. This method is called 5 minutes after last message of each channel.

Parameters:id – Identifier of required stream of messages
Returns:Nothing
remove_client(id, queue)[source]

Remove client listening on ‘id’ message stream with queue ‘queue’. This means removing associated queue and deleting the entry from internal dictionary. If no such client exists, nothing is done.

Parameters:
  • id – Identifier of required stream of messages
  • queue – Queue associated with client to be removed
Returns:

Nothing

send_message(id, message)[source]

Send ‘message’ to client listening on stream with ‘id’. If ‘id’ is not known, the message is saved for latter use. Messages for connected clients are put into queues, so no message will get lost.

Parameters:
  • id – Identifier of required stream of messages
  • message – String containing text to be sent
Returns:

Nothing

class monitor.websocket_connections.WebsocketServer(websock_uri, connections, loop, logger)[source]

Bases: threading.Thread

Websocket server, which handles all connection asynchronously in one (separate) thread. To start server, call start() method, for waiting to finish, there is join() method (as in threading.Thread class).

connection_handler(websocket, path)[source]

Internal asyncio.coroutine function for handling one websocket request.

Parameters:
  • websocket – Socket with request
  • path – Requested path of socket (not used)
Returns:

Returns when socket is closed or poison pill is found in message queue from ClientConnections.

run()[source]

Function to start websocket server, which handle and serve all connections.

Returns:This function returns when given message loop is stopped and returns nothing.

monitor.zeromq_connection module

Handle zeromq socket.

class monitor.zeromq_connection.ServerConnection(address, port, logger)[source]

Bases: object

Class responsible for creating zeromq socket (server) and receiving messages from connected clients. The message should be text with format <ID>,<MESSAGE>, where text <MESSAGE> will be sent to websocket client subscribed to channel <ID>.

start(message_callback)[source]

Start receiving messages from underlying zeromq socket.

Parameters:message_callback – Function to be called when new messages arrived. This function should not block for long. Required are two parameters, first is id of stream and second is text of the message. Both are strings.
Returns:True if exited normally (by “exit” message with ID 0), False if socket error occurred.

Module contents