Implement network statistics

This commit is contained in:
Mark Veidemanis 2022-07-25 19:08:28 +01:00
parent 1c4d87e662
commit c993bb9c6e
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
5 changed files with 108 additions and 114 deletions

View File

@ -1,5 +1,6 @@
from core.lib.threshold import threshold_request from core.lib.threshold import threshold_request
def get_irc_stats(): def get_irc_stats():
url = "irc/stats" url = "irc/stats"
payload = {} payload = {}
@ -8,10 +9,11 @@ def get_irc_stats():
return {} return {}
return stats return stats
def get_irc_networks(): def get_irc_networks():
url = "irc/networks" url = "irc/networks"
payload = {} payload = {}
networks = threshold_request(url, payload) networks = threshold_request(url, payload)
if not networks: if not networks:
return {} return {}
return networks return networks

View File

@ -2,33 +2,33 @@
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<table class="table is-fullwidth is-hoverable"> <table class="table is-fullwidth is-hoverable">
<thead> <thead>
<th>name</th> <th>net</th>
<th>relays</th> <th>relays</th>
<th>channels</th> <th>channels</th>
<th>records</th> <th>records</th>
</thead> </thead>
{% for key, net in networks.items %} {% for key, net in networks.items %}
<tr> <tr>
<th>{{ key }}</th> <th>{{ key }}</th>
<td> <td>
<span class="icon has-text-info has-tooltip-info"> <span class="icon has-text-info has-tooltip-info">
<i class="fa-brands fa-unity"></i> <i class="fa-brands fa-unity"></i>
</span> </span>
{{ net.relays }} {{ net.relays }}
</td> </td>
<td> <td>
<span class="icon has-text-info has-tooltip-info"> <span class="icon has-text-info has-tooltip-info">
<i class="fa-solid fa-hashtag"></i> <i class="fa-solid fa-hashtag"></i>
</span> </span>
{{ net.channels }} {{ net.channels }}
</td> </td>
<td> <td>
<span class="icon has-text-info has-tooltip-info"> <span class="icon has-text-info has-tooltip-info">
<i class="fa-solid fa-album"></i> <i class="fa-solid fa-album"></i>
</span> </span>
{{ net.records }} {{ net.records }}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</div> </div>

View File

@ -1,57 +1,49 @@
<div id="stats"> <div id="stats">
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">
<table class="table is-fullwidth is-hoverable">
<table class="table is-fullwidth is-hoverable"> <thead>
<thead> <tr>
<tr> <th>attribute</th>
<th>X</th> <th>count</th>
<th>total</th> </tr>
<th>unique</th> </thead>
</tr> <tbody>
</thead> <tr>
<tbody> <th>relays</th>
<tr> <td>
<th>total</th> {{ stats.servers_online_total }}/{{ stats.servers_total_total }}
<td> </td>
{{ stats.servers_total_total }} </tr>
</td> <tr>
<td> <th>networks</th>
{{ stats.servers_total_unique }} <td>
</td> {{ stats.servers_online_unique }}/{{ stats.servers_total_unique }}
</tr> </td>
<tr> </tr>
<th>online</th>
<td>
{{ stats.servers_online_total }}
</td>
<td>
{{ stats.servers_online_unique }}
</td>
</tr>
<tr> <tr>
<th>channels</th> <th>channels</th>
<td> <td>
{{ stats.channels}} {{ stats.channels}}
</td> </td>
</tr> </tr>
<tr> <tr>
<th>records</th> <th>records</th>
<td> <td>
{{ stats.records }} {{ stats.records }}
</td> </td>
</tr> </tr>
<tr> <tr>
<th>events</th> <th>events</th>
<td> <td>
{{ stats.eventrate }} {{ stats.eventrate }}
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,51 +1,51 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<div <div
style="display: none;" style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_stats' %}" hx-post="{% url 'threshold_irc_stats' %}"
hx-trigger="load" hx-trigger="load"
hx-target="#stats" hx-target="#stats"
hx-swap="outerHTML"> hx-swap="outerHTML">
</div> </div>
<div <div
style="display: none;" style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_networks' %}" hx-post="{% url 'threshold_irc_networks' %}"
hx-trigger="load" hx-trigger="load"
hx-target="#networks" hx-target="#networks"
hx-swap="outerHTML"> hx-swap="outerHTML">
</div> </div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<div class="box"> <div class="box">
<div id="stats"> <div id="stats">
</div>
</div>
</div>
<div class="column">
<div class="box">
<div id="networks">
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="column">
<div class="box">
<div id="networks">
</div>
</div>
</div>
</div>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<div class="box"> <div class="box">
<div id="channels"> <div id="channels">
</div>
</div>
</div>
<div class="column">
<div class="box">
<div id="alerts">
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="column">
<div class="box">
<div id="alerts">
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}

View File

@ -1,12 +1,13 @@
from django.views import View
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from core.lib.manage.threshold import get_irc_networks, get_irc_stats
from core.views.manage.permissions import SuperUserRequiredMixin from core.views.manage.permissions import SuperUserRequiredMixin
from core.lib.manage.threshold import get_irc_stats, get_irc_networks
class ThresholdIRCStats(SuperUserRequiredMixin, View): class ThresholdIRCStats(SuperUserRequiredMixin, View):
stats_template = "dynamic/manage/threshold/irc/stats.html" stats_template = "dynamic/manage/threshold/irc/stats.html"
def post(self, request): def post(self, request):
stats = get_irc_stats() stats = get_irc_stats()
context = {"stats": stats} context = {"stats": stats}
@ -16,8 +17,7 @@ class ThresholdIRCStats(SuperUserRequiredMixin, View):
class ThresholdIRCNetworks(SuperUserRequiredMixin, View): class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
stats_template = "dynamic/manage/threshold/irc/networks.html" stats_template = "dynamic/manage/threshold/irc/networks.html"
def post(self, request): def post(self, request):
stats = get_irc_networks() stats = get_irc_networks()
context = {"networks": stats} context = {"networks": stats}
return render(request, self.stats_template, context) return render(request, self.stats_template, context)