コード例 #1
0
ファイル: perf_db_test.py プロジェクト: miracvbasaran/SPARTA
 def test_insert_cpu(self):
     '''unit test for insert_network
     
     Insert a few values and make sure they can be retrieved'''
     hosts = ["client", "client", "server"]
     identifiers = ["cpu1", "cpu2", "cpu1"]
     times = [
              time.time(),
              time.time() + 15.347,
              time.time() + 53.421
              ] 
     user_pcts = [23.7, 32.4, 77.8]
     sys_pcts = [10.2, 23.2, 8.3]
     wait_pcts = [1.1, 0.0, 2.1]
     irq_pcts = [2.3, 4.3, 0.1]
     idle_pcts = [0.0, 0.5, 0.0]
     total_pcts = [33.9, 55.6, 86.1]
     
     expected_rows = []
     con = create_perf_db(":memory:")
     for i in range(len(hosts)):
         insert_cpu(con, hosts[i], identifiers[i], times[i],  
                    user_pcts[i], sys_pcts[i], wait_pcts[i], irq_pcts[i],
                    idle_pcts[i], total_pcts[i], commit=False)
         expected_rows.append((hosts[i], identifiers[i], 
                    epoch_to_sql(times[i]), user_pcts[i], sys_pcts[i], 
                    wait_pcts[i], irq_pcts[i], idle_pcts[i], total_pcts[i]))
     con.commit()
     cur = con.cursor()
     query = "SELECT host, cpu_identifier, time, user_pct, sys_pct, wait_pct, irq_pct, idle_pct, total_pct from Cpu;"
     cur.execute(query)
     results = cur.fetchall()
     self.assertEqual(len(expected_rows), len(results))
     for row in expected_rows:
         self.assertIn(row, results)
コード例 #2
0
ファイル: perf_db_test.py プロジェクト: miracvbasaran/SPARTA
 def test_insert_ram(self):
     '''unit test for insert_ram
     
     Insert a few values and make sure they can be retrieved'''
     
     hosts = ["client", "thirdparty", "thirdparty"]
     times = [
              time.time(),
              time.time() + 15.347,
              time.time() + 53.421
              ]
     used_kbs = [1024, 2047.0, 2046.3]
     free_kbs = [0.0, 1.0, 0.7]
     swap_totals = [4096.0, 8192.0, 8192.0]
     swap_useds = [1234.5, 2102.7, 4212.0]
     swap_frees = [2861.5, 6089.3, 3980.0]
     
     expected_rows = []
     con = create_perf_db(":memory:")
     for i in range(len(hosts)):
         insert_ram(con, hosts[i], times[i], used_kbs[i], 
                    free_kbs[i], swap_totals[i], swap_useds[i], 
                    swap_frees[i], commit=False)
         expected_rows.append((hosts[i], epoch_to_sql(times[i]), 
                    used_kbs[i], free_kbs[i], swap_totals[i], swap_useds[i],
                    swap_frees[i]))
     con.commit()
     cur = con.cursor()
     query = "SELECT host, time, used_kb, free_kb, swap_total, swap_used, swap_free from Ram;"
     cur.execute(query)
     results = cur.fetchall()
     self.assertEqual(len(expected_rows), len(results))
     for row in expected_rows:
         self.assertIn(row, results)
コード例 #3
0
ファイル: perf_db_test.py プロジェクト: miracvbasaran/SPARTA
 def test_insert_network(self):
     '''unit test for insert_network
     
     Insert a few values and make sure they can be retrieved'''
     times = [
              time.time(),
              time.time() + 15.347,
              time.time() + 53.421
              ] 
     directions = ["client_to_server", 
                   "server_to_client", "server_to_client"]
     payload_sizes = [500, 1024, 1460]
     protocols = ["IP/TCP", "IP/TCP", "IP/TCP"]
     
     con = create_perf_db(":memory:")
     expected_rows = []
     for i in range(len(times)):
         insert_network(con, times[i], directions[i], payload_sizes[i],
                         protocols[i], commit=False)
         expected_rows.append((epoch_to_sql(times[i]), directions[i], 
                               payload_sizes[i], protocols[i]))       
     con.commit()
     cur = con.cursor()
     query = "SELECT time, direction, payloadlength, protocol FROM Network;"
     cur.execute(query)
     results = cur.fetchall()
     self.assertEqual(len(expected_rows), len(results))
     for row in expected_rows:
         self.assertIn(row, results)
