mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Log query analytics
This commit is contained in:
parent
61828d412a
commit
f26948b76f
65
app/DataMapper/Analytics/DbQuery.php
Normal file
65
app/DataMapper/Analytics/DbQuery.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\DataMapper\Analytics;
|
||||
|
||||
class DbQuery
|
||||
{
|
||||
/**
|
||||
* The type of Sample.
|
||||
*
|
||||
* Monotonically incrementing counter
|
||||
*
|
||||
* - counter
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'mixed_metric';
|
||||
|
||||
/**
|
||||
* The name of the counter.
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'db.queries';
|
||||
|
||||
/**
|
||||
* The datetime of the counter measurement.
|
||||
*
|
||||
* date("Y-m-d H:i:s")
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
public $datetime;
|
||||
|
||||
/**
|
||||
* The Class failure name
|
||||
* set to 0.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $string_metric5 = 'uri';
|
||||
public $string_metric6 = 'uri';
|
||||
|
||||
/**
|
||||
* The counter
|
||||
* set to 1.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $int_metric1 = 1;
|
||||
|
||||
public $double_metric2 = 1;
|
||||
|
||||
public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2) {
|
||||
$this->string_metric5 = $string_metric5;
|
||||
$this->double_metric2 = $double_metric2;
|
||||
}
|
||||
}
|
@ -11,10 +11,13 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\DataMapper\Analytics\DbQuery;
|
||||
use App\Utils\Ninja;
|
||||
use Closure;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Turbo124\Beacon\Facades\LightLogs;
|
||||
|
||||
/**
|
||||
* Class QueryLogging.
|
||||
@ -31,32 +34,33 @@ class QueryLogging
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$timeStart = microtime(true);
|
||||
|
||||
// Enable query logging for development
|
||||
if (config('ninja.app_env') == 'production') {
|
||||
if (!Ninja::isHosted() || !config('beacon.enabled')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$timeStart = microtime(true);
|
||||
DB::enableQueryLog();
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
if (config('ninja.app_env') != 'production') {
|
||||
// hide requests made by debugbar
|
||||
if (strstr($request->url(), '_debugbar') === false) {
|
||||
|
||||
// hide requests made by debugbar
|
||||
if (strstr($request->url(), '_debugbar') === false) {
|
||||
$queries = DB::getQueryLog();
|
||||
$count = count($queries);
|
||||
$timeEnd = microtime(true);
|
||||
$time = $timeEnd - $timeStart;
|
||||
$queries = DB::getQueryLog();
|
||||
$count = count($queries);
|
||||
$timeEnd = microtime(true);
|
||||
$time = $timeEnd - $timeStart;
|
||||
|
||||
nlog($request->method().' - '.$request->url().": $count queries - ".$time);
|
||||
nlog($request->method().' - '.$request->url().": $count queries - ".$time);
|
||||
|
||||
// if($count > 50)
|
||||
//nlog($queries);
|
||||
}
|
||||
// if($count > 50)
|
||||
//nlog($queries);
|
||||
|
||||
LightLogs::create(new DbQuery($request->method(), $request->url(), $count, $time))
|
||||
->batch();
|
||||
}
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
@ -249,19 +249,14 @@ class Invoice extends BaseModel
|
||||
$partial_due_date = $this->partial_due_Date ? Carbon::parse($this->partial_due_date) : false;
|
||||
|
||||
if ($this->status_id == self::STATUS_SENT && $due_date && $due_date->gt(now())) {
|
||||
nlog("1 unpaid");
|
||||
return self::STATUS_UNPAID;
|
||||
} elseif ($this->status_id == self::STATUS_PARTIAL && $partial_due_date && $partial_due_date->gt(now())) {
|
||||
nlog("2 partial");
|
||||
return self::STATUS_PARTIAL;
|
||||
} elseif ($this->status_id == self::STATUS_SENT && $due_date && $due_date->lt(now())) {
|
||||
nlog("3 overdue");
|
||||
return self::STATUS_OVERDUE;
|
||||
} elseif ($this->status_id == self::STATUS_PARTIAL && $partial_due_date && $partial_due_date->lt(now())) {
|
||||
nlog("4 overdue");
|
||||
return self::STATUS_OVERDUE;
|
||||
} else {
|
||||
nlog("status id ");
|
||||
return $this->status_id;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user