def backIntoCache(metricList):
  for (metric, datapoints) in metricList:
    for point in datapoints:
      try:
        MetricCache.store(metric, point)
      except:
        datapoints.append(point)
  log.msg("Failed to publish to RabbitMQ. Pushed the metrics back to cache")
Ejemplo n.º 2
0
    def test_write_strategy_sorted(self):
        """Create a metric cache, insert metrics, ensure sorted writes"""
        self.assertEqual("sorted", MetricCache.method)
        now = time.time()
        datapoint1 = (now - 10, float(1))
        datapoint2 = (now, float(2))
        MetricCache.store("d.e.f", datapoint1)
        MetricCache.store("a.b.c", datapoint1)
        MetricCache.store("a.b.c", datapoint2)

        (m, d) = MetricCache.pop()
        self.assertEqual(("a.b.c", deque([datapoint1, datapoint2])), (m, d))
        (m, d) = MetricCache.pop()
        self.assertEqual(("d.e.f", deque([datapoint1])), (m, d))

        self.assertEqual(0, MetricCache.size)
Ejemplo n.º 3
0
def store(metric, value):
  fullMetric = 'carbon.agents.%s.%s' % (HOSTNAME, metric)
  datapoint = (time.time(), value)
  MetricCache.store(fullMetric, datapoint)