コード例 #4
0
ファイル: perf_db_test.py プロジェクト: miracvbasaran/SPARTA
 def test_insert_disk(self):
     '''unit test for insert_disk
     
     Insert a few vlues and make sure they can be retrieved'''
     hosts = ["thirdparty", "thirdparty", "server"]
     times = [
              time.time(),
              time.time() + 15.347,
              time.time() + 53.421
              ]        
     disk_names = ["/dev/sda", "/dev/sdb", "/dev/hda"]
     reads_per_secs = [5.3, 4.7, 6.8]
     reads_kbps = [48.6, 983.2, 43.7]
     writes_per_secs = [76.2, 53.4, 98.2]
     writes_kbps = [123.4, 321.5, 1023.7]
     
     expected_rows = []
     con = create_perf_db(":memory:")
     for i in range(len(hosts)):
         insert_disk(con, hosts[i], times[i], disk_names[i], 
                    reads_per_secs[i], reads_kbps[i], writes_per_secs[i], 
                    writes_kbps[i], commit=False)
         expected_rows.append((hosts[i], epoch_to_sql(times[i]), 
                    disk_names[i], reads_per_secs[i], reads_kbps[i], 
                    writes_per_secs[i], writes_kbps[i]))
     con.commit()
     cur = con.cursor()
     query = "SELECT host, time, disk_name, reads_per_sec, reads_kbps, writes_per_sec, writes_kbps from Disk;"
     cur.execute(query)
     results = cur.fetchall()
     self.assertEqual(len(expected_rows), len(results))
     for row in expected_rows:
         self.assertIn(row, results)
コード例 #5
0
ファイル: perf_db_test.py プロジェクト: miracvbasaran/SPARTA
 def test_create_perf_db(self):
     '''unit test for create_perf_db
     
     Ensure that tables are created'''
     con = create_perf_db(":memory:")
     cur = con.cursor()
     cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
     tables = cur.fetchall()
     self.assertIn(("Network",), tables)
     self.assertIn(("Cpu",), tables)
     self.assertIn(("Ram",), tables)
     self.assertIn(("Disk",), tables)
コード例 #6
0
    def test_write_to_database(self):
        '''Unit test for write_to_database
        
        Generate some records, write them to database
        query database, ensure records in db'''

        reader = nlp.NetworkLogReader(
            StringIO.StringIO(TEST_NETWORK_LOG_FILE_1))
        reader.add_handle(StringIO.StringIO(TEST_NETWORK_LOG_FILE_2))
        reader.add_handle(StringIO.StringIO(TEST_NETWORK_LOG_FILE_3))

        con = perfdb.create_perf_db(":memory:")
        reader.write_to_database(con)

        expected_entries = [{
            "time": 1373902408.284399,
            "direction": "client_to_thirdparty",
            "payloadlength": 0,
            "protocol": "IP/TCP"
        }, {
            "time": 1373902408.292883,
            "direction": "thirdparty_to_client",
            "payloadlength": 1460,
            "protocol": "IP/TCP"
        }, {
            "time": 1373902411.754983,
            "direction": "thirdparty_to_client",
            "payloadlength": 0,
            "protocol": "IP/TCP"
        }]

        expected_rows = []
        for entry in expected_entries:
            expected_rows.append(
                (epoch_to_sql(entry["time"]), entry["direction"],
                 entry["payloadlength"], entry["direction"]))

        query = "SELECT time, direction, payloadlength, direction FROM Network;"
        cursor = con.cursor()
        cursor.execute(query)
        actual_rows = cursor.fetchall()

        for entry in expected_rows:
            self.assertIn(entry, actual_rows)
