Traffiy Type
This commit is contained in:
parent
a0037a4bc3
commit
ad52bb15a3
6 changed files with 67 additions and 10 deletions
|
@ -43,7 +43,7 @@ class CalculateTraffic extends Command
|
|||
$result = [];
|
||||
$res = DB::select("SELECT * FROM access");
|
||||
foreach($res as $r) {
|
||||
$key = $r->tenant."-".$r->gallery."-".$r->year."-".$r->month."-".$r->day."-".$r->hour;
|
||||
$key = $r->tenant."-".$r->gallery."-".$r->year."-".$r->month."-".$r->day."-".$r->hour."-".$r->typ;
|
||||
if(isset($result[$key])) {
|
||||
$result[$key] = $result[$key] + $r->size;
|
||||
} else {
|
||||
|
@ -64,6 +64,7 @@ class CalculateTraffic extends Command
|
|||
->where("month", "=", (int)$split[3])
|
||||
->where("day", "=", (int)$split[4])
|
||||
->where("hour", "=", (int)$split[5])
|
||||
->where("typ", "=", $this->getTyp($split[6]))
|
||||
->first();
|
||||
} else {
|
||||
$traffic = Traffic::query()
|
||||
|
@ -73,6 +74,7 @@ class CalculateTraffic extends Command
|
|||
->where("month", "=", (int)$split[3])
|
||||
->where("day", "=", (int)$split[4])
|
||||
->where("hour", "=", (int)$split[5])
|
||||
->where("typ", "=", $this->getTyp($split[6]))
|
||||
->first();
|
||||
}
|
||||
|
||||
|
@ -84,6 +86,7 @@ class CalculateTraffic extends Command
|
|||
$traffic->month =$split[3];
|
||||
$traffic->day = $split[4];
|
||||
$traffic->hour = $split[5];
|
||||
$traffic->typ = $this->getTyp($split[6]);
|
||||
$traffic->date = $split[2]."-".$split[3]."-".$split[4];
|
||||
}
|
||||
if($traffic->gallery == "") {
|
||||
|
@ -98,4 +101,14 @@ class CalculateTraffic extends Command
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getTyp($typ) {
|
||||
if($typ == "Access") {
|
||||
return "s3";
|
||||
}
|
||||
if($typ == "Cache") {
|
||||
return "cache";
|
||||
}
|
||||
return "generic";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,11 @@ class ReportController extends BaseController
|
|||
return $res;
|
||||
}
|
||||
|
||||
public function traficReport($year, $month) {
|
||||
public function trafficReport($year, $month) {
|
||||
$reportData = DB::select("SELECT * FROM traffic WHERE tenant = ".(int)session("current_tenant_id")." AND `year` = ".(int)$year." AND `month` = ".(int)$month.";");
|
||||
$report = "year;month;day;hour;gallery;traffic\n";
|
||||
$report = "year;month;day;hour;gallery;typ;traffic\n";
|
||||
foreach ($reportData as $reportLine) {
|
||||
$report .= $reportLine->year.";".$reportLine->month.";".$reportLine->day.";".$reportLine->hour.";".$reportLine->gallery.";".$reportLine->traffic."\n";
|
||||
$report .= $reportLine->year.";".$reportLine->month.";".$reportLine->day.";".$reportLine->hour.";".$reportLine->gallery.";".$reportLine->typ.";".$reportLine->traffic."\n";
|
||||
}
|
||||
|
||||
$res = new Response();
|
||||
|
|
|
@ -47,7 +47,7 @@ class Traffic extends Authenticatable
|
|||
];
|
||||
|
||||
public static function getLastDays(int $days = 7) {
|
||||
$sql = "SELECT year, month, day, SUM(traffic) AS `traffic` FROM traffic WHERE tenant = ".session("current_tenant_id")." GROUP BY year, month, day ORDER BY year, month, day DESC LIMIT ".$days.";";
|
||||
$sql = "SELECT year, month, day, typ, SUM(traffic) AS `traffic` FROM traffic WHERE tenant = ".session("current_tenant_id")." GROUP BY year, month, day, typ ORDER BY year, month, day DESC LIMIT ".$days.";";
|
||||
$res = DB::select($sql);
|
||||
|
||||
$now = new \DateTime( $days." days ago", new \DateTimeZone('UTC'));
|
||||
|
@ -56,10 +56,10 @@ class Traffic extends Authenticatable
|
|||
$result = [];
|
||||
foreach( $period as $day) {
|
||||
$key = $day->format('Y-m-d');
|
||||
$result[$day->format('Y-m-d')] = 0;
|
||||
$result[$day->format('Y-m-d')] = ["cache" => 0, "s3" => 0];
|
||||
foreach($res as $r) {
|
||||
if($r->year == $day->format('Y') && $r->month == $day->format('m') && $r->day == $day->format('d')) {
|
||||
$result[$day->format('Y-m-d')] = $r->traffic / 1000 / 1000;
|
||||
$result[$day->format('Y-m-d')][$r->typ] = $r->traffic / 1000 / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
30
database/migrations/2021_01_21_145341_traffix_typ.php
Normal file
30
database/migrations/2021_01_21_145341_traffix_typ.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class TraffixTyp extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table("traffic", function (Blueprint $table) {
|
||||
$table->enum("typ", ["cache", "s3", "generic"])->default("generic");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@
|
|||
@endforeach],
|
||||
datasets: [
|
||||
{
|
||||
label: "Traffic per Day",
|
||||
label: "Cache Traffic per Day",
|
||||
fillColor: "rgba(220,220,220,0.2)",
|
||||
strokeColor: "rgba(220,220,220,1)",
|
||||
pointColor: "rgba(220,220,220,1)",
|
||||
|
@ -59,7 +59,21 @@
|
|||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data: [
|
||||
@foreach($lastDaysTreffic as $traffic)
|
||||
{{ $traffic }},
|
||||
{{ $traffic["cache"] }},
|
||||
@endforeach
|
||||
]
|
||||
},
|
||||
{
|
||||
label: "S3 Traffic per Day",
|
||||
fillColor: "rgba(220,220,220,0.2)",
|
||||
strokeColor: "rgba(220,220,220,1)",
|
||||
pointColor: "rgba(220,220,220,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data: [
|
||||
@foreach($lastDaysTreffic as $traffic)
|
||||
{{ $traffic["s3"] }},
|
||||
@endforeach
|
||||
]
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
|
|||
Route::get("/s/watermark/delete", [\App\Http\Controllers\TenantController::class, "deleteWatermark"]);
|
||||
Route::get("s/reports", [\App\Http\Controllers\ReportController::class, "showReportList"]);
|
||||
Route::get("s/reports/{year}/{month}/space", [\App\Http\Controllers\ReportController::class, "spaceReport"]);
|
||||
Route::get("s/reports/{year}/{month}/traffic", [\App\Http\Controllers\ReportController::class, "traficReport"]);
|
||||
Route::get("s/reports/{year}/{month}/traffic", [\App\Http\Controllers\ReportController::class, "trafficReport"]);
|
||||
});
|
||||
|
||||
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);
|
||||
|
|
Loading…
Reference in a new issue