Beispiel #1
0
 def setUp(self):
     self.testdbname = 'cdrstats'
     self.influxdbcdr = InfluxdbHandlerCDR(settings.INFLUXDB_HOST,
                                           settings.INFLUXDB_PORT,
                                           settings.INFLUXDB_USER,
                                           settings.INFLUXDB_PASSWORD,
                                           self.testdbname)
     try:
         self.influxdbcdr.create_database()
     except InfluxDBClientError:
         print "create_database failed: DB already created..."
         pass
Beispiel #2
0
 def setUp(self):
     self.testdbname = "cdrstats"
     self.influxdbcdr = InfluxdbHandlerCDR(
         settings.INFLUXDB_HOST,
         settings.INFLUXDB_PORT,
         settings.INFLUXDB_USER,
         settings.INFLUXDB_PASSWORD,
         self.testdbname,
     )
     try:
         self.influxdbcdr.create_database()
     except InfluxDBClientError:
         print "create_database failed: DB already created..."
         pass
Beispiel #3
0
class TestInfluxdbHandlerCDR(TestCase):

    """Test TestInfluxdbHandlerCDR"""

    def setUp(self):
        self.testdbname = "cdrstats"
        self.influxdbcdr = InfluxdbHandlerCDR(
            settings.INFLUXDB_HOST,
            settings.INFLUXDB_PORT,
            settings.INFLUXDB_USER,
            settings.INFLUXDB_PASSWORD,
            self.testdbname,
        )
        try:
            self.influxdbcdr.create_database()
        except InfluxDBClientError:
            print "create_database failed: DB already created..."
            pass

    def test_delete_series(self):
        self.influxdbcdr.delete_series()

    def test_add_points(self):
        self.influxdbcdr.set_columns(["time", "duration", "billsec", "country_id", "hangup_id", "switch_id", "user_id"])
        self.influxdbcdr.add_points([1413460800, 10, 8, 55, 16, 1, 1])
        self.influxdbcdr.add_points([1413460802, 25, 20, 55, 16, 1, 1])
        self.influxdbcdr.commit()

    def test_generate_points_lastdays(self):
        import datetime
        import random

        self.influxdbcdr.set_columns(["time", "duration", "billsec", "country_id", "hangup_id", "switch_id", "user_id"])

        nb_day = 3  # number of day to generate time series
        timeinterval_min = 10  # create an event every x minutes
        total_minutes = 1440 * nb_day
        total_records = int(total_minutes / timeinterval_min)
        now = datetime.datetime.today()

        # generate data for 2 switches
        for switch_id in range(1, 2):
            # loop on the totalrecords to create
            for i in range(0, total_records):
                past_date = now - datetime.timedelta(minutes=i * timeinterval_min)
                billsec = random.randint(10, 50)
                duration = billsec + random.randint(5, 10)
                country_id = 10 + random.randint(10, 40)
                hangup_id = 1 + random.randint(10, 16)
                user_id = 1
                # add points
                self.influxdbcdr.add_points(
                    [int(past_date.strftime("%s")), duration, billsec, country_id, hangup_id, switch_id, user_id]
                )

        self.influxdbcdr.commit()
        # assert False

    def test_query_cdr_last_two_week(self):
        result = self.influxdbcdr.query_column_aggr_time(column="duration", time_bucket="1h", past="15d", aggr="MEAN")
        self.assertEqual(len(result["points"]), 361)

    def test_query_country_aggr_time(self):

        result = self.influxdbcdr.query_country(past="1d")
        val = len(result["points"])
        result = {}
        self.assertEqual(val, 775)
Beispiel #4
0
class TestInfluxdbHandlerCDR(TestCase):
    """Test TestInfluxdbHandlerCDR"""
    def setUp(self):
        self.testdbname = 'cdrstats'
        self.influxdbcdr = InfluxdbHandlerCDR(settings.INFLUXDB_HOST,
                                              settings.INFLUXDB_PORT,
                                              settings.INFLUXDB_USER,
                                              settings.INFLUXDB_PASSWORD,
                                              self.testdbname)
        try:
            self.influxdbcdr.create_database()
        except InfluxDBClientError:
            print "create_database failed: DB already created..."
            pass

    def test_delete_series(self):
        self.influxdbcdr.delete_series()

    def test_add_points(self):
        self.influxdbcdr.set_columns([
            "time", "duration", "billsec", "country_id", "hangup_id",
            "switch_id", "user_id"
        ])
        self.influxdbcdr.add_points([1413460800, 10, 8, 55, 16, 1, 1])
        self.influxdbcdr.add_points([1413460802, 25, 20, 55, 16, 1, 1])
        self.influxdbcdr.commit()

    def test_generate_points_lastdays(self):
        import datetime
        import random

        self.influxdbcdr.set_columns([
            "time", "duration", "billsec", "country_id", "hangup_id",
            "switch_id", "user_id"
        ])

        nb_day = 3  # number of day to generate time series
        timeinterval_min = 10  # create an event every x minutes
        total_minutes = 1440 * nb_day
        total_records = int(total_minutes / timeinterval_min)
        now = datetime.datetime.today()

        # generate data for 2 switches
        for switch_id in range(1, 2):
            # loop on the totalrecords to create
            for i in range(0, total_records):
                past_date = now - datetime.timedelta(minutes=i *
                                                     timeinterval_min)
                billsec = random.randint(10, 50)
                duration = billsec + random.randint(5, 10)
                country_id = 10 + random.randint(10, 40)
                hangup_id = 1 + random.randint(10, 16)
                user_id = 1
                # add points
                self.influxdbcdr.add_points([
                    int(past_date.strftime('%s')), duration, billsec,
                    country_id, hangup_id, switch_id, user_id
                ])

        self.influxdbcdr.commit()
        # assert False

    def test_query_cdr_last_two_week(self):
        result = self.influxdbcdr.query_column_aggr_time(column='duration',
                                                         time_bucket='1h',
                                                         past='15d',
                                                         aggr='MEAN')
        self.assertEqual(len(result['points']), 361)

    def test_query_country_aggr_time(self):

        result = self.influxdbcdr.query_country(past='1d')
        val = len(result['points'])
        result = {}
        self.assertEqual(val, 775)