-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathclient.py
More file actions
35 lines (33 loc) · 1.19 KB
/
client.py
File metadata and controls
35 lines (33 loc) · 1.19 KB
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
from prometheus_client import start_http_server, CollectorRegistry, Summary, Gauge
# import random
import time
import requests
import json
import random
registry = CollectorRegistry()
# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
g = Gauge('my_progressed_requests', 'Description of gauge')
def process_request(t):
"""A dummy function that takes some time."""
time.sleep(t)
API_ENDPOINT = "http://127.0.0.1:8080/prediction"
# Time the code
with REQUEST_TIME.time():
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
input = [[[random.uniform(-1, 1)] for x in range(6)]]
# data to be sent to api
param = {
"inputs": json.dumps(input)
}
# sending post request and saving response as response object
response = requests.post(url = API_ENDPOINT, data = param)
g.inc()
result = response.json()
# extracting response text
print(result)
process_request(10)