Esempio n. 1
0
    def post(self):
        """create a new metric"""
        
        log = logging.getLogger('tornado.access')
        log.debug("%s %s %s" ,self.request.method, self.request.uri, self.request.arguments)

        if 'batch' in self.request.arguments:
            metrics = json.loads(self.get_argument('metrics'))
            MetricsModel.batch_add(metrics)
        else:
            data = dict()
            for arg in ['metric_id', 'ts', 'value']:
                data[arg] = self.get_argument(arg)

            # TODO: Return appropriate error codes on failure
            MetricsModel.add(data)
        
        self.set_status(200)
Esempio n. 2
0
    def get(self):
        """search for metrics"""
        log = logging.getLogger('tornado.access')
        log.debug("%s %s %s" ,self.request.method, self.request.uri, self.request.arguments)

        query = dict()
        for arg in ['metric', 'to', 'from', 'aggregation']:
            query[arg] = self.get_argument(arg)

        # TODO: Return appropriate error codes on failure
        self.write(MetricsModel.search(query))
        self.set_status(200)