File transfer
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Collect Network Metrics Job — runs every 10 seconds per node.
|
||||
*
|
||||
* @author Ball Studios <https://git.balls.studio>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Addons\AdvancedAdmin\Jobs\Network;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Pterodactyl\Addons\AdvancedAdmin\Services\Network\DockerStatsCollector;
|
||||
use Pterodactyl\Models\Node;
|
||||
|
||||
class CollectNetworkMetricsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public int $tries = 1;
|
||||
public int $timeout = 30;
|
||||
|
||||
public function handle(DockerStatsCollector $collector): void
|
||||
{
|
||||
if (!config('advanced-admin.network.enabled')) return;
|
||||
|
||||
$nodes = Node::all();
|
||||
$now = now();
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
$stats = $collector->collectForNode($node);
|
||||
if (empty($stats)) continue;
|
||||
|
||||
// Batch insert for efficiency
|
||||
$rows = array_map(fn ($s) => [
|
||||
'server_id' => $s['server_id'],
|
||||
'node_id' => $s['node_id'],
|
||||
'rx_bytes' => $s['rx_bytes'],
|
||||
'tx_bytes' => $s['tx_bytes'],
|
||||
'resolution' => 'raw',
|
||||
'recorded_at' => $now,
|
||||
'created_at' => $now,
|
||||
], $stats);
|
||||
|
||||
DB::table('addon_network_metrics')->insert($rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user