コード例 #7
0
    def _create_database(self):
        con = perf_db.create_perf_db(":memory:")
        # 1377616554 = 2013-08-27 15:15:54 (GMT)
        perf_db.insert_ram(con, "client", 1377616554.1, 10000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.2, 12000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.3, 18000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.4, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.5, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.6, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.7, 35000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.8, 33000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "client", 1377616554.9, 30000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.1, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.2, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.3, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.4, 10000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.5, 5000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.6, 5000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.7, 25000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.8, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "server", 1377616554.9, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.1, 1000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.2, 35000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.3, 25000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.4, 1000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.5, 10000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.6, 25000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.7, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.8, 40000, 0, 0, 0, 0)
        perf_db.insert_ram(con, "thirdparty", 1377616554.9, 15000, 0, 0, 0, 0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.1, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.1, 0, 0, 0, 0, 0,
                           15.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.1, 0, 0, 0, 0, 0,
                           20.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.1, 0, 0, 0, 0, 0,
                           25.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.2, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.2, 0, 0, 0, 0, 0,
                           12.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.2, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.2, 0, 0, 0, 0, 0,
                           43.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.3, 0, 0, 0, 0, 0,
                           23.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.3, 0, 0, 0, 0, 0,
                           15.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.3, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.3, 0, 0, 0, 0, 0,
                           34.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.4, 0, 0, 0, 0, 0,
                           34.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.4, 0, 0, 0, 0, 0,
                           33.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.4, 0, 0, 0, 0, 0,
                           0.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.4, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.5, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.5, 0, 0, 0, 0, 0,
                           13.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.5, 0, 0, 0, 0, 0,
                           100.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.5, 0, 0, 0, 0, 0,
                           88.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.6, 0, 0, 0, 0, 0,
                           43.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.6, 0, 0, 0, 0, 0,
                           17.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.6, 0, 0, 0, 0, 0,
                           74.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.6, 0, 0, 0, 0, 0,
                           56.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.7, 0, 0, 0, 0, 0,
                           76.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.7, 0, 0, 0, 0, 0,
                           45.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.7, 0, 0, 0, 0, 0,
                           17.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.7, 0, 0, 0, 0, 0,
                           77.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.8, 0, 0, 0, 0, 0,
                           14.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.8, 0, 0, 0, 0, 0,
                           54.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.8, 0, 0, 0, 0, 0,
                           11.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.8, 0, 0, 0, 0, 0,
                           96.0)
        perf_db.insert_cpu(con, "client", "cpu_0", 1377616554.9, 0, 0, 0, 0, 0,
                           41.0)
        perf_db.insert_cpu(con, "client", "cpu_1", 1377616554.9, 0, 0, 0, 0, 0,
                           47.0)
        perf_db.insert_cpu(con, "client", "cpu_2", 1377616554.9, 0, 0, 0, 0, 0,
                           9.0)
        perf_db.insert_cpu(con, "client", "cpu_3", 1377616554.9, 0, 0, 0, 0, 0,
                           0.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.1, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.1, 0, 0, 0, 0, 0,
                           15.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.1, 0, 0, 0, 0, 0,
                           20.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.1, 0, 0, 0, 0, 0,
                           25.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.2, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.2, 0, 0, 0, 0, 0,
                           12.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.2, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.2, 0, 0, 0, 0, 0,
                           43.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.3, 0, 0, 0, 0, 0,
                           23.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.3, 0, 0, 0, 0, 0,
                           15.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.3, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.3, 0, 0, 0, 0, 0,
                           34.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.4, 0, 0, 0, 0, 0,
                           34.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.4, 0, 0, 0, 0, 0,
                           33.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.4, 0, 0, 0, 0, 0,
                           55.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.4, 0, 0, 0, 0, 0,
                           32.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.5, 0, 0, 0, 0, 0,
                           10.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.5, 0, 0, 0, 0, 0,
                           13.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.5, 0, 0, 0, 0, 0,
                           100.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.5, 0, 0, 0, 0, 0,
                           88.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.6, 0, 0, 0, 0, 0,
                           43.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.6, 0, 0, 0, 0, 0,
                           17.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.6, 0, 0, 0, 0, 0,
                           74.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.6, 0, 0, 0, 0, 0,
                           56.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.7, 0, 0, 0, 0, 0,
                           76.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.7, 0, 0, 0, 0, 0,
                           45.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.7, 0, 0, 0, 0, 0,
                           17.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.7, 0, 0, 0, 0, 0,
                           77.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.8, 0, 0, 0, 0, 0,
                           14.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.8, 0, 0, 0, 0, 0,
                           54.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.8, 0, 0, 0, 0, 0,
                           11.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.8, 0, 0, 0, 0, 0,
                           96.0)
        perf_db.insert_cpu(con, "server", "cpu_0", 1377616554.9, 0, 0, 0, 0, 0,
                           41.0)
        perf_db.insert_cpu(con, "server", "cpu_1", 1377616554.9, 0, 0, 0, 0, 0,
                           47.0)
        perf_db.insert_cpu(con, "server", "cpu_2", 1377616554.9, 0, 0, 0, 0, 0,
                           9.0)
        perf_db.insert_cpu(con, "server", "cpu_3", 1377616554.9, 0, 0, 0, 0, 0,
                           0.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.1, 0, 0, 0,
                           0, 0, 10.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.1, 0, 0, 0,
                           0, 0, 15.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.1, 0, 0, 0,
                           0, 0, 20.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.1, 0, 0, 0,
                           0, 0, 25.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.2, 0, 0, 0,
                           0, 0, 10.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.2, 0, 0, 0,
                           0, 0, 12.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.2, 0, 0, 0,
                           0, 0, 32.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.2, 0, 0, 0,
                           0, 0, 43.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.3, 0, 0, 0,
                           0, 0, 23.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.3, 0, 0, 0,
                           0, 0, 15.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.3, 0, 0, 0,
                           0, 0, 32.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.3, 0, 0, 0,
                           0, 0, 34.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.4, 0, 0, 0,
                           0, 0, 34.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.4, 0, 0, 0,
                           0, 0, 33.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.4, 0, 0, 0,
                           0, 0, 55.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.4, 0, 0, 0,
                           0, 0, 32.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.5, 0, 0, 0,
                           0, 0, 10.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.5, 0, 0, 0,
                           0, 0, 13.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.5, 0, 0, 0,
                           0, 0, 100.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.5, 0, 0, 0,
                           0, 0, 88.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.6, 0, 0, 0,
                           0, 0, 43.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.6, 0, 0, 0,
                           0, 0, 17.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.6, 0, 0, 0,
                           0, 0, 74.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.6, 0, 0, 0,
                           0, 0, 56.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.7, 0, 0, 0,
                           0, 0, 76.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.7, 0, 0, 0,
                           0, 0, 45.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.7, 0, 0, 0,
                           0, 0, 17.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.7, 0, 0, 0,
                           0, 0, 77.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.8, 0, 0, 0,
                           0, 0, 14.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.8, 0, 0, 0,
                           0, 0, 54.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.8, 0, 0, 0,
                           0, 0, 11.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.8, 0, 0, 0,
                           0, 0, 96.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_0", 1377616554.9, 0, 0, 0,
                           0, 0, 41.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_1", 1377616554.9, 0, 0, 0,
                           0, 0, 47.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_2", 1377616554.9, 0, 0, 0,
                           0, 0, 9.0)
        perf_db.insert_cpu(con, "thirdparty", "cpu_3", 1377616554.9, 0, 0, 0,
                           0, 0, 0.0)
        perf_db.insert_disk(con, "client", 1377616554.1, "sda", 0, 32.2, 0,
                            23.2, 0)
        perf_db.insert_disk(con, "client", 1377616554.1, "sdb", 0, 52.2, 0,
                            63.5, 0)
        perf_db.insert_disk(con, "client", 1377616554.1, "sdc", 0, 123.4, 0,
                            12.5, 0)
        perf_db.insert_disk(con, "client", 1377616554.2, "sda", 0, 63, 0, 21.9,
                            0)
        perf_db.insert_disk(con, "client", 1377616554.2, "sdb", 0, 214, 0, 52,
                            0)
        perf_db.insert_disk(con, "client", 1377616554.2, "sdc", 0, 63, 0, 98.2,
                            0)
        perf_db.insert_disk(con, "client", 1377616554.3, "sda", 0, 47, 0, 36.2,
                            0)
        perf_db.insert_disk(con, "client", 1377616554.3, "sdb", 0, 84.4, 0,
                            41.4, 0)
        perf_db.insert_disk(con, "client", 1377616554.3, "sdc", 0, 63.9, 0,
                            96.3, 0)
        perf_db.insert_disk(con, "client", 1377616554.4, "sda", 0, 85.2, 0,
                            10.0, 0)
        perf_db.insert_disk(con, "client", 1377616554.4, "sdb", 0, 71.4, 0,
                            18.0, 0)
        perf_db.insert_disk(con, "client", 1377616554.4, "sdc", 0, 5.2, 0,
                            36.5, 0)
        perf_db.insert_disk(con, "client", 1377616554.5, "sda", 0, 104.1, 0,
                            47.8, 0)
        perf_db.insert_disk(con, "client", 1377616554.5, "sdb", 0, 3, 0, 0.0,
                            0)
        perf_db.insert_disk(con, "client", 1377616554.5, "sdc", 0, 150.7, 0,
                            0.0, 0)
        perf_db.insert_disk(con, "client", 1377616554.6, "sda", 0, 63.7, 0,
                            01.5, 0)
        perf_db.insert_disk(con, "client", 1377616554.6, "sdb", 0, 57.4, 0,
                            84.6, 0)
        perf_db.insert_disk(con, "client", 1377616554.6, "sdc", 0, 14.8, 0,
                            98.4, 0)
        perf_db.insert_disk(con, "client", 1377616554.7, "sda", 0, 98.6, 0,
                            56.3, 0)
        perf_db.insert_disk(con, "client", 1377616554.7, "sdb", 0, 74.5, 0,
                            47.1, 0)
        perf_db.insert_disk(con, "client", 1377616554.7, "sdc", 0, 48.5, 0,
                            96.1, 0)
        perf_db.insert_disk(con, "client", 1377616554.8, "sda", 0, 25.6, 0,
                            87.4, 0)
        perf_db.insert_disk(con, "client", 1377616554.8, "sdb", 0, 49.8, 0,
                            24.8, 0)
        perf_db.insert_disk(con, "client", 1377616554.8, "sdc", 0, 57.9, 0,
                            63.6, 0)
        perf_db.insert_disk(con, "client", 1377616554.9, "sda", 0, 32.6, 0,
                            14.5, 0)
        perf_db.insert_disk(con, "client", 1377616554.9, "sdb", 0, 19.4, 0,
                            74.2, 0)
        perf_db.insert_disk(con, "client", 1377616554.9, "sdc", 0, 1.3, 0, 85,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.1, "sda", 0, 32.2, 0,
                            23.2, 0)
        perf_db.insert_disk(con, "server", 1377616554.1, "sdb", 0, 52.2, 0,
                            63.5, 0)
        perf_db.insert_disk(con, "server", 1377616554.1, "sdc", 0, 123.4, 0,
                            12.5, 0)
        perf_db.insert_disk(con, "server", 1377616554.2, "sda", 0, 63, 0, 21.9,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.2, "sdb", 0, 214, 0, 52,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.2, "sdc", 0, 63, 0, 98.2,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.3, "sda", 0, 47, 0, 36.2,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.3, "sdb", 0, 84.4, 0,
                            41.4, 0)
        perf_db.insert_disk(con, "server", 1377616554.3, "sdc", 0, 63.9, 0,
                            96.3, 0)
        perf_db.insert_disk(con, "server", 1377616554.4, "sda", 0, 85.2, 0,
                            10.0, 0)
        perf_db.insert_disk(con, "server", 1377616554.4, "sdb", 0, 71.4, 0,
                            18.0, 0)
        perf_db.insert_disk(con, "server", 1377616554.4, "sdc", 0, 5.2, 0,
                            36.5, 0)
        perf_db.insert_disk(con, "server", 1377616554.5, "sda", 0, 104.1, 0,
                            47.8, 0)
        perf_db.insert_disk(con, "server", 1377616554.5, "sdb", 0, 3, 0, 0.0,
                            0)
        perf_db.insert_disk(con, "server", 1377616554.5, "sdc", 0, 150.7, 0,
                            0.0, 0)
        perf_db.insert_disk(con, "server", 1377616554.6, "sda", 0, 63.7, 0,
                            1.5, 0)
        perf_db.insert_disk(con, "server", 1377616554.6, "sdb", 0, 57.4, 0,
                            84.6, 0)
        perf_db.insert_disk(con, "server", 1377616554.6, "sdc", 0, 14.8, 0,
                            98.4, 0)
        perf_db.insert_disk(con, "server", 1377616554.7, "sda", 0, 98.6, 0,
                            56.3, 0)
        perf_db.insert_disk(con, "server", 1377616554.7, "sdb", 0, 74.5, 0,
                            47.1, 0)
        perf_db.insert_disk(con, "server", 1377616554.7, "sdc", 0, 48.5, 0,
                            96.1, 0)
        perf_db.insert_disk(con, "server", 1377616554.8, "sda", 0, 25.6, 0,
                            87.4, 0)
        perf_db.insert_disk(con, "server", 1377616554.8, "sdb", 0, 49.8, 0,
                            24.8, 0)
        perf_db.insert_disk(con, "server", 1377616554.8, "sdc", 0, 57.9, 0,
                            63.6, 0)
        perf_db.insert_disk(con, "server", 1377616554.9, "sda", 0, 32.6, 0,
                            14.5, 0)
        perf_db.insert_disk(con, "server", 1377616554.9, "sdb", 0, 19.4, 0,
                            74.2, 0)
        perf_db.insert_disk(con, "server", 1377616554.9, "sdc", 0, 1.3, 0, 85,
                            0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.1, "sda", 0, 32.2, 0,
                            23.2, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.1, "sdb", 0, 52.2, 0,
                            63.5, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.1, "sdc", 0, 123.4,
                            0, 12.5, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.2, "sda", 0, 63, 0,
                            21.9, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.2, "sdb", 0, 214, 0,
                            52, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.2, "sdc", 0, 63, 0,
                            98.2, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.3, "sda", 0, 47, 0,
                            36.2, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.3, "sdb", 0, 84.4, 0,
                            41.4, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.3, "sdc", 0, 63.9, 0,
                            96.3, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.4, "sda", 0, 85.2, 0,
                            10.0, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.4, "sdb", 0, 71.4, 0,
                            18.0, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.4, "sdc", 0, 5.2, 0,
                            36.5, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.5, "sda", 0, 104.1,
                            0, 47.8, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.5, "sdb", 0, 3, 0,
                            0.0, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.5, "sdc", 0, 150.7,
                            0, 0.0, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.6, "sda", 0, 63.7, 0,
                            1.5, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.6, "sdb", 0, 57.4, 0,
                            84.6, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.6, "sdc", 0, 14.8, 0,
                            98.4, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.7, "sda", 0, 98.6, 0,
                            56.3, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.7, "sdb", 0, 74.5, 0,
                            47.1, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.7, "sdc", 0, 48.5, 0,
                            96.1, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.8, "sda", 0, 25.6, 0,
                            87.4, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.8, "sdb", 0, 49.8, 0,
                            24.8, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.8, "sdc", 0, 57.9, 0,
                            63.6, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.9, "sda", 0, 32.6, 0,
                            14.5, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.9, "sdb", 0, 19.4, 0,
                            74.2, 0)
        perf_db.insert_disk(con, "thirdparty", 1377616554.9, "sdc", 0, 1.3, 0,
                            85, 0)
        perf_db.insert_network(con, 1377616554.1, "client_to_server", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "client_to_server", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.30, "client_to_server", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.34, "client_to_server", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.36, "client_to_server", 1200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.41, "client_to_server", 1400,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.43, "client_to_server", 300,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.48, "client_to_server", 600,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.49, "client_to_server", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.51, "client_to_server", 200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.53, "client_to_server", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "client_to_server", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "client_to_server", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "client_to_server", 1100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "client_to_server", 1200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "client_to_server", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.1, "server_to_client", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "server_to_client", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.30, "server_to_client", 1200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.34, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.36, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.39, "server_to_client", 1400,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.43, "server_to_client", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.48, "server_to_client", 200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.53, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.57, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.63, "server_to_client", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "server_to_client", 800,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "server_to_client", 1100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "server_to_client", 1200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "server_to_client", 1500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.1, "client_to_thirdparty", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "client_to_thirdparty", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.30, "client_to_thirdparty", 800,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.31, "client_to_thirdparty", 300,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.32, "client_to_thirdparty", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.35, "client_to_thirdparty", 400,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.39, "client_to_thirdparty",
                               1300, "TCP/IP")
        perf_db.insert_network(con, 1377616554.41, "client_to_thirdparty", 900,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.49, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.61, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.68, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "client_to_thirdparty",
                               1100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "client_to_thirdparty",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "client_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.1, "thirdparty_to_client", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "thirdparty_to_client", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.28, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.44, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.46, "thirdparty_to_client",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.48, "thirdparty_to_client",
                               1400, "TCP/IP")
        perf_db.insert_network(con, 1377616554.485, "thirdparty_to_client",
                               1300, "TCP/IP")
        perf_db.insert_network(con, 1377616554.49, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.493, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.51, "thirdparty_to_client",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.53, "thirdparty_to_client",
                               1300, "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "thirdparty_to_client", 600,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "thirdparty_to_client",
                               1100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "thirdparty_to_client",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "thirdparty_to_client",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.1, "server_to_thirdparty", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "server_to_thirdparty", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.30, "server_to_thirdparty", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.34, "server_to_thirdparty", 200,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.36, "server_to_thirdparty", 150,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.363, "server_to_thirdparty", 50,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.3643, "server_to_thirdparty",
                               100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.3648, "server_to_thirdparty",
                               150, "TCP/IP")
        perf_db.insert_network(con, 1377616554.3649, "server_to_thirdparty",
                               50, "TCP/IP")
        perf_db.insert_network(con, 1377616554.51, "server_to_thirdparty", 400,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.53, "server_to_thirdparty", 800,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "server_to_thirdparty",
                               1100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "server_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "server_to_thirdparty",
                               1100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "server_to_thirdparty",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "server_to_thirdparty",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.1, "thirdparty_to_server", 1000,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.2, "thirdparty_to_server", 500,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.30, "thirdparty_to_server", 700,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.34, "thirdparty_to_server", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.36, "thirdparty_to_server", 100,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.41, "thirdparty_to_server",
                               1400, "TCP/IP")
        perf_db.insert_network(con, 1377616554.43, "thirdparty_to_server", 800,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.548, "thirdparty_to_server",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.549, "thirdparty_to_server",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.551, "thirdparty_to_server",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.63, "thirdparty_to_server", 700,
                               "TCP/IP")
        perf_db.insert_network(con, 1377616554.70, "thirdparty_to_server",
                               1000, "TCP/IP")
        perf_db.insert_network(con, 1377616554.80, "thirdparty_to_server",
                               1500, "TCP/IP")
        perf_db.insert_network(con, 1377616554.85, "thirdparty_to_server",
                               1100, "TCP/IP")
        perf_db.insert_network(con, 1377616554.87, "thirdparty_to_server",
                               1200, "TCP/IP")
        perf_db.insert_network(con, 1377616554.90, "thirdparty_to_server",
                               1500, "TCP/IP")

        return con
