Ejemplo n.º 1
0
    def submit_influxdb_measurement(self):
        """Submit a measurement for a message to InfluxDB"""
        measurement = influxdb.Measurement(*self.influxdb)
        measurement.set_timestamp(time.time())
        for key, value in self.measurement.counters.items():
            measurement.set_field(key, value)
        for key, value in self.measurement.tags.items():
            measurement.set_tag(key, value)
        for key, value in self.measurement.values.items():
            measurement.set_field(key, value)

        for key, values in self.measurement.durations.items():
            if len(values) == 1:
                measurement.set_field(key, values[0])
            elif len(values) > 1:
                measurement.set_field('{}-average'.format(key),
                                      sum(values) / len(values))
                measurement.set_field('{}-max'.format(key), max(values))
                measurement.set_field('{}-min'.format(key), min(values))
                measurement.set_field('{}-median'.format(key),
                                      utils.percentile(values, 50))
                measurement.set_field('{}-95th'.format(key),
                                      utils.percentile(values, 95))

        influxdb.add_measurement(measurement)
        LOGGER.debug('InfluxDB Measurement: %r', measurement.marshall())
Ejemplo n.º 2
0
    def submit_influxdb_measurement(self):
        """Submit a measurement for a message to InfluxDB"""
        measurement = influxdb.Measurement(*self.influxdb)
        measurement.set_timestamp(time.time())
        for key, value in self.measurement.counters.items():
            measurement.set_field(key, value)
        for key, value in self.measurement.tags.items():
            measurement.set_tag(key, value)
        for key, value in self.measurement.values.items():
            measurement.set_field(key, value)

        for key, values in self.measurement.durations.items():
            if len(values) == 1:
                measurement.set_field(key, values[0])
            elif len(values) > 1:
                measurement.set_field('{}-average'.format(key),
                                      sum(values) / len(values))
                measurement.set_field('{}-max'.format(key), max(values))
                measurement.set_field('{}-min'.format(key), min(values))
                measurement.set_field('{}-median'.format(key),
                                      utils.percentile(values, 50))
                measurement.set_field('{}-95th'.format(key),
                                      utils.percentile(values, 95))

        influxdb.add_measurement(measurement)
        LOGGER.debug('InfluxDB Measurement: %r', measurement.marshall())
Ejemplo n.º 3
0
 def setup_batch():
     influxdb.set_max_batch_size(100)
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     for iteration in range(0, 1000):
         measurement = influxdb.Measurement(database, name)
         measurement.set_field('test', random.randint(1000, 2000))
         influxdb.add_measurement(measurement)
Ejemplo n.º 4
0
 def _record_dynamodb_execution(measurements):
     for row in measurements:
         measurement = influxdb.Measurement(INFLUXDB_DATABASE,
                                            INFLUXDB_MEASUREMENT)
         measurement.set_timestamp(row.timestamp)
         measurement.set_tag('action', row.action)
         measurement.set_tag('table', row.table)
         measurement.set_tag('attempt', row.attempt)
         if row.error:
             measurement.set_tag('error', row.error)
         measurement.set_field('duration', row.duration)
         influxdb.add_measurement(measurement)
Ejemplo n.º 5
0
 def submit_influxdb_measurement(self):
     """Submit a measurement for a message to InfluxDB"""
     measurement = influxdb.Measurement(*self.influxdb)
     measurement.set_timestamp(time.time())
     for key, value in self.measurement.counters.items():
         measurement.set_field(key, value)
     for key, value in self.measurement.tags.items():
         measurement.set_tag(key, value)
     for key, value in self.measurement.values.items():
         measurement.set_field(key, value)
     influxdb.add_measurement(measurement)
     LOGGER.debug('InfluxDB Measurement: %r', measurement.marshall())
Ejemplo n.º 6
0
 def test_timer(self):
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     test_value = random.randint(1000, 2000)
     measurement = influxdb.Measurement(database, name)
     measurement.set_field('test', test_value)
     with measurement.duration('duration-test'):
         future = gen.sleep(0.100)
         self.io_loop.add_future(future, self.stop)
         self.wait()
     influxdb.add_measurement(measurement)
     self.assertEqual(influxdb._pending_measurements(), 1)
     self.flush()
     value = self.get_measurement()
     self.assertAlmostEqual(float(value.fields['duration-test']), 0.1, 1)
Ejemplo n.º 7
0
    def test_measurement_was_sent(self):
        database = str(uuid.uuid4())
        name = str(uuid.uuid4())
        tag_value = str(uuid.uuid4())
        test_value = random.randint(1000, 2000)

        measurement = influxdb.Measurement(database, name)
        measurement.set_field('test', test_value)
        measurement.set_tag('test_tag', tag_value)

        influxdb.add_measurement(measurement)
        self.flush()
        result = self.get_measurement()
        self.assertEqual(result.db, database)
        self.assertEqual(result.name, name)
        self.assertEqual(result.fields['test'], test_value)
        self.assertEqual(result.tags['test_tag'], tag_value)
