feat: add player and webrtc statistics aggregation scripts, update subproject reference, and include latency images
Some checks failed
Build LaTeX Document / build_latex (push) Has been cancelled
Some checks failed
Build LaTeX Document / build_latex (push) Has been cancelled
This commit is contained in:
103
peertube/datavis/CRUD/player-statistics.js
Normal file
103
peertube/datavis/CRUD/player-statistics.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/* global use, db */
|
||||
// MongoDB Playground
|
||||
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
|
||||
// Make sure you are connected to enable completions and to be able to run a playground.
|
||||
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
|
||||
// The result of the last command run in a playground is shown on the results panel.
|
||||
// By default the first 20 documents will be returned with a cursor.
|
||||
// Use 'console.log()' to print to the debug output.
|
||||
// For more documentation on playgrounds please refer to
|
||||
// https://www.mongodb.com/docs/mongodb-vscode/playgrounds/
|
||||
|
||||
// Select the database to use.
|
||||
use('statistics');
|
||||
|
||||
// Insert a few documents into the sales collection.
|
||||
db.getCollection('peertube_hetzner_high_latency').aggregate(
|
||||
[
|
||||
{
|
||||
$group: {
|
||||
_id: "$tags.session",
|
||||
maxDownPeers: {
|
||||
$max: "$player.Download Breakdown.Peers"
|
||||
},
|
||||
maxDownServer: {
|
||||
$max: "$player.Download Breakdown.Server"
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalDownPeers: {
|
||||
$sum: "$maxDownPeers"
|
||||
},
|
||||
totalDownServer: {
|
||||
$sum: "$maxDownServer"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
totalDownPeers: 1,
|
||||
totalDownServer: 1,
|
||||
totalComputedDown: {
|
||||
$sum: [
|
||||
"$totalDownPeers",
|
||||
"$totalDownServer"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
totalDownPeers: 1,
|
||||
totalDownServer: 1,
|
||||
totalComputedDown: 1,
|
||||
percentageOfTotalPeers: {
|
||||
$round: {
|
||||
$multiply: [
|
||||
{
|
||||
$divide: [
|
||||
"$totalDownPeers",
|
||||
"$totalComputedDown"
|
||||
]
|
||||
},
|
||||
100
|
||||
]
|
||||
}
|
||||
},
|
||||
percentageOfTotalServer: {
|
||||
$round: {
|
||||
$multiply: [
|
||||
{
|
||||
$divide: [
|
||||
"$totalDownServer",
|
||||
"$totalComputedDown"
|
||||
]
|
||||
},
|
||||
100
|
||||
]
|
||||
}
|
||||
},
|
||||
ratio: {
|
||||
$round: {
|
||||
$divide: [
|
||||
"$totalDownPeers",
|
||||
"$totalDownServer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
ratio: -1
|
||||
}
|
||||
},
|
||||
{
|
||||
$limit: 10
|
||||
}
|
||||
]
|
||||
)
|
255
peertube/datavis/CRUD/webrtc-statistics.js
Normal file
255
peertube/datavis/CRUD/webrtc-statistics.js
Normal file
@@ -0,0 +1,255 @@
|
||||
/* global use, db */
|
||||
// MongoDB Playground
|
||||
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
|
||||
// Make sure you are connected to enable completions and to be able to run a playground.
|
||||
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
|
||||
// The result of the last command run in a playground is shown on the results panel.
|
||||
// By default the first 20 documents will be returned with a cursor.
|
||||
// Use 'console.log()' to print to the debug output.
|
||||
// For more documentation on playgrounds please refer to
|
||||
// https://www.mongodb.com/docs/mongodb-vscode/playgrounds/
|
||||
use("statistics");
|
||||
|
||||
let formattedDate = (date) => ({
|
||||
unix: { $toLong: date },
|
||||
iso: { $toString: date },
|
||||
});
|
||||
|
||||
// Find the minimum timestamp and calculate the maximum timestamp (one hour later) for a collection
|
||||
function getTimeWindow(collectionName) {
|
||||
const minTimestamp = db.getCollection(collectionName).aggregate([
|
||||
{ $sort: { timestamp: 1 } },
|
||||
{ $limit: 1 },
|
||||
{ $project: { _id: 0, timestamp: 1 } }
|
||||
]).toArray()[0]?.timestamp;
|
||||
|
||||
if (!minTimestamp) return null;
|
||||
|
||||
const maxTimestamp = new Date(minTimestamp.getTime() + 60 * 60 * 1000);
|
||||
return { minTimestamp, maxTimestamp };
|
||||
}
|
||||
|
||||
// Get time windows for both collections
|
||||
const highLatencyTimeWindow = getTimeWindow("peertube_hetzner_high_latency");
|
||||
const defaultLatencyTimeWindow = getTimeWindow("peertube_hetzner_default_latency");
|
||||
|
||||
// Function to perform the aggregation for a given collection
|
||||
function getAggregationResult(collectionName, timeWindow) {
|
||||
if (!timeWindow) return [];
|
||||
|
||||
return db.getCollection(collectionName).aggregate([
|
||||
// Filter documents within the collection's specific time window
|
||||
{
|
||||
$match: {
|
||||
timestamp: {
|
||||
$gte: timeWindow.minTimestamp,
|
||||
$lt: timeWindow.maxTimestamp
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: "$peers"
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
"peers.iceConnectionState": "connected"
|
||||
}
|
||||
},
|
||||
{
|
||||
$unwind: "$peers.values"
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
"peers.values.type": "data-channel",
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$peers.id",
|
||||
maxBytesReceived: {
|
||||
$max: "$peers.values.bytesReceived"
|
||||
},
|
||||
maxBytesSent: {
|
||||
$max: "$peers.values.bytesSent"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalMaxBytesReceived: {
|
||||
$sum: "$maxBytesReceived"
|
||||
},
|
||||
totalMaxBytesSent: {
|
||||
$sum: "$maxBytesSent"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
collection: collectionName,
|
||||
totalBytesReceived: "$totalMaxBytesReceived",
|
||||
totalBytesSent: "$totalMaxBytesSent",
|
||||
formattedBytesReceived: {
|
||||
$switch: {
|
||||
branches: [
|
||||
{
|
||||
case: {
|
||||
$gte: [
|
||||
"$totalMaxBytesReceived",
|
||||
1073741824 // 1024^3
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesReceived",
|
||||
1073741824 // 1024^3
|
||||
]
|
||||
}
|
||||
},
|
||||
" GiB"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
case: {
|
||||
$gte: [
|
||||
"$totalMaxBytesReceived",
|
||||
1048576 // 1024^2
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesReceived",
|
||||
1048576 // 1024^2
|
||||
]
|
||||
}
|
||||
},
|
||||
" MiB"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
case: {
|
||||
$gte: [
|
||||
"$totalMaxBytesReceived",
|
||||
1024 // 1024^1
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesReceived",
|
||||
1024 // 1024^1
|
||||
]
|
||||
}
|
||||
},
|
||||
" KiB"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
default: {
|
||||
$concat: [
|
||||
{
|
||||
$toString:
|
||||
"$totalMaxBytesReceived"
|
||||
},
|
||||
" bytes"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
formattedBytesSent: {
|
||||
$switch: {
|
||||
branches: [
|
||||
{
|
||||
case: {
|
||||
$gte: [
|
||||
"$totalMaxBytesSent",
|
||||
1073741824 // 1024^3
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesSent",
|
||||
1073741824 // 1024^3
|
||||
]
|
||||
}
|
||||
},
|
||||
" GiB"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
case: {
|
||||
$gte: [
|
||||
"$totalMaxBytesSent",
|
||||
1048576 // 1024^2
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesSent",
|
||||
1048576 // 1024^2
|
||||
]
|
||||
}
|
||||
},
|
||||
" MiB"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
case: {
|
||||
$gte: ["$totalMaxBytesSent", 1024] // 1024^1
|
||||
},
|
||||
then: {
|
||||
$concat: [
|
||||
{
|
||||
$toString: {
|
||||
$divide: [
|
||||
"$totalMaxBytesSent",
|
||||
1024 // 1024^1
|
||||
]
|
||||
}
|
||||
},
|
||||
" KiB"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
default: {
|
||||
$concat: [
|
||||
{ $toString: "$totalMaxBytesSent" },
|
||||
" bytes"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]).toArray();
|
||||
}
|
||||
|
||||
// Get results from both collections using their respective time windows
|
||||
const highLatencyResults = getAggregationResult("peertube_hetzner_high_latency", highLatencyTimeWindow);
|
||||
const defaultLatencyResults = getAggregationResult("peertube_hetzner_default_latency", defaultLatencyTimeWindow);
|
||||
|
||||
// Combine and return the results
|
||||
const combinedResults = [...highLatencyResults, ...defaultLatencyResults];
|
||||
combinedResults;
|
Submodule peertube/statnerd updated: fbd87e01c5...2b18644024
Reference in New Issue
Block a user