Ejemplo n.º 1
0
    def __init__(self, clock):
        self.clock = clock

        self.last_received_command = self.clock.time_msec()
        self.last_sent_command = 0
        self.time_we_closed = None  # When we requested the connection be closed

        self.received_ping = False  # Have we reecived a ping from the other side

        self.state = ConnectionStates.CONNECTING

        self.name = "anon"  # The name sent by a client.
        self.conn_id = random_string(5)  # To dedupe in case of name clashes.

        # List of pending commands to send once we've established the connection
        self.pending_commands = []

        # The LoopingCall for sending pings.
        self._send_ping_loop = None

        self.inbound_commands_counter = CounterMetric(
            "inbound_commands",
            labels=["command"],
        )
        self.outbound_commands_counter = CounterMetric(
            "outbound_commands",
            labels=["command"],
        )
Ejemplo n.º 2
0
    def test_scalar(self):
        counter = CounterMetric("scalar")

        self.assertEquals(counter.render(), [
            'scalar 0',
        ])

        counter.inc()

        self.assertEquals(counter.render(), [
            'scalar 1',
        ])

        counter.inc_by(2)

        self.assertEquals(counter.render(), ['scalar 3'])
Ejemplo n.º 3
0
    def test_vector(self):
        counter = CounterMetric("vector", labels=["method"])

        # Empty counter doesn't yet know what values it has
        self.assertEquals(counter.render(), [])

        counter.inc("GET")

        self.assertEquals(counter.render(), [
            'vector{method="GET"} 1',
        ])

        counter.inc("GET")
        counter.inc("PUT")

        self.assertEquals(counter.render(), [
            'vector{method="GET"} 2',
            'vector{method="PUT"} 1',
        ])
Ejemplo n.º 4
0
    def test_vector(self):
        counter = CounterMetric("vector", labels=["method"])

        # Empty counter doesn't yet know what values it has
        self.assertEquals(counter.render(), [])

        counter.inc("GET")

        self.assertEquals(counter.render(), [
            'vector{method="GET"} 1',
        ])

        counter.inc("GET")
        counter.inc("PUT")

        self.assertEquals(counter.render(), [
            'vector{method="GET"} 2',
            'vector{method="PUT"} 1',
        ])

        # Check that passing too few values errors
        self.assertRaises(ValueError, counter.inc)