From 60bc5943ff71ea815057b8aeeca80e1e201a83e2 Mon Sep 17 00:00:00 2001 From: dongwei <838456736@qq.com> Date: Thu, 14 Mar 2019 16:58:11 +0800 Subject: [PATCH] add monitor switch & catch exception log to lumen. --- src/Middleware/TunnelMiddleware.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Middleware/TunnelMiddleware.php b/src/Middleware/TunnelMiddleware.php index 9733b0d..94c519c 100644 --- a/src/Middleware/TunnelMiddleware.php +++ b/src/Middleware/TunnelMiddleware.php @@ -6,6 +6,7 @@ use Closure; use GuzzleHttp\Client; use Illuminate\Http\JsonResponse; use InfluxDB\Database; +use InfluxDB\Exception; use InfluxDB\Point; /** @@ -39,7 +40,7 @@ class TunnelMiddleware { //过滤tool返回结果 if ($response instanceof JsonResponse) { - if (app()->environment('develop')) { + if (app()->environment('develop', 'production') && env('RPC_MONITOR_SWITCH') == 1) { $content = $response->getOriginalContent(); $status = isset($content['error']) ? $content['error']['code'] : 200; $client = new \InfluxDB\Client("influxdb-svc", 8086, '', '', false, false, 1, 1); @@ -52,6 +53,11 @@ class TunnelMiddleware ['status_value' => $status == 200 ? $status : -$status] ) ); + try { + $database->writePoints($points, Database::PRECISION_SECONDS); + } catch (Exception $exception) { + app('log')->error('influxdb-write-wrong', ['code' => $exception->getCode(),'message' => $exception->getMessage()]); + } } }