added getters of averages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
35c3643b1a
commit
f5edd93ee1
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from flask import request, current_app, Response
|
from flask import request, current_app, Response, jsonify
|
||||||
from flask_classful import FlaskView, route
|
from flask_classful import FlaskView, route
|
||||||
from utils import json_required, influxdb_instance
|
from utils import json_required, influxdb_instance
|
||||||
from influxdb_client import Point
|
from influxdb_client import Point
|
||||||
@ -7,9 +7,11 @@ from influxdb_client import Point
|
|||||||
|
|
||||||
class ReportView(FlaskView):
|
class ReportView(FlaskView):
|
||||||
|
|
||||||
|
# LINK
|
||||||
|
|
||||||
@route("/link", methods=['POST'])
|
@route("/link", methods=['POST'])
|
||||||
@json_required
|
@json_required
|
||||||
def link(self):
|
def link_post(self):
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
||||||
points = []
|
points = []
|
||||||
@ -26,9 +28,52 @@ class ReportView(FlaskView):
|
|||||||
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
||||||
return Response(status=201)
|
return Response(status=201)
|
||||||
|
|
||||||
|
@route("/link", methods=['GET'])
|
||||||
|
def link_get(self):
|
||||||
|
q = influxdb_instance.connection.query_api()
|
||||||
|
response = {}
|
||||||
|
|
||||||
|
# Query latency
|
||||||
|
|
||||||
|
latency_tables = q.query(f"""from(bucket: "alma")
|
||||||
|
|> range(start: -2m, stop: now())
|
||||||
|
|> filter(fn: (r) => r["_measurement"] == "link_latency")
|
||||||
|
|> timedMovingAverage(every: 30s, period: 1m)
|
||||||
|
|> last()
|
||||||
|
|> yield()""")
|
||||||
|
|
||||||
|
for table in latency_tables:
|
||||||
|
for value in table.values:
|
||||||
|
key = value['client'] + ":" + value['site']
|
||||||
|
if key in response:
|
||||||
|
response[key]['latency'] = value['_value']
|
||||||
|
else:
|
||||||
|
response[key] = {'latency': value['_value']}
|
||||||
|
|
||||||
|
# Query rate
|
||||||
|
|
||||||
|
rate_tables = q.query(f"""from(bucket: "alma")
|
||||||
|
|> range(start: -2m, stop: now())
|
||||||
|
|> filter(fn: (r) => r["_measurement"] == "link_rate")
|
||||||
|
|> timedMovingAverage(every: 30s, period: 1m)
|
||||||
|
|> last()
|
||||||
|
|> yield()""")
|
||||||
|
|
||||||
|
for table in rate_tables:
|
||||||
|
for value in table.values:
|
||||||
|
key = value['client'] + ":" + value['site']
|
||||||
|
if key in response:
|
||||||
|
response[key]['rate'] = value['_value']
|
||||||
|
else:
|
||||||
|
response[key] = {'rate': value['_value']}
|
||||||
|
|
||||||
|
return jsonify(response)
|
||||||
|
|
||||||
|
# CLIENT
|
||||||
|
|
||||||
@route("/client", methods=['POST'])
|
@route("/client", methods=['POST'])
|
||||||
@json_required
|
@json_required
|
||||||
def client(self):
|
def client_post(self):
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
||||||
points = []
|
points = []
|
||||||
@ -44,9 +89,35 @@ class ReportView(FlaskView):
|
|||||||
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
||||||
return Response(status=201)
|
return Response(status=201)
|
||||||
|
|
||||||
|
@route("/client", methods=['GET'])
|
||||||
|
def client_get(self):
|
||||||
|
q = influxdb_instance.connection.query_api()
|
||||||
|
response = {}
|
||||||
|
|
||||||
|
# Query queue
|
||||||
|
|
||||||
|
latency_tables = q.query(f"""from(bucket: "alma")
|
||||||
|
|> range(start: -2m, stop: now())
|
||||||
|
|> filter(fn: (r) => r["_measurement"] == "client_queue")
|
||||||
|
|> timedMovingAverage(every: 30s, period: 1m)
|
||||||
|
|> last()
|
||||||
|
|> yield()""")
|
||||||
|
|
||||||
|
for table in latency_tables:
|
||||||
|
for value in table.values:
|
||||||
|
key = value['client']
|
||||||
|
if key in response:
|
||||||
|
response[key]['queue'] = value['_value']
|
||||||
|
else:
|
||||||
|
response[key] = {'queue': value['_value']}
|
||||||
|
|
||||||
|
return jsonify(response)
|
||||||
|
|
||||||
|
# SITE
|
||||||
|
|
||||||
@route("/site", methods=['POST'])
|
@route("/site", methods=['POST'])
|
||||||
@json_required
|
@json_required
|
||||||
def site(self):
|
def site_post(self):
|
||||||
data = request.json
|
data = request.json
|
||||||
|
|
||||||
points = []
|
points = []
|
||||||
@ -61,3 +132,27 @@ class ReportView(FlaskView):
|
|||||||
|
|
||||||
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
influxdb_instance.connection.write_api().write("alma", current_app.config['INFLUXDB_V2_ORG'], points)
|
||||||
return Response(status=201)
|
return Response(status=201)
|
||||||
|
|
||||||
|
@route("/site", methods=['GET'])
|
||||||
|
def site_get(self):
|
||||||
|
q = influxdb_instance.connection.query_api()
|
||||||
|
response = {}
|
||||||
|
|
||||||
|
# Query queue
|
||||||
|
|
||||||
|
latency_tables = q.query(f"""from(bucket: "alma")
|
||||||
|
|> range(start: -2m, stop: now())
|
||||||
|
|> filter(fn: (r) => r["_measurement"] == "site_queue")
|
||||||
|
|> timedMovingAverage(every: 30s, period: 1m)
|
||||||
|
|> last()
|
||||||
|
|> yield()""")
|
||||||
|
|
||||||
|
for table in latency_tables:
|
||||||
|
for value in table.values:
|
||||||
|
key = value['site']
|
||||||
|
if key in response:
|
||||||
|
response[key]['queue'] = value['_value']
|
||||||
|
else:
|
||||||
|
response[key] = {'queue': value['_value']}
|
||||||
|
|
||||||
|
return jsonify(response)
|
||||||
|
Loading…
Reference in New Issue
Block a user