def librato_metric_task(name, num, attributes=None, metric_type="gauge", **kwargs): connection = librato.connect(settings.APP_METRICS_LIBRATO_USER, settings.APP_METRICS_LIBRATO_TOKEN) if metric_type == "counter": metric = LibratoCounter(connection, name, attributes=attributes) else: metric = LibratoGauge(connection, name, attributes=attributes) metric.add(num, source=settings.APP_METRICS_LIBRATO_SOURCE)
def get(self, name, **query_props): resp = self._mexe("metrics/%s" % self.sanitize(name), method="GET", query_props=query_props) if resp['type'] == 'gauge': return Gauge.from_dict(self, resp) elif resp['type'] == 'counter': return Counter.from_dict(self, resp) else: raise Exception('The server sent me something that is not a Gauge nor a Counter.')
def create_counter(self, name, description=None, **query_props): """Create a new counter""" from librato.metrics import Counter if query_props is None: query_props = {} query_props['name'] = name if description: query_props['description'] = description resp = self._mexe("counters.json", method="POST", query_props=query_props) return Counter.from_dict(self, resp)
def get_counter(self, name): """Fetch a specific counter""" from librato.metrics import Counter resp = self._mexe("counters/%s.json" % name) return Counter.from_dict(self, resp)