コード例 #8
0
def main():
    '''Reads in raw log files/pcap and writes entries to an sqlite database'''

    parser = argparse.ArgumentParser()
    parser.add_argument('-e',
                        '--endpoint',
                        dest='host',
                        type=str,
                        required=False,
                        help='endpoint, aka host ("client", "server", etc.)')
    parser.add_argument('-c',
                        '--cpu-file',
                        dest='cpu_file',
                        type=str,
                        required=False,
                        default=None,
                        help='(uncompressed) cpu log file')
    parser.add_argument('-d',
                        '--disk-file',
                        dest='disk_file',
                        type=str,
                        required=False,
                        default=None,
                        help='(uncompressed) disk log file')
    parser.add_argument('-r',
                        '--ram-file',
                        dest='ram_file',
                        type=str,
                        required=False,
                        default=None,
                        help='(uncompressed) ram log file')
    parser.add_argument('-n',
                        '--network-file',
                        dest='network_file',
                        type=str,
                        required=False,
                        default=None,
                        help='pcap file')
    parser.add_argument(
        "-m",
        "--network-map",
        dest='network_map',
        type=str,
        required=False,
        default=None,
        help='file containing map from IP address to host ("client")')
    parser.add_argument('-o',
                        '--output-file',
                        dest='sqlite_file',
                        type=str,
                        required=True,
                        help='sqlite3 file to write to')

    options = parser.parse_args()

    con = create_perf_db(options.sqlite_file)

    if (options.cpu_file != None):
        reader = CpuLogReader(handle=open(options.cpu_file), host=options.host)
        reader.write_to_database(con)
    if (options.disk_file != None):
        reader = DiskLogReader(handle=open(options.disk_file),
                               host=options.host)
        reader.write_to_database(con)
    if (options.ram_file != None):
        reader = RamLogReader(handle=open(options.ram_file), host=options.host)
        reader.write_to_database(con)
    if (options.network_file != None):
        if (options.network_map == None):
            sys.stderr.write("Must include network map if parsing pcap files")
        else:
            mappings = get_mappings_from_handle(open(options.network_map))
            reader = pcap_to_log(options.network_file, mappings)
            reader.write_to_database(con)
