Merge branch 'feature/tunnel'
This commit is contained in:
commit
d28d9973c1
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace JsonRpc\Middleware;
|
namespace JsonRpc\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
@ -37,23 +38,23 @@ class TunnelMiddleware
|
||||||
public function terminate($request, $response)
|
public function terminate($request, $response)
|
||||||
{
|
{
|
||||||
//过滤tool返回结果
|
//过滤tool返回结果
|
||||||
if ($response instanceof JsonResponse)
|
if ($response instanceof JsonResponse) {
|
||||||
{
|
if (app()->environment('dev', 'production')) {
|
||||||
$content = $response->getOriginalContent();
|
$content = $response->getOriginalContent();
|
||||||
$status = isset($content['error']) ? $content['error']['code'] : 200;
|
$status = isset($content['error']) ? $content['error']['code'] : 200;
|
||||||
|
$client = new \InfluxDB\Client("10.0.1.67");
|
||||||
$client = new \InfluxDB\Client('http://localhost', '8086');
|
|
||||||
$database = $client->selectDB('rpc_monitor');
|
$database = $client->selectDB('rpc_monitor');
|
||||||
$points = array(
|
$points = array(
|
||||||
new Point(
|
new Point(
|
||||||
'monitor',
|
'monitor',
|
||||||
0.64,
|
null,
|
||||||
['app' =>env('APP_NAME'), 'status' => $status],
|
['app' => env('APP_NAME'), 'status' => $status, 'env' => app()->environment()],
|
||||||
['content' => $request->getContent()]
|
['content' => $request->getContent()]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$result = $database->writePoints($points, Database::PRECISION_SECONDS);
|
$database->writePoints($points, Database::PRECISION_SECONDS);
|
||||||
app('rpc.logger')->info('rpc tunnel ctx ' [$result]);
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,21 @@ class JsonRpcMethod extends JsonRpc
|
||||||
public function error($code, $msg)
|
public function error($code, $msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
return [
|
return is_string($msg)
|
||||||
|
? [
|
||||||
'jsonrpc' => '2.0',
|
'jsonrpc' => '2.0',
|
||||||
'error' => [
|
'error' => [
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'message' => is_array($msg) ? json_encode($msg) : $msg,
|
'message' => $msg,
|
||||||
|
],
|
||||||
|
'id' => $this->id
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
'jsonrpc' => '2.0',
|
||||||
|
'error' => [
|
||||||
|
'code' => $code,
|
||||||
|
'message' => self::ErrorMsg[$code],
|
||||||
|
'data' => $msg
|
||||||
],
|
],
|
||||||
'id' => $this->id
|
'id' => $this->id
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user