This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nikhila05/sample_app
Sample app
- Loading branch information
Showing
45 changed files
with
2,658 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,4 @@ ENV/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
logs/ |
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,14 @@ | ||
language: python | ||
|
||
python: | ||
- "3.4" | ||
|
||
install: | ||
- python setup.py install | ||
- pip install coveralls | ||
|
||
script: | ||
- coverage run --source=testingapp sandbox/manage.py test | ||
|
||
after_success: | ||
coveralls |
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,5 @@ | ||
include README.rst | ||
recursive-include django_web_profiler/templates * | ||
recursive-include django_web_profiler/static * | ||
recursive-include django_web_profiler/management * | ||
recursive-include django_web_profiler/migrations * |
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,113 @@ | ||
django-web-profiler's documentation: | ||
===================================== | ||
|
||
Introduction: | ||
============= | ||
|
||
django-web-profiler is a django profiling tool which logs, stores debug toolbar statistics and also a set of URL's statistics using a management command. It logs request values such as device, ip address, user cpu time, system cpu time, No of queries, sql time, no of cache calls, missing, setting data cache calls for a particular url. | ||
|
||
It provides a basic UI, which will differentiate development url statistics, production level statistics which generates using a management command. | ||
|
||
Source Code is available in Micropyramid Repository(https://github.com/MicroPyramid/django-web-profiler). | ||
|
||
|
||
Modules used: | ||
|
||
* Python >= 2.6 (or Python 3.4) | ||
* Django = 1.11.2 | ||
* Django Compressor = 2.1.1 | ||
* Django Debug Toolbar = 1.8 | ||
* requests = 2.17.3 | ||
* JQuery >= 1.7 | ||
|
||
|
||
Installation Procedure | ||
====================== | ||
|
||
1. Install django-web-packer using the following command:: | ||
|
||
pip install django-web-profiler | ||
|
||
(or) | ||
|
||
git clone git://github.com/micropyramid/django-web-profiler.git | ||
|
||
cd django-web-profiler | ||
|
||
python setup.py install | ||
|
||
2. Add app name in settings.py:: | ||
|
||
INSTALLED_APPS = [ | ||
'..................', | ||
'compressor', | ||
'debug_toolbar', | ||
'django_web_profiler', | ||
'..................' | ||
] | ||
|
||
3. Add 'django_web_profiler.middleware.DebugLoggingMiddleware' to your project middlewares: | ||
|
||
MIDDLEWARE = [ | ||
'..................', | ||
'django_web_profiler.middleware.DebugLoggingMiddleware' | ||
'..................' | ||
] | ||
|
||
Disable 'debug_toolbar.middleware.DebugToolbarMiddleware' if you've already using it. | ||
|
||
4. Make sure that 'debug-toolbar' has enabled for your application. After installing debug toolbar, add the following details to settings.py: | ||
|
||
INTERNAL_IPS = ('127.0.0.1',) | ||
|
||
|
||
5. After installing/cloning, add the following details in settings file about urls, logger names:: | ||
|
||
URLS = ['http://stage.testsite.com/', 'http://stage.testsite.com/testing/'] | ||
|
||
|
||
6. Add the following logger to your existing loggers and create a folder called 'logs' where all profiler log files are stored:: | ||
|
||
'request-logging': { | ||
'level': 'DEBUG', | ||
'handlers': ['console', 'file_log'], | ||
'propagate': False, | ||
}, | ||
|
||
Here file_log is a handler which contains a path where log files are stored. | ||
|
||
|
||
Sample Application | ||
================== | ||
|
||
1. Install application requirements using the following command:: | ||
|
||
pip install -r requirements.txt | ||
|
||
|
||
2. Load the application load using the following command:: | ||
|
||
python sandbox/manage.py loaddata sandbox/fixtures/users.json | ||
|
||
|
||
3. Using the following command, we can generate url statistics in production environment i.e debug=False: | ||
|
||
python sandbox/manage.py logging_urls | ||
|
||
|
||
We are always looking to help you customize the whole or part of the code as you like. | ||
|
||
|
||
Visit our Django Development page `Here`_ | ||
|
||
|
||
We welcome your feedback and support, raise `github ticket`_ if you want to report a bug. Need new features? `Contact us here`_ | ||
|
||
.. _contact us here: https://micropyramid.com/contact-us/ | ||
.. _github ticket: https://github.com/MicroPyramid/django-web-profiler/issues | ||
.. _Here: https://micropyramid.com/django-development-services/ | ||
|
||
or | ||
|
||
mailto:: "[email protected]" | ||
|
Empty file.
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DjangoWebProfilerConfig(AppConfig): | ||
name = 'django_web_profiler' |
Empty file.
Empty file.
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,64 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.management import call_command | ||
import json | ||
from django.conf import settings | ||
import requests | ||
from django.test.client import Client | ||
import logging | ||
from django_web_profiler.models import ProfileLog, ProfileLogRecord | ||
import collections | ||
from datetime import datetime | ||
|
||
|
||
class Command(BaseCommand): | ||
args = '<filename>' | ||
help = 'Loads the initial data in to database' | ||
|
||
def handle(self, *args, **options): | ||
client = Client() | ||
logger1 = logging.getLogger("request-logging") | ||
profile_log = ProfileLog.objects.create(name=datetime.now(), start_time=datetime.now()) | ||
|
||
for url in settings.URLS: | ||
response = client.get(url, DJANGO_DEBUG_LOGGING=True) | ||
request = response.wsgi_request | ||
statistics = request.statistics | ||
total_time = total_user_cpu_time = total_system_cpu_time = total_sql_time = 0.0 | ||
total_sql_queries = total_cache_hits = total_cache_misses = 0 | ||
|
||
if settings.DEBUG: | ||
cache_calls = {k:i for i,k in enumerate(statistics['cache_counts'])} | ||
|
||
total_time += statistics['total_cpu_time'] | ||
total_user_cpu_time += statistics['user_cpu_time'] | ||
total_system_cpu_time += statistics['system_cpu_time'] | ||
total_sql_time += statistics['sql_total_time'] | ||
total_sql_queries += statistics['num_queries'] | ||
total_cache_hits += statistics['cache_total_calls'] | ||
total_cache_misses += statistics['cache_misses'] | ||
ProfileLogRecord.objects.create(profile_log=profile_log, request_path=statistics['path'], ip_address=statistics['ip_address'], device=statistics['device'], | ||
timer_utime=statistics['user_cpu_time'], timer_stime=statistics['system_cpu_time'], timer_cputime=statistics['total_cpu_time'], | ||
sql_num_queries=statistics['num_queries'], sql_time=statistics['sql_total_time'], sql_queries=statistics['num_queries'], | ||
cache_num_calls=statistics['cache_total_calls'], cache_time=statistics['cache_total_time'], cache_hits=statistics['cache_hits'], cache_misses=statistics['cache_misses'], | ||
cache_sets=cache_calls['set'], cache_gets=cache_calls['get'], cache_get_many=cache_calls['get_many'], cache_deletes=cache_calls['delete'], cache_calls=statistics['cache_total_calls']) | ||
|
||
else: | ||
total_time += float(statistics['total_cpu_time']) | ||
total_user_cpu_time += float(statistics['user_cpu_time']) | ||
total_system_cpu_time += float(statistics['system_cpu_time']) | ||
|
||
ProfileLogRecord.objects.create(profile_log=profile_log, request_path=statistics['path'], ip_address=statistics['ip_address'], device=statistics['device'], | ||
timer_utime=statistics['user_cpu_time'], timer_stime=statistics['system_cpu_time'], timer_cputime=statistics['total_cpu_time']) | ||
profile_log_records = ProfileLogRecord.objects.filter(profile_log=profile_log) | ||
profile_log.total_requests = len(settings.URLS) | ||
profile_log.avg_time = (total_time/len(settings.URLS)) | ||
profile_log.total_time = total_time | ||
profile_log.avg_cpu_time = total_user_cpu_time/len(settings.URLS) | ||
profile_log.total_user_cpu_time = total_user_cpu_time | ||
profile_log.total_system_cpu_time = total_system_cpu_time | ||
profile_log.end_time = datetime.now() | ||
profile_log.save() | ||
|
||
result = {'message': "Successfully Loading initial data"} | ||
|
||
return json.dumps(result) |
Oops, something went wrong.