-
Notifications
You must be signed in to change notification settings - Fork 13
/
views.py
53 lines (45 loc) · 1.61 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from .helpers import muninview
from django.contrib.sessions.models import Session
from datetime import datetime
from datetime import timedelta
import time
from .models import Test
from django.contrib.auth import get_user_model
User = get_user_model()
@muninview(config="""graph_title Total Users
graph_vlabel users""")
def total_users(request):
return [("users",User.objects.all().count())]
@muninview(config="""graph_title Active Users
graph_vlabel users
graph_info Number of users logged in during the last hour""")
def active_users(request):
hour_ago = datetime.now() - timedelta(hours=1)
return [("users",User.objects.filter(last_login__gt=hour_ago).count())]
@muninview(config="""graph_title Total Sessions
graph_vlabel sessions""")
def total_sessions(request):
return [("sessions",Session.objects.all().count())]
@muninview(config="""graph_title Active Sessions
graph_vlabel sessions""")
def active_sessions(request):
return [("sessions",Session.objects.filter(expire_date__gt=datetime.now()).count())]
@muninview(config="""graph_title DB performance
graph_vlabel milliseconds
graph_info performance of simple insert/select/delete operations""")
def db_performance(request):
start = time.time()
t = Test.objects.create(name="inserting at %f" % start)
end = time.time()
insert = end - start
start = time.time()
t2 = Test.objects.get(id=t.id)
end = time.time()
select = end - start
start = time.time()
t2.delete()
end = time.time()
delete = end - start
return [("insert",1000 * insert),
("select",1000 * select),
("delete",1000 * delete)]