Skip to content

Commit

Permalink
add time per call in serviceTIme metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Vega committed Jan 18, 2017
1 parent e62cbc6 commit c98d0e4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
75 changes: 54 additions & 21 deletions src/orchestrator/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class Stats(object):
"incomingTransactionResponseSize": 0,
"incomingTransactionErrors": 0,
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
Expand All @@ -146,12 +147,13 @@ def collectMetrics(self, service_start, service_name, subservice_name,
flow_metrics = flow.getFlowMetrics()
else:
flow_metrics = {
"serviceTime": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
"outgoingTransactionErrors": 0,
}
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
"outgoingTransactionErrors": 0,
}

if service_name and not service_name in self.service:
self.service[service_name] = {
Expand All @@ -161,6 +163,7 @@ def collectMetrics(self, service_start, service_name, subservice_name,
"incomingTransactionResponseSize": 0,
"incomingTransactionErrors": 0,
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
Expand All @@ -177,13 +180,13 @@ def collectMetrics(self, service_start, service_name, subservice_name,
"incomingTransactionResponseSize": 0,
"incomingTransactionErrors": 0,
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
"outgoingTransactionErrors": 0,
}

# TODO:
# Analize "response"" to know if is a Response about an error or not
if response.status_code not in [200, 201, 204]:
# API error
Expand All @@ -198,13 +201,13 @@ def collectMetrics(self, service_start, service_name, subservice_name,
self.service[service_name]["subservs"][subservice_name]["incomingTransactionErrors"] += 1
self.service[service_name]["subservs"][subservice_name]["incomingTransactionRequestSize"] += len(json.dumps(request.data))
self.service[service_name]["subservs"][subservice_name]["incomingTransactionResponseSize"] += len(json.dumps(response.data))
self.service[service_name]["subservs"][subservice_name]["serviceTime"] += (service_stop - service_start)
self.service[service_name]["subservs"][subservice_name]["serviceTimeTotal"] += (service_stop - service_start)

self.service[service_name]["subservs"][subservice_name]["outgoingTransactions"] += flow_metrics["outgoingTransactions"]
self.service[service_name]["subservs"][subservice_name]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"]
self.service[service_name]["subservs"][subservice_name]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"]
self.service[service_name]["subservs"][subservice_name]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"]
self.service[service_name]["subservs"][subservice_name]["serviceTime"] += flow_metrics["serviceTime"]
self.service[service_name]["subservs"][subservice_name]["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"]



Expand All @@ -215,12 +218,12 @@ def collectMetrics(self, service_start, service_name, subservice_name,
self.service[service_name]["sum"]["incomingTransactionErrors"] += 1
self.service[service_name]["sum"]["incomingTransactionRequestSize"] += len(json.dumps(request.data))
self.service[service_name]["sum"]["incomingTransactionResponseSize"] += len(json.dumps(response.data))
self.service[service_name]["sum"]["serviceTime"] += (service_stop - service_start)
self.service[service_name]["sum"]["serviceTimeTotal"] += (service_stop - service_start)
self.service[service_name]["sum"]["outgoingTransactions"] += flow_metrics["outgoingTransactions"]
self.service[service_name]["sum"]["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"]
self.service[service_name]["sum"]["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"]
self.service[service_name]["sum"]["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"]
self.service[service_name]["sum"]["serviceTime"] += flow_metrics["serviceTime"]
self.service[service_name]["sum"]["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"]

# Sum
if not transactionError:
Expand All @@ -229,12 +232,12 @@ def collectMetrics(self, service_start, service_name, subservice_name,
self.sum["incomingTransactionErrors"] += 1
self.sum["incomingTransactionRequestSize"] += len(json.dumps(request.data))
self.sum["incomingTransactionResponseSize"] += len(json.dumps(response.data))
self.sum["serviceTime"] += (service_stop - service_start)
self.sum["serviceTimeTotal"] += (service_stop - service_start)
self.sum["outgoingTransactions"] += flow_metrics["outgoingTransactions"]
self.sum["outgoingTransactionRequestSize"] += flow_metrics["outgoingTransactionRequestSize"]
self.sum["outgoingTransactionResponseSize"] += flow_metrics["outgoingTransactionResponseSize"]
self.sum["outgoingTransactionErrors"] += flow_metrics["outgoingTransactionErrors"]
self.sum["serviceTime"] += flow_metrics["serviceTime"]
self.sum["serviceTimeTotal"] += flow_metrics["serviceTimeTotal"]


def resetMetrics(self):
Expand All @@ -245,13 +248,48 @@ def resetMetrics(self):
"incomingTransactionResponseSize": 0,
"incomingTransactionErrors": 0,
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
"outgoingTransactionErrors": 0,
}


def composeMetrics(self):

result = {
"service": self.service,
"sum": self.sum
}

for serv in result["service"]:
if result["service"][serv]["sum"]["serviceTimeTotal"] > 0:
result["service"][serv]["sum"]["serviceTime"] = result["service"][serv]["sum"]["serviceTimeTotal"] / (
result["service"][serv]["sum"]["incomingTransactions"] +
result["service"][serv]["sum"]["incomingTransactionErrors"] +
result["service"][serv]["sum"]["outgoingTransactions"] +
result["service"][serv]["sum"]["outgoingTransactionErrors"]
)

for subserv in result["service"][serv]["subservs"]:
if result["service"][serv]["subservs"][subserv]["serviceTimeTotal"] > 0:
result["service"][serv]["subservs"][subserv]["serviceTime"] = result["service"][serv]["subservs"][subserv]["serviceTimeTotal"] / (
result["service"][serv]["subservs"][subserv]["incomingTransactions"] +
result["service"][serv]["subservs"][subserv]["incomingTransactionErrors"] +
result["service"][serv]["subservs"][subserv]["outgoingTransactions"] +
result["service"][serv]["subservs"][subserv]["outgoingTransactionErrors"]
)

if result["sum"]["serviceTimeTotal"] > 0:
result["sum"]["serviceTime"] = result["sum"]["serviceTimeTotal"] / (
result["sum"]["incomingTransactions"] +
result["sum"]["incomingTransactionErrors"] +
result["sum"]["outgoingTransactions"] +
result["sum"]["outgoingTransactionErrors"]
)
return result


class IoTConf(Stats):
throttle_classes = (AnonRateThrottle,)
Expand Down Expand Up @@ -3033,10 +3071,8 @@ def get(self, request):
reset = request.GET.get('reset', False) == "true"

try:
result = {
"service": self.service,
"sum": self.sum
}
result = self.composeMetrics()

if reset:
self.resetMetrics()

Expand All @@ -3061,10 +3097,7 @@ def delete(self, request):
CORRELATOR_ID = self.getCorrelatorIdHeader(request)

try:
result = {
"service" : self.service,
"sum" : self.sum
}
result = self.composeMetrics()
self.resetMetrics()
response = Response(result, status=status.HTTP_204_OK,
headers={"Fiware-Correlator": CORRELATOR_ID})
Expand Down
3 changes: 2 additions & 1 deletion src/orchestrator/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self,
self.service = {}
self.sum = {
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
Expand Down Expand Up @@ -271,7 +272,7 @@ def collectOutgoingMetrics(self, service_start, data_request, response):
self.sum["outgoingTransactionErrors"] += 1
self.sum["outgoingTransactionRequestSize"] += len(json.dumps(data_request))
self.sum["outgoingTransactionResponseSize"] += len(json.dumps(data_response))
self.sum["serviceTime"] += (service_stop - service_start)
self.sum["serviceTimeTotal"] += (service_stop - service_start)
except Exception, ex:
self.logger.error("ERROR collecting outgoing metrics %s", ex)

Expand Down
1 change: 1 addition & 0 deletions src/orchestrator/core/flow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(self,

self.sum = {
"serviceTime": 0,
"serviceTimeTotal": 0,
"outgoingTransactions": 0,
"outgoingTransactionRequestSize": 0,
"outgoingTransactionResponseSize": 0,
Expand Down

0 comments on commit c98d0e4

Please sign in to comment.