Skip to content

Commit

Permalink
Ajoute des statistiques Munin concernant les membres (#6639)
Browse files Browse the repository at this point in the history
- le nombre de membres bannis
- le nombre de membres qui ont l'attribut `is_active=True`
- le nombre de membres qui se sont connectés au moins une fois
  • Loading branch information
philippemilink authored Sep 7, 2024
1 parent f3a93ab commit cefa2cb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
11 changes: 9 additions & 2 deletions django_munin/munin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db.models import Q
from .helpers import muninview
from .models import Test

Expand All @@ -14,10 +15,16 @@

@muninview(
config="""graph_title Total Users
graph_vlabel users"""
graph_vlabel users
graph_args --lower-limit 0
graph_scale no"""
)
def total_users(request):
return [("users", User.objects.all().count())]
return [
("users", User.objects.all().count()),
("confirmed_users", User.objects.filter(is_active=True).count()),
("logged_once_users", User.objects.filter(~Q(last_login=None)).count()),
]


@muninview(
Expand Down
16 changes: 16 additions & 0 deletions zds/munin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def setUp(self):
"base:total-sessions",
"base:active-sessions",
"base:db-performance",
"banned-users",
"total-topics",
"total-posts",
"total-mp",
Expand Down Expand Up @@ -44,3 +45,18 @@ def test_sessions(self):

response = self.client.get(reverse("munin:base:total-sessions"))
self.assertEqual(response.content.decode(), "sessions 1")

def test_banned_users(self):
response = self.client.get(reverse("munin:banned-users"))
self.assertEqual(response.content.decode(), "banned_users 0")

profile = ProfileFactory()

response = self.client.get(reverse("munin:banned-users"))
self.assertEqual(response.content.decode(), "banned_users 0")

profile.can_read = False
profile.save()

response = self.client.get(reverse("munin:banned-users"))
self.assertEqual(response.content.decode(), "banned_users 1")
11 changes: 10 additions & 1 deletion zds/munin/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from django.urls import path, include

from zds.munin.views import total_topics, total_posts, total_mps, total_tutorials, total_articles, total_opinions
from zds.munin.views import (
banned_users,
total_topics,
total_posts,
total_mps,
total_tutorials,
total_articles,
total_opinions,
)


urlpatterns = [
path("", include(("django_munin.munin.urls", "base"))),
path("banned_users/", banned_users, name="banned-users"),
path("total_topics/", total_topics, name="total-topics"),
path("total_posts/", total_posts, name="total-posts"),
path("total_mps/", total_mps, name="total-mp"),
Expand Down
11 changes: 11 additions & 0 deletions zds/munin/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from django_munin.munin.helpers import muninview
from zds.forum.models import Topic, Post
from zds.member.models import Profile
from zds.mp.models import PrivateTopic, PrivatePost
from zds.tutorialv2.models.database import PublishableContent, ContentReaction


@muninview(
config="""graph_title Banned Users
graph_vlabel Banned Users
graph_args --lower-limit 0
graph_scale no"""
)
def banned_users(request):
return [("banned_users", Profile.objects.filter(can_read=False, end_ban_read=None).count())]


@muninview(
config="""graph_title Total Topics
graph_vlabel topics"""
Expand Down

0 comments on commit cefa2cb

Please sign in to comment.