Ejemplo n.º 8
0
 def test_periodic_callback_while_already_processing(self):
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     test_value = random.randint(1000, 2000)
     measurement = influxdb.Measurement(database, name)
     measurement.set_field('test', test_value)
     influxdb.add_measurement(measurement)
     self.assertEqual(influxdb._pending_measurements(), 1)
     future = influxdb._on_timeout()
     self.assertIsNone(influxdb._on_timeout())
     self.assertEqual(influxdb._pending_measurements(), 0)
     self.io_loop.add_future(future, self.stop)
     self.wait()
     result = self.get_measurement()
     self.assertEqual(result.db, database)
     self.assertEqual(result.name, name)
     self.assertEqual(result.fields['test'], test_value)
Ejemplo n.º 9
0
    def test_that_authentication_header_was_sent(self):
        database = str(uuid.uuid4())
        name = str(uuid.uuid4())
        test_value = random.randint(1000, 2000)

        measurement = influxdb.Measurement(database, name)
        measurement.set_field('test', test_value)

        influxdb.add_measurement(measurement)
        self.flush()

        result = self.get_measurement()
        self.assertIn('Authorization', result.headers)
        scheme, value = result.headers['Authorization'].split(' ')
        self.assertEqual(scheme, 'Basic')
        temp = base64.b64decode(value.encode('utf-8'))
        values = temp.decode('utf-8').split(':')
        self.assertEqual(values[0], self.username)
        self.assertEqual(values[1], self.password)
Ejemplo n.º 10
0
 def test_with_http_error(self):
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     test_value = random.randint(1000, 2000)
     measurement = influxdb.Measurement(database, name)
     measurement.set_field('test', test_value)
     influxdb.add_measurement(measurement)
     self.assertEqual(influxdb._pending_measurements(), 1)
     with mock.patch('tornado.httpclient.AsyncHTTPClient.fetch') as fetch:
         future = concurrent.Future()
         fetch.return_value = future
         future.set_exception(httpclient.HTTPError(599, 'TestError'))
         self.flush()
     self.assertEqual(influxdb._pending_measurements(), 1)
     self.flush()
     result = self.get_measurement()
     self.assertEqual(result.db, database)
     self.assertEqual(result.name, name)
     self.assertEqual(result.fields['test'], test_value)
Ejemplo n.º 11
0
 def test_write_measurements_while_already_processing(self):
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     test_value = random.randint(1000, 2000)
     measurement = influxdb.Measurement(database, name)
     measurement.set_field('test', test_value)
     influxdb.add_measurement(measurement)
     self.assertEqual(influxdb._pending_measurements(), 1)
     future = influxdb._on_timeout()
     second_write = influxdb._write_measurements()
     self.assertTrue(concurrent.is_future(second_write))
     self.assertTrue(second_write.done())
     self.assertFalse(second_write.result())
     self.assertEqual(influxdb._pending_measurements(), 0)
     self.io_loop.add_future(future, self.stop)
     self.wait()
     result = self.get_measurement()
     self.assertEqual(result.db, database)
     self.assertEqual(result.name, name)
     self.assertEqual(result.fields['test'], test_value)
Ejemplo n.º 12
0
 def test_with_oserror(self):
     database = str(uuid.uuid4())
     name = str(uuid.uuid4())
     test_value = random.randint(1000, 2000)
     measurement = influxdb.Measurement(database, name)
     measurement.set_field('test', test_value)
     influxdb.add_measurement(measurement)
     influxdb._create_http_client()
     self.assertEqual(influxdb._pending_measurements(), 1)
     with mock.patch.object(influxdb._http_client, 'fetch') as fetch:
         future = concurrent.Future()
         future.set_exception(OSError())
         fetch.return_value = future
         influxdb._on_timeout()
     self.assertEqual(influxdb._pending_measurements(), 1)
     self.flush()
     result = self.get_measurement()
     self.assertEqual(result.db, database)
     self.assertEqual(result.name, name)
     self.assertEqual(result.fields['test'], test_value)
Ejemplo n.º 13
0
    def test_measurement_tags(self):
        database = str(uuid.uuid4())
        name = str(uuid.uuid4())
        tags = {
            'tag1': str(uuid.uuid4()),
            'tag2': str(uuid.uuid4())
        }
        test_value = random.randint(1000, 2000)

        measurement = influxdb.Measurement(database, name)
        measurement.set_field('test', test_value)
        measurement.set_tags(tags)

        influxdb.add_measurement(measurement)
        self.flush()
        result = self.get_measurement()
        self.assertEqual(result.db, database)
        self.assertEqual(result.name, name)
        self.assertEqual(result.fields['test'], test_value)
        for tag, value in tags.items():
            self.assertEqual(result.tags[tag], value)
Ejemplo n.º 14
0
 def test_missing_value_raises_value_error(self):
     with self.assertRaises(ValueError):
         database = str(uuid.uuid4())
         name = str(uuid.uuid4())
         measurement = influxdb.Measurement(database, name)
         influxdb.add_measurement(measurement)