-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Django. Basic uWSGI information exposed via Admin contrib
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Summary, Configuration | ||
from .realms import SummaryAdmin, ConfigurationAdmin | ||
|
||
admin.site.register(Summary, SummaryAdmin) | ||
admin.site.register(Configuration, ConfigurationAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.contrib import admin | ||
from django.template.response import TemplateResponse | ||
from django.urls import path | ||
|
||
from uwsgiconf import uwsgi | ||
|
||
|
||
class OnePageAdmin(admin.ModelAdmin): | ||
|
||
def get_urls(self): | ||
info = self.model._meta.app_label, self.model._meta.model_name | ||
|
||
urlpatterns = [ | ||
path('', self.admin_site.admin_view(self.view_onepage), name='%s_%s_changelist' % info) | ||
] | ||
|
||
return urlpatterns | ||
|
||
def view_onepage(self, request): | ||
context = dict( | ||
self.admin_site.each_context(request), | ||
|
||
stub=uwsgi.is_stub, | ||
title=self.opts.verbose_name, | ||
) | ||
self.contribute_onepage_context(request, context) | ||
return TemplateResponse(request, 'admin/uwsgify/onepage.html', context) | ||
|
||
def contribute_onepage_context(self, request, context): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class Summary(models.Model): | ||
|
||
class Meta: | ||
app_label = 'uwsgify' | ||
managed = False | ||
verbose_name = _('Summary') | ||
verbose_name_plural = _('Summary') | ||
|
||
|
||
class Configuration(models.Model): | ||
|
||
class Meta: | ||
app_label = 'uwsgify' | ||
managed = False | ||
verbose_name = _('Configuration') | ||
verbose_name_plural = _('Configuration') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from collections import OrderedDict | ||
|
||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from uwsgiconf.runtime.environ import uwsgi_env | ||
from .base import OnePageAdmin | ||
|
||
|
||
class SummaryAdmin(OnePageAdmin): | ||
|
||
def contribute_onepage_context(self, request, context): | ||
context.update({ | ||
'info': OrderedDict([ | ||
(_('Version'), uwsgi_env.get_version()), | ||
(_('Hostname'), uwsgi_env.hostname), | ||
(_('Started'), uwsgi_env.started_on), | ||
(_('Cores'), uwsgi_env.cores_count), | ||
(_('Workers'), uwsgi_env.workers_count), | ||
(_('Buffer'), uwsgi_env.buffer_size), | ||
(_('Clock'), uwsgi_env.clock), | ||
(_('Master PID'), uwsgi_env.master_pid), | ||
(_('Memory'), uwsgi_env.memory), | ||
(_('Threads support'), uwsgi_env.threads_enabled), | ||
(_('Current worker'), uwsgi_env.worker_id), | ||
(_('Requests served'), uwsgi_env.request.total_count), | ||
]), | ||
}) | ||
|
||
|
||
class ConfigurationAdmin(OnePageAdmin): | ||
|
||
def contribute_onepage_context(self, request, context): | ||
context.update({ | ||
'info': uwsgi_env.config, | ||
}) |
28 changes: 28 additions & 0 deletions
28
uwsgiconf/contrib/django/uwsgify/templates/admin/uwsgify/onepage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% extends "admin/base_site.html" %} | ||
{% load i18n static %} | ||
|
||
{% block content %} | ||
|
||
{% if stub %} | ||
<p class="errornote"> | ||
{% trans "This site is not served by uWSGI. Some functionality may be unavailable." %} | ||
</p> | ||
{% endif %} | ||
|
||
|
||
<div class="results"> | ||
|
||
<table width="100%"> | ||
<thead></thead> | ||
<tbody> | ||
{% for key, val in info.items %} | ||
<tr class="{% cycle 'row1' 'row2' %}"> | ||
<td nowrap width="25%">{{ key }}:</td> | ||
<td>{{ val }}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
</div> | ||
|
||
{% endblock %} |