Providing /stats to give us basic reporting on number of nodes and packets seen by the tool

This commit is contained in:
Pablo Revilla
2025-01-17 11:52:42 -08:00
parent 35da39e079
commit 4bcc7b08d0
6 changed files with 1128 additions and 31 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
env/*
__pycache__/*
packets.db
/table_details.py

View File

@@ -28,7 +28,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser('meshview')
parser.add_argument('--bind', nargs='*', default=['*'])
parser.add_argument('--acme-challenge')
parser.add_argument('--port', default=8080, type=int)
parser.add_argument('--port', default=8081, type=int)
parser.add_argument('--tls-cert')
parser.add_argument('--mqtt-server', default='mqtt.bayme.sh')

View File

@@ -12,6 +12,29 @@ from meshview.models import Packet, PacketSeen, Node, Traceroute
from meshview import notify
# We count the total amount of packages
async def get_total_packet_count():
async with database.async_session() as session:
q = select(func.count(Packet.id)) # Use SQLAlchemy's func to count packets
result = await session.execute(q)
return result.scalar() # Return the total count of packets
# We count the total amount of nodes
async def get_total_node_count():
async with database.async_session() as session:
q = select(func.count(Node.id)) # Use SQLAlchemy's func to count nodes
result = await session.execute(q)
return result.scalar() # Return the total count of nodes
# We count the total amount of seen packets
async def get_total_packet_seen_count():
async with database.async_session() as session:
q = select(func.count(PacketSeen.node_id)) # Use SQLAlchemy's func to count nodes
result = await session.execute(q)
return result.scalar() # Return the total count of seen packets
async def process_envelope(topic, env):
if not env.packet.id:
return
@@ -266,3 +289,6 @@ async def get_mqtt_neighbors(since):
)
return result

View File

@@ -26,19 +26,19 @@
}
#details_map {
width: 100%;
height: 300px;
height: 500px;
}
{% block css %}
{% endblock %}
</style>
</head>
<body hx-indicator="#spinner">
<div style="text-align:center"><strong>Bay Area Mesh - http://bayme.sh</strong></div>
<div style="text-align:center"><a href="/">Search for a node </a>&nbsp;-&nbsp;<a href="/graph/network">See a realtime graph of the network </a>&nbsp;-&nbsp;<a href="/chat">See what people are saying </a>&nbsp;-&nbsp;<a href="/firehose">See <strong>everything</strong> </a> </div><br>
<div id="spinner" class="spinner-border secondary-primary htmx-indicator position-absolute top-50 start-50" role="status">
<br><div style="text-align:center"><strong>Bay Area Mesh - http://bayme.sh</strong></div>
<div style="text-align:center">Quick Links:&nbsp;&nbsp;<a href="/">Search for a node </a>&nbsp;-&nbsp;<a href="/chat">Conversations</a>&nbsp;-&nbsp;<a href="/firehose">See <strong>everything</strong> </a>&nbsp;-&nbsp;<a href="/graph/network">Mesh Graph </a></div><br> <div id="spinner" class="spinner-border secondary-primary htmx-indicator position-absolute top-50 start-50" role="status">
<span class="visually-hidden">Loading...</span>
</div>
{% block body %}
{% endblock %}
<br><div style="text-align:center">Visit <strong><a href="https://github.com/pablorevilla-meshtastic/meshview">Meshview</a></strong> on Github. Also visit the original <a href="https://github.com/armooo/meshview">Meshview</a> by Armooo.</div><br>
</body>
</html>

View File

@@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block css %}
#packet_details{
height: 95vh;
overflow: scroll;
}
{% endblock %}
{% block body %}
<div style="font-family: Arial, sans-serif; color: #333; background-color: #f9f9f9; padding: 15px; border-radius: 8px; max-width: 300px; margin: auto;">
<p style="font-size: 18px; font-weight: bold; margin-bottom: 10px;">Total Nodes: <span style="font-weight: normal; color: #007bff;">{{ total_nodes }}</span></p>
<p style="font-size: 18px; font-weight: bold; margin-bottom: 10px;">Total Packets: <span style="font-weight: normal; color: #007bff;">{{ total_packets }}</span></p>
<p style="font-size: 18px; font-weight: bold;">Total MQQT Reports: <span style="font-weight: normal; color: #007bff;">{{ total_packets_seen }}</span></p>
</div>
{% endblock body %}

File diff suppressed because it is too large Load Diff