Commit 00023336 authored by Robin Obůrka's avatar Robin Obůrka

msgloop: Add monitoring to all basic boxes

parent 95b4e5cf
......@@ -11,6 +11,7 @@ from .network import SN
from .network import get_arg_parser
from .messages import encode_msg, parse_msg
from .exceptions import SetupError, UndefinedSocketError, InvalidMsgError
from .monitoring import Monitoring
class LoopHardFail(Exception):
......@@ -59,6 +60,11 @@ class SNBox():
# Data generated by setup function are placed into separate variable
# Final box shouldn't use "self" - we want to isolate its values
self.ctx = None
# Monitoring
self.socket_monitoring = self.get_socket("mon")
self.mon = Monitoring(box_name, self.socket_monitoring)
self.received_messages = self.mon.get_counter("msg_recv")
self.sent_messages = self.mon.get_counter("msg_sent")
# Core methods - Will be implemented in non-abstract boxes
def check_configuration(self):
......@@ -273,6 +279,7 @@ class SNPipelineBox(SNBox):
"""
msg = self.socket_recv.recv_multipart()
msg_type, payload = parse_msg(msg)
self.received_messages.count()
return self.process(msg_type, payload)
......@@ -288,6 +295,7 @@ class SNPipelineBox(SNBox):
msg_type, payload = result
msg_out = encode_msg(msg_type, payload)
self.socket_send.send_multipart(msg_out)
self.sent_messages.count()
except (ValueError, InvalidMsgError):
raise LoopFail("Generated broken output message. Possibly bug in box.")
......@@ -342,6 +350,7 @@ class SNGeneratorBox(SNBox):
msg_type, payload = result
msg_out = encode_msg(msg_type, payload)
self.socket_send.send_multipart(msg_out)
self.sent_messages.count()
except (ValueError, InvalidMsgError):
raise LoopFail("Generated broken output message. Possibly bug in box.")
......@@ -374,6 +383,7 @@ class SNTerminationBox(SNBox):
"""
msg = self.socket_recv.recv_multipart()
msg_type, payload = parse_msg(msg)
self.received_messages.count()
return self.process(msg_type, payload)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment