simple-2.py 1.68 KB
Newer Older
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
import requests, json, time 

url = "http://localhost:8766"
#train model request 

url_file = '/home/jean-didier/Projects/morphemic/performance-model/ml_code/example/dataset.csv'
url_file_3 = '/home/jean-didier/Projects/morphemic/performance-model/ml_code/example/all.csv'

#features = ['time','served_request','request_rate','response_time','performance','cpu_usage','memory']
#features_3 = ['number','served_request','request_rate','number_instances','response_time','performance','cpu_usage','cpu_alloc','memory','memory_alloc']
features_2 = ['cpu_usage','memory','level','response_time','latency']


#post_data = {'url_file': url_file, 'application': 'application-1','target':'performance','features': features}
post_data_2 = {'url_file': "", 'application': 'fcr','target':'response_time','features': features_2}
#post_data_3 = {'url_file': url_file_3, 'application': 'application-3','target':'performance','features': features_3}
#print("Get model")
#response = requests.post(url+"/api/v1/model", data='{"application":"application-2"}', headers={'Content-Type':'application/json'})
#print(response.text)


#response = requests.post(url+"/api/v1/model/train", data=json.dumps(post_data_2),headers={'Content-Type':'application/json'}).text 
#print("Training phase")
#print(response)

#time.sleep(5)
#prediction request 

#features = {'cpu_alloc': 1 ,'memory_alloc': 64,'number_instances':4, "memory": 51086677.3333}
features = {'cpu_usage': 31, "memory": 4500.23, 'latency': 2.1, 'level': 1}
post_data = {'application': 'fcr','target':'response_time','features':features}
response = requests.post(url+"/api/v1/model/predict", data=json.dumps(post_data),headers={'Content-Type':'application/json'}).text 
print(response)