mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 15:06:48 +00:00
Merge pull request #346 from hongwei1/develop
feature/added the lastEndpoint info on metric page
This commit is contained in:
commit
edba69ada0
16
apimanager/metrics/static/metrics/js/lastEndpointMetric.js
Normal file
16
apimanager/metrics/static/metrics/js/lastEndpointMetric.js
Normal file
@ -0,0 +1,16 @@
|
||||
$(document).ready(function($) {
|
||||
getMetricLastEndpoint();
|
||||
});
|
||||
|
||||
function getMetricLastEndpoint(){
|
||||
$.ajax({url: "/metrics/api/last-endpoint", success: function(result){
|
||||
var content = ""
|
||||
+result['implemented_by_partial_function']+" took "
|
||||
+result['duration']+" ms at "
|
||||
+result['date']+" "
|
||||
+result['verb']+" "
|
||||
+ result['url'];
|
||||
$("#last_endpoint").text(content);
|
||||
setTimeout(function(){getMetricLastEndpoint();}, 5000); // will call function to update time every 5 seconds
|
||||
}});
|
||||
}
|
||||
@ -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">
|
||||
@ -12,7 +14,7 @@
|
||||
{{ form.media }} {# Form required JS and CSS #}
|
||||
{% endblock %}
|
||||
<h1>{% trans "API Metrics" %}</h1>
|
||||
|
||||
<p id ="last_endpoint">getBanks took 43ms at 2023-12-06T11:00:49Z GET /obp/v4.0.0/banks ms. </p>
|
||||
<div id="metrics-filter">
|
||||
<h2>{% trans "Filter" %}</h2>
|
||||
<form action="" method="get">
|
||||
|
||||
@ -15,13 +15,17 @@ from .views import (
|
||||
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'),
|
||||
|
||||
@ -10,6 +10,7 @@ from datetime import datetime, timedelta
|
||||
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
|
||||
@ -201,6 +202,26 @@ class APIMetricsView(MetricsView):
|
||||
})
|
||||
return context
|
||||
|
||||
def get_metric_last_endpoint(request):
|
||||
to_date = datetime.datetime.now().strftime(settings.API_DATE_FORMAT_WITH_MILLISECONDS)
|
||||
urlpath = "/management/metrics?limit=1&to_date="+to_date
|
||||
api = API(request.session.get('obp'))
|
||||
last_endpoint_metric={}
|
||||
try:
|
||||
metric = api.get(urlpath)['metrics'][0]
|
||||
last_endpoint_metric={
|
||||
'implemented_by_partial_function':metric['implemented_by_partial_function'],
|
||||
'duration': metric['duration'],
|
||||
'date': metric['date'],
|
||||
'verb': metric['verb'],
|
||||
'url': metric['url']
|
||||
}
|
||||
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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user