Skip to content

Commit

Permalink
Django. Basic uWSGI information exposed via Admin contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Sep 11, 2019
1 parent ec2bbd7 commit a1e5b3c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uwsgiconf changelog
Unreleased
----------
! Dropped QA for Python 2.
+ Django. Basic uWSGI information exposed via Admin contrib.
* Django. Fixed uwsgify default config loading.
* Fixed 'is_stub' attribute binding to uwsgi/uwsgi_stub modules.
* Runtime. Fixed 'environ.uwsgi_env.buffer_size' value.
Expand Down
7 changes: 7 additions & 0 deletions uwsgiconf/contrib/django/uwsgify/admin/__init__.py
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)
30 changes: 30 additions & 0 deletions uwsgiconf/contrib/django/uwsgify/admin/base.py
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
20 changes: 20 additions & 0 deletions uwsgiconf/contrib/django/uwsgify/admin/models.py
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')
35 changes: 35 additions & 0 deletions uwsgiconf/contrib/django/uwsgify/admin/realms.py
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,
})
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 %}

0 comments on commit a1e5b3c

Please sign in to comment.