Skip to content

Commit

Permalink
feature/added the lastEndpoint info on metric page
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Dec 4, 2023
1 parent ff2b203 commit d196ae7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
17 changes: 17 additions & 0 deletions apimanager/metrics/static/metrics/js/lastEndpointMetric.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$(document).ready(function($) {
getMetricLastEndpoint();
});

function getMetricLastEndpoint(){
$.ajax({url: "/metrics/api/last-endpoint", success: function(result){
var content = "Last call: "
+result['app_name']+" "
+result['verb']+" "
+ result['implemented_by_partial_function']
+" costed "
+result['duration']
+" ms.";
$("#last_endpoint").text(content);
setTimeout(function(){getMetricLastEndpoint();}, 5000); // will call function to update time every 5 seconds
}});
}
6 changes: 4 additions & 2 deletions apimanager/metrics/templates/metrics/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{% load i18n %}

{% block page_title %}{{ block.super }} / API Metrics{% endblock page_title %}

{% block extrajs %}
<script type="text/javascript" src="{% static 'metrics/js/lastEndpointMetric.js' %}"></script>
{% endblock extrajs %}
{% load bootstrap3 %}
{% block content %}
<div id="metrics">
Expand All @@ -12,7 +14,7 @@
{{ form.media }} {# Form required JS and CSS #}
{% endblock %}
<h1>{% trans "API Metrics" %}</h1>

<h5 id ="last_endpoint">Last call: API Manager getMetrics costed 294 ms</h5>
<div id="metrics-filter">
<h2>{% trans "Filter" %}</h2>
<form action="" method="get">
Expand Down
6 changes: 5 additions & 1 deletion apimanager/metrics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
WeeklySummaryView,
DailySummaryView,
HourlySummaryView,
CustomSummaryView
CustomSummaryView,
get_metric_last_endpoint
)

urlpatterns = [
url(r'^api/$',
APIMetricsView.as_view(),
name='api-metrics'),
url(r'^api/last-endpoint/$',
get_metric_last_endpoint,
name='api-metrics-last-endpoint'),
url(r'^api/summary-partial-function$',
APISummaryPartialFunctionView.as_view(),
name='api-metrics-summary-partial-function'),
Expand Down
19 changes: 19 additions & 0 deletions apimanager/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from enum import Enum

from django.conf import settings
from django.http import JsonResponse
from apimanager import local_settings
from apimanager.settings import API_HOST, EXCLUDE_APPS, EXCLUDE_FUNCTIONS, EXCLUDE_URL_PATTERN, API_EXPLORER_APP_NAME, API_DATE_FORMAT_WITH_MILLISECONDS, API_DATE_FORMAT_WITH_SECONDS , DEBUG
from django.contrib import messages
Expand Down Expand Up @@ -201,6 +202,24 @@ def get_context_data(self, **kwargs):
})
return context

def get_metric_last_endpoint(request):
urlpath = "/management/metrics?limit=1"
api = API(request.session.get('obp'))
last_endpoint_metric={}
try:
metric = api.get(urlpath)['metrics'][0]
last_endpoint_metric={
'app_name':metric['app_name'],
'verb': metric['verb'],
'implemented_by_partial_function': metric['implemented_by_partial_function'],
'duration': metric['duration']
}
except Exception as err:
LOGGER.exception('error_once_only - Error Message: {}'.format(err))

return JsonResponse(last_endpoint_metric)



class APISummaryPartialFunctionView(APIMetricsView):
template_name = 'metrics/api_summary_partial_function.html'
Expand Down

0 comments on commit d196ae7

Please sign in to comment.