コード例 #9
0
    def test_write_to_database(self):
        '''Unit test for write_to_database
        
        Generate some records, write them to database
        query database, ensure records in db'''
        
        reader = clp.CpuLogReader(StringIO.StringIO(TEST_CPU_LOG_FILE_1), "client")
        reader.add_handle(StringIO.StringIO(TEST_CPU_LOG_FILE_2), "server")
        reader.add_handle(StringIO.StringIO(TEST_CPU_LOG_FILE_3), "thirdparty")
        
        con = perfdb.create_perf_db(":memory:")
        reader.write_to_database(con)
                
        expected_entries = [
            {
             "host" : "client", 
             "time_epoch" : date_and_time_to_epoch("20130805", "11:38:56.377"),
             "cpu_identifier" : "cpu_6",   
             "user_pct" : .72, 
             "sys_pct" : 0.0,
             "wait_pct" : 0.0, 
             "irq_pct" : 0.0,
             "idle_pct" : 99.28, 
             "total_pct" : .72 
            },
            {
             "host" : "server", 
             "time_epoch" : date_and_time_to_epoch("20130805", "11:39:00.505"),
             "cpu_identifier" : "cpu_4",   
             "user_pct" : 2.94, 
             "sys_pct" : 0.74,
             "wait_pct" : 0.0, 
             "irq_pct" : 0.0,
             "idle_pct" : 96.32, 
             "total_pct" : 3.68 
            },                      
            {
             "host" : "thirdparty", 
             "time_epoch" : date_and_time_to_epoch("20130805", "11:39:06.009"),
             "cpu_identifier" : "cpu_0",   
             "user_pct" : 0.0, 
             "sys_pct" : 0.0,
             "wait_pct" : 2.17, 
             "irq_pct" : 0.0,
             "idle_pct" : 97.83, 
             "total_pct" : 0.0 
            } 
            ]

        expected_rows = []
        for entry in expected_entries:
            expected_rows.append((entry["host"], epoch_to_sql(entry["time_epoch"]), 
                                  entry["cpu_identifier"], 
                                  entry["user_pct"], entry["sys_pct"],
                                  entry["wait_pct"], entry["irq_pct"],
                                  entry["idle_pct"], entry["total_pct"])) 
        
        query = "SELECT host, time, cpu_identifier, user_pct, sys_pct, wait_pct, irq_pct, idle_pct, total_pct from Cpu;"
        cursor = con.cursor()
        cursor.execute(query)
        actual_rows = cursor.fetchall()
        
        for entry in expected_rows:
            self.assertIn(entry, actual_rows)
            
