Ejemplo n.º 1
0
 def test_parse_gauge_metric_from_request(self):
     self.assertEqual(
         Gauge("cpu_usage", 45.3),
         parse_metric_from_request("cpu_usage:45.3|g")
     )
     self.assertEqual(
         Gauge("mem usage?", 10240, 1),
         parse_metric_from_request("mem usage?:10240|g|@1")
     )
     self.assertEqual(
         Gauge("weird.gauge.with.rate", 23.3, 0.5),
         parse_metric_from_request("weird.gauge.with.rate:23.3|g|@0.5")
     )
Ejemplo n.º 2
0
 def test_parse_set_metric_from_request(self):
     self.assertEqual(
         Set("host", '127.0.0.1'),
         parse_metric_from_request("host:127.0.0.1|s")
     )
     self.assertEqual(
         Set("user id?", '12345', 1),
         parse_metric_from_request("user id?:12345|s|@1")
     )
     self.assertEqual(
         Set("weird.set.with.rate", '25.7', 0.5),
         parse_metric_from_request("weird.set.with.rate:25.7|s|@0.5")
     )
Ejemplo n.º 3
0
 def test_parse_set_metric_from_request(self):
     self.assertEqual(
         Set("host", '127.0.0.1'),
         parse_metric_from_request("host:127.0.0.1|s")
     )
     self.assertEqual(
         Set("user id?", '12345', 1),
         parse_metric_from_request("user id?:12345|s|@1")
     )
     self.assertEqual(
         Set("weird.set.with.rate", '25.7', 0.5),
         parse_metric_from_request("weird.set.with.rate:25.7|s|@0.5")
     )
Ejemplo n.º 4
0
 def test_parse_gauge_metric_from_request(self):
     self.assertEqual(
         Gauge("cpu_usage", 45.3),
         parse_metric_from_request("cpu_usage:45.3|g")
     )
     self.assertEqual(
         Gauge("mem usage?", 10240, 1),
         parse_metric_from_request("mem usage?:10240|g|@1")
     )
     self.assertEqual(
         Gauge("weird.gauge.with.rate", 23.3, 0.5),
         parse_metric_from_request("weird.gauge.with.rate:23.3|g|@0.5")
     )
Ejemplo n.º 5
0
 def test_parse_gauge_delta_metric_from_request(self):
     self.assertEqual(
         GaugeDelta("cpu_usage", 6),
         parse_metric_from_request("cpu_usage:+6|g")
     )
     self.assertEqual(
         GaugeDelta("mem usage?", -2048, 1),
         parse_metric_from_request("mem usage?:-2048|g|@1")
     )
     self.assertEqual(
         GaugeDelta("weird.gauge.delta.with.rate", 23.3, 0.5),
         parse_metric_from_request(
             "weird.gauge.delta.with.rate:+23.3|g|@0.5")
     )
Ejemplo n.º 6
0
 def test_parse_gauge_delta_metric_from_request(self):
     self.assertEqual(
         GaugeDelta("cpu_usage", 6),
         parse_metric_from_request("cpu_usage:+6|g")
     )
     self.assertEqual(
         GaugeDelta("mem usage?", -2048, 1),
         parse_metric_from_request("mem usage?:-2048|g|@1")
     )
     self.assertEqual(
         GaugeDelta("weird.gauge.delta.with.rate", 23.3, 0.5),
         parse_metric_from_request(
             "weird.gauge.delta.with.rate:+23.3|g|@0.5")
     )
Ejemplo n.º 7
0
 def test_parse_timer_metric_from_request(self):
     self.assertEqual(
         Timer("exact", 1),
         parse_metric_from_request("exact:1|ms")
     )
     self.assertEqual(
         Timer("db query?", 2.4),
         parse_metric_from_request("db query?:2.4|ms")
     )
     self.assertEqual(
         Timer("db.query.with.rate", 10, 1),
         parse_metric_from_request("db.query.with.rate:10|ms|@1")
     )
     self.assertEqual(
         Timer("db_query_float_rate", 23.5, 0.5),
         parse_metric_from_request("db_query_float_rate:23.5|ms|@0.5")
     )
Ejemplo n.º 8
0
 def test_parse_counter_metric_from_request(self):
     self.assertEqual(
         Counter("sales", 10),
         parse_metric_from_request("sales:10|c")
     )
     self.assertEqual(
         Counter("with rate?", 0, 1),
         parse_metric_from_request("with rate?:0|c|@1")
     )
     self.assertEqual(
         Counter("accounts.active.disable", 4567, 1.0),
         parse_metric_from_request("accounts.active.disable:4567|c|@1.0")
     )
     self.assertEqual(
         Counter("float_rate", 345, 0.2),
         parse_metric_from_request("float_rate:345|c|@0.2")
     )
Ejemplo n.º 9
0
 def test_parse_counter_metric_from_request(self):
     self.assertEqual(
         Counter("sales", 10),
         parse_metric_from_request("sales:10|c")
     )
     self.assertEqual(
         Counter("with rate?", 0, 1),
         parse_metric_from_request("with rate?:0|c|@1")
     )
     self.assertEqual(
         Counter("accounts.active.disable", 4567, 1.0),
         parse_metric_from_request("accounts.active.disable:4567|c|@1.0")
     )
     self.assertEqual(
         Counter("float_rate", 345, 0.2),
         parse_metric_from_request("float_rate:345|c|@0.2")
     )
Ejemplo n.º 10
0
 def test_parse_timer_metric_from_request(self):
     self.assertEqual(
         Timer("exact", 1),
         parse_metric_from_request("exact:1|ms")
     )
     self.assertEqual(
         Timer("db query?", 2.4),
         parse_metric_from_request("db query?:2.4|ms")
     )
     self.assertEqual(
         Timer("db.query.with.rate", 10, 1),
         parse_metric_from_request("db.query.with.rate:10|ms|@1")
     )
     self.assertEqual(
         Timer("db_query_float_rate", 23.5, 0.5),
         parse_metric_from_request("db_query_float_rate:23.5|ms|@0.5")
     )
Ejemplo n.º 11
0
 def _process_request(self, request):
     request = str(request)
     self._log_debug("processing metrics: {}".format(request))
     lines = [line.strip() for line in request.split("\n") if line.strip()]
     should_stop = self._should_stop_processing.is_set
     for line in lines:
         if should_stop():
             break
         try:
             metric = parse_metric_from_request(line)
         except ValueError as parse_error:
             self._log_error(
                 "failed to parse statsd metrics from '{}': {}".format(
                     line, parse_error))
             continue
         self._shelf.add(metric)
Ejemplo n.º 12
0
 def _process_request(self, request):
     # type: (str) -> None
     request = str(request)
     self._log_debug("processing metrics: {}".format(request))
     lines = [line.strip() for line in request.split("\n") if line.strip()]
     should_stop = self._should_stop_processing.is_set
     for line in lines:
         if should_stop():
             break
         try:
             metric = parse_metric_from_request(line)
         except ValueError as parse_error:
             self._log_error(
                 "failed to parse statsd metrics from '{}': {}".format(
                     line, parse_error))
             continue
         self._shelf.add(metric)