Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ca28f1

Browse files
committed
Daily P2P Statistics Command
1 parent 900007d commit 6ca28f1

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

app/Models/P2pDailyStats.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace IXP\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class P2pDailyStats extends Model
9+
{
10+
use HasFactory;
11+
}

app/Utils/Grapher/Rrd.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,16 @@ private function getIndexKeys(): array
309309
* @throws
310310
*/
311311
public function data(): array
312+
{
313+
return $this->dataCollect(time() - self::PERIOD_TIME[ $this->graph()->period() ], time());
314+
}
315+
316+
public function dataCollect($start,$end): array
312317
{
313318
$rrd = rrd_fetch( $this->file, [
314319
'AVERAGE',
315-
'--start', time() - self::PERIOD_TIME[ $this->graph()->period() ]
320+
'--start', $start,
321+
'--end', $end,
316322
]);
317323

318324
if( $rrd === false || !is_array( $rrd ) ) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('p2p_daily_stats', function (Blueprint $table) {
15+
$table->id();
16+
$table->integer('cust_id');
17+
$table->foreign('cust_id')->references('id')->on('cust')->onDelete('cascade');
18+
$table->date('day');
19+
$table->string('peer_id');
20+
$table->integer('ipv4_total_in')->nullable();
21+
$table->integer('ipv4_total_out')->nullable();
22+
$table->integer('ipv6_total_in')->nullable();
23+
$table->integer('ipv6_total_out')->nullable();
24+
$table->integer('ipv4_max_in')->nullable();
25+
$table->integer('ipv4_max_out')->nullable();
26+
$table->integer('ipv6_max_in')->nullable();
27+
$table->integer('ipv6_max_out')->nullable();
28+
$table->timestamps();
29+
});
30+
}
31+
32+
/**
33+
* Reverse the migrations.
34+
*/
35+
public function down(): void
36+
{
37+
Schema::dropIfExists('p2p_daily_stats');
38+
}
39+
};

0 commit comments

Comments
 (0)