コード例 #10
0
    def test_write_to_database(self):
        '''Unit test for write_to_database
        
        Generate some records, write them to database
        query database, ensure records in db'''

        reader = rlp.RamLogReader(StringIO.StringIO(TEST_RAM_LOG_FILE_1),
                                  "client")
        reader.add_handle(StringIO.StringIO(TEST_RAM_LOG_FILE_2), "thirdparty")
        reader.add_handle(StringIO.StringIO(TEST_RAM_LOG_FILE_3), "thirdparty")

        con = perfdb.create_perf_db(":memory:")
        reader.write_to_database(con)

        expected_entries = [{
            "host":
            "client",
            "time_epoch":
            date_and_time_to_epoch("20130731", "11:33:33.003"),
            "free_kb":
            71368,
            "used_kb":
            940564,
            "swap_total":
            1046524,
            "swap_used":
            304800,
            "swap_free":
            741724
        }, {
            "host":
            "thirdparty",
            "time_epoch":
            date_and_time_to_epoch("20130731", "11:33:42.003"),
            "free_kb":
            71244,
            "used_kb":
            940688,
            "swap_total":
            1046524,
            "swap_used":
            304800,
            "swap_free":
            741724
        }, {
            "host":
            "thirdparty",
            "time_epoch":
            date_and_time_to_epoch("20130731", "11:33:57.003"),
            "free_kb":
            73352,
            "used_kb":
            938580,
            "swap_total":
            1046524,
            "swap_used":
            304800,
            "swap_free":
            741724
        }]

        expected_rows = []
        for entry in expected_entries:
            expected_rows.append(
                (entry["host"], epoch_to_sql(entry["time_epoch"]),
                 entry["free_kb"], entry["used_kb"], entry["swap_total"],
                 entry["swap_used"], entry["swap_free"]))

        query = "SELECT host, time, free_kb, used_kb, swap_total, swap_used, swap_free FROM Ram;"
        cursor = con.cursor()
        cursor.execute(query)
        actual_rows = cursor.fetchall()

        for entry in expected_rows:
            self.assertIn(entry, actual_rows)
