-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB_Write.py
executable file
·86 lines (63 loc) · 2.09 KB
/
DB_Write.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
import json
import pymongo
import datetime
import string
import random
import os
import uuid
import time
import sys
from datetime import timezone, datetime
from mongoengine import *
connect('mongoengine_test', host='localhost', port=27017)
#from pymongo import MongoClient
#client = MongoClient('localhost', 27017) #making connection to MongoClient
class FirstTC(Document):
syscall_nr = IntField(min_value=None, max_value=None)
syscall_name = StringField(required=True)
dtb = StringField(required=True, max_length=50)
rsp = StringField(required=True, max_length=20)
rip = StringField(required=True, max_length=20)
pid = IntField(min_value=None, max_value=None)
ts = IntField(min_value=None, max_value=None)
vmid = StringField(required=True, max_length=20)
logtype = StringField(required=True, max_length=20)
#return Math.round(new Date().getTime()); /* timestamp in milliseconds */
#print ("hello")
def random_generator(size=6, chars=string.ascii_uppercase):
return ''.join(random.choice(chars) for x in range(size))
def random_hexgenerator():
hexN="0x"+uuid.uuid4().hex
return hexN[:18]
def timestamp_gen():
ts=int(datetime.now(tz=timezone.utc).timestamp() * 1000)
return ts
i=0
orig_stdout = sys.stdout
f = open('/media/sf_DB_Readings/Readings.csv', 'w')
sys.stdout=f
comm=","
while i<10000:
i=i+1
start = time.time()
post_1 = FirstTC(
syscall_nr=random.randint(1,101),
syscall_name=random_generator(6,"abcdefghijklmnopqrstuvwxyz"),
dtb=random_hexgenerator(),
rsp=random_hexgenerator(),
rip=random_hexgenerator(),
pid=random.randint(1,10000),
ts= timestamp_gen(),
vmid="vm"+random_generator(2,'1234'),
logtype=random_generator(3,'xyz')
)
post_1.save() # This will perform an insert
end=time.time()
executionTime = (end - start) * 1000 # Convert to ms
print (i,comm,executionTime)
sys.stdout = orig_stdout
#f.write(",%f\n" % executionTime)
f.close()
print("saved")
#os.system('mongoexport --db mongoengine_test --collection post --pretty --out output.json > /dev/null 2>&1')