added prometheus couter for language changes
This commit is contained in:
parent
e0e38ff699
commit
4d8cc8b989
2 changed files with 18 additions and 1 deletions
|
@ -6,7 +6,7 @@
|
|||
<div class="narrow">
|
||||
<h2>{% trans 'Pick your language' %}</h2>
|
||||
|
||||
<form action="{% url 'set_language' %}" method="post">
|
||||
<form action="{{ request.path }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input name="next" type="hidden" value="{% url 'site.index' %}" />
|
||||
{% get_current_language as CURRENT_LANGUAGE %}
|
||||
|
|
|
@ -25,6 +25,7 @@ from django.utils.translation import ngettext_lazy
|
|||
from django.views.decorators.cache import cache_control, never_cache
|
||||
from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
from django.views.decorators.http import etag
|
||||
from django.views.i18n import LANGUAGE_QUERY_PARAMETER, set_language
|
||||
|
||||
from c3nav import __version__ as c3nav_version
|
||||
from c3nav.api.models import Secret
|
||||
|
@ -44,6 +45,10 @@ from c3nav.site.forms import APISecretForm, DeleteAccountForm, PositionForm, Pos
|
|||
from c3nav.site.models import Announcement, SiteUpdate
|
||||
|
||||
|
||||
if settings.METRICS:
|
||||
from prometheus_client import Counter
|
||||
|
||||
|
||||
def check_location(location: Optional[str], request) -> Optional[SpecificLocation]:
|
||||
if location is None:
|
||||
return None
|
||||
|
@ -462,7 +467,19 @@ def access_redeem_view(request, token):
|
|||
})
|
||||
|
||||
|
||||
language_change_counter = None
|
||||
if settings.METRICS:
|
||||
language_change_counter = Counter('language_change', 'Language changes', ['language'])
|
||||
for lang_code, lang_name in settings.LANGUAGES:
|
||||
language_change_counter.labels(lang_code)
|
||||
|
||||
|
||||
def choose_language(request):
|
||||
if request.method == 'POST':
|
||||
lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)
|
||||
if language_change_counter:
|
||||
language_change_counter.labels(lang_code).inc()
|
||||
return set_language(request)
|
||||
return render(request, 'site/language.html', {})
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue