Example #1
0
    def __init__(self, connection, name, sample_rate=1):
        """Construct a metric that reports samples to the supplied
        C{connection}.

        @param connection: The connection endpoint representing
            the StatsD server.
        @param name: Indicates what is being instrumented.
        @param sample_rate: Restrict the number of samples sent
            to the StatsD server based on the supplied C{sample_rate}.
        """
        Metric.__init__(self, connection, name, sample_rate=sample_rate)
    def __init__(self, connection, name, sample_rate=1):
        """Construct a metric that reports samples to the supplied
        C{connection}.

        @param connection: The connection endpoint representing
            the StatsD server.
        @param name: Indicates what is being instrumented.
        @param sample_rate: Restrict the number of samples sent
            to the StatsD server based on the supplied C{sample_rate}.
        """
        Metric.__init__(self, connection, name, sample_rate=sample_rate)
Example #3
0
 def test_hash_with_single_client(self):
     clients = [FakeClient("127.0.0.1", 10001)]
     client = ConsistentHashingClient(clients)
     bar = Metric(client, "bar")
     foo = Metric(client, "foo")
     dba = Metric(client, "dba")
     bar.send("1")
     foo.send("1")
     dba.send("1")
     self.assertEqual(clients[0].data, ["bar:1", "foo:1", "dba:1"])
Example #4
0
 def decrement(self, name, value=1, sample_rate=1, tags=None):
     """Report and decrease in name by count."""
     key, name = self.key_and_fqn(name, tags)
     if key not in self._metrics:
         metric = Metric(self.connection, name, sample_rate, tags)
         self._metrics[key] = metric
     self._metrics[key].send("%s|c" % -value)
Example #5
0
 def decrement(self, name, value=1, sample_rate=1):
     """Report and decrease in name by count."""
     name = self.fully_qualify_name(name)
     if not name in self._metrics:
         metric = Metric(self.connection,
                         name,
                         sample_rate)
         self._metrics[name] = metric
     self._metrics[name].send("%s|c" % -value)
Example #6
0
 def timing(self, name, duration=None, sample_rate=1, tags=None):
     """Report that this sample performed in duration seconds.
        Default duration is the actual elapsed time since
        the last call to this method or reset_timing()"""
     if duration is None:
         duration = self.calculate_duration()
     key, name = self.key_and_fqn(name, tags)
     if key not in self._metrics:
         metric = Metric(self.connection, name, sample_rate, tags)
         self._metrics[key] = metric
     self._metrics[key].send("%s|ms" % (duration * 1000))
Example #7
0
 def timing(self, name, duration=None, sample_rate=1):
     """Report that this sample performed in duration seconds.
        Default duration is the actual elapsed time since
        the last call to this method or reset_timing()"""
     if duration is None:
         duration = self.calculate_duration()
     name = self.fully_qualify_name(name)
     if not name in self._metrics:
         metric = Metric(self.connection,
                         name,
                         sample_rate)
         self._metrics[name] = metric
     self._metrics[name].send("%s|ms" % (duration * 1000))
 def test_hash_with_three_clients(self):
     clients = [
         FakeClient("127.0.0.1", 10001),
         FakeClient("127.0.0.1", 10002),
         FakeClient("127.0.0.1", 10003),
     ]
     client = ConsistentHashingClient(clients)
     bar = Metric(client, "bar")
     foo = Metric(client, "foo")
     dba = Metric(client, "dba")
     bar.send("1")
     foo.send("1")
     dba.send("1")
     self.assertEqual(clients[0].data, ["bar:1"])
     self.assertEqual(clients[1].data, ["foo:1"])
     self.assertEqual(clients[2].data, ["dba:1"])