コード例 #11
0
    def test_write_to_database(self):
        '''Unit test for write_to_database
        
        Generate some records, write them to database
        query database, ensure records in db'''

        reader = dlp.DiskLogReader(StringIO.StringIO(TEST_DISK_LOG_FILE_1),
                                   "client")
        reader.add_handle(StringIO.StringIO(TEST_DISK_LOG_FILE_2), "server")
        reader.add_handle(StringIO.StringIO(TEST_DISK_LOG_FILE_3),
                          "thirdparty")

        con = perfdb.create_perf_db(":memory:")
        reader.write_to_database(con)

        expected_entries = [{
            "host":
            "client",
            "time_epoch":
            date_and_time_to_epoch("20130802", "16:07:52.568"),
            "disk_name":
            "sda",
            "reads_per_sec":
            240.84,
            "reads_kbps":
            3710.05,
            "writes_per_sec":
            4.68,
            "writes_kbps":
            59.24
        }, {
            "host":
            "server",
            "time_epoch":
            date_and_time_to_epoch("20130802", "16:07:57.700"),
            "disk_name":
            "sda",
            "reads_per_sec":
            47.47,
            "reads_kbps":
            11297.47,
            "writes_per_sec":
            34.02,
            "writes_kbps":
            5901.90
        }, {
            "host":
            "thirdparty",
            "time_epoch":
            date_and_time_to_epoch("20130802", "16:08:04.399"),
            "disk_name":
            "sdb",
            "reads_per_sec":
            301.87,
            "reads_kbps":
            2985.96,
            "writes_per_sec":
            1.56,
            "writes_kbps":
            31.20
        }]

        expected_rows = []
        for entry in expected_entries:
            expected_rows.append(
                (entry["host"], epoch_to_sql(entry["time_epoch"]),
                 entry["disk_name"], entry["reads_per_sec"],
                 entry["reads_kbps"], entry["writes_per_sec"],
                 entry["writes_kbps"]))

        query = "SELECT host, time, disk_name, reads_per_sec, reads_kbps, writes_per_sec, writes_kbps FROM Disk;"
        cursor = con.cursor()
        cursor.execute(query)
        actual_rows = cursor.fetchall()

        for entry in expected_rows:
            self.assertIn(entry, actual_rows)