Hi Ádler,
Thank you for your reply.
Can you please review this code before I commit?
"""uWSGIController API Version 0.8.3
Middleware for storing uWSGI statistics into the environ object.
"""
import sys
import os
import logging
import demjson
import urllib
logger = logging.getLogger(__name__)
from notmm.controllers.wsgi import WSGIController
__all__ = ('uWSGIController',)
class uWSGIController(WSGIController):
def __init__(self, wsgi_app, stats_url='http://localhost:9001'):
self.wsgi_app = wsgi_app
self.stats_url = stats_url
super(uWSGIController, self).__init__() # hack
def init_request(self, request):
logger.debug('In uWSGIController.init_request...')
request.environ['uwsgi.requests'] =
self.connections(self.stats_url)
self._request = request
self._environ = request.environ
return self._request
def connections(self, url):
"""Return the amount of live connections (requests) for all
workers"""
fp = urllib.urlopen(url)
json = demjson.decode(fp.read())
connections = 0
for worker in json['workers']:
connections += worker['requests']
fp.close()
return connections
Best regards,
Etienne
Le 2017-12-07 à 13:29, Ádler Oliveira Silva Neves a écrit :
Sounds like you want retrieving statistics from uWSGI's stats server.
http://uwsgi-docs.readthedocs.io/en/latest/StatsServer.html
In order to get that JSON via HTTP requests, your server ".ini" should
receive extra arguments to start an stats server listening to the
specified port and application must be somehow aware of such port
number, which has a side-effect of increasing coupling.
Sincerely,
Adler
On 07/12/2017 13:13, Etienne Robillard wrote:
Hi,
I would like to access the uWSGI stats API from within Django by
creating a custom WSGI middleware.
Could it be possible to compute the number of requests currently
being used by uWSGI workers in Python/Django ?
Ideally, i could then retrieve the active connections in use in a
standard Django view:
def someview(request):
# retrieve the number of active requests (connections)
connections = request.environ['uwsgi.requests']
What do you think?
Etienne
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/c6d79973-28b8-5236-a64e-4c24ed3c30a7%40gmail.com
<https://groups.google.com/d/msgid/django-users/c6d79973-28b8-5236-a64e-4c24ed3c30a7%40gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/381c4e78-74b3-74d2-8298-7684820db97e%40yandex.com.
For more options, visit https://groups.google.com/d/optout.