Esempio n. 1
0
    def post(self):
        """Read the message and forward it to the intake
            The message is expected to follow the format:

        """
        # read the message it should be a list of
        # monasca_agent.common.metrics.Measurements expressed as a dict
        msg = tornado.escape.json_decode(self.request.body)
        try:
            measurements = [metrics.Measurement(**m) for m in msg]
        except Exception:
            log.exception('Error parsing body of Agent Input')
            raise tornado.web.HTTPError(500)

        headers = self.request.headers

        if len(measurements) > 0:
            # Setup a transaction for this message
            tr = transaction.MetricTransaction(measurements, headers)
        else:
            raise tornado.web.HTTPError(500)

        self.write("Transaction: %s" % tr.get_id())
Esempio n. 2
0
    def _post_metrics(self):

        if len(self._metrics) > 0:
            transaction.MetricTransaction(
                self._metrics, headers={'Content-Type': 'application/json'})
            self._metrics = {}