diff --git a/src/metric/CoroutineServerStats.php b/src/metric/src/CoroutineServerStats.php similarity index 98% rename from src/metric/CoroutineServerStats.php rename to src/metric/src/CoroutineServerStats.php index e0a0d4e31..171ef4c77 100644 --- a/src/metric/CoroutineServerStats.php +++ b/src/metric/src/CoroutineServerStats.php @@ -9,7 +9,7 @@ declare(strict_types=1); * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ -namespace Hyperf\Server; +namespace Hyperf\Metric; use Hyperf\Contract\Arrayable; diff --git a/src/metric/src/Listener/OnMetricFactoryReady.php b/src/metric/src/Listener/OnMetricFactoryReady.php index 4a6df2798..c6bd35207 100644 --- a/src/metric/src/Listener/OnMetricFactoryReady.php +++ b/src/metric/src/Listener/OnMetricFactoryReady.php @@ -18,10 +18,10 @@ use Hyperf\Coordinator\Timer; use Hyperf\Engine\Coroutine as Co; use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Metric\Contract\MetricFactoryInterface; +use Hyperf\Metric\CoroutineServerStats; use Hyperf\Metric\Event\MetricFactoryReady; use Hyperf\Metric\MetricFactoryPicker; use Hyperf\Metric\MetricSetter; -use Hyperf\Server\CoroutineServerStats; use Hyperf\Utils\Coroutine; use Hyperf\Utils\System; use Psr\Container\ContainerInterface; @@ -99,7 +99,9 @@ class OnMetricFactoryReady implements ListenerInterface if ($server instanceof SwooleServer) { $serverStatsFactory = fn (): array => $server->stats(); } - } else { + } + + if (! $serverStatsFactory) { $serverStatsFactory = fn (): array => $this->container->get(CoroutineServerStats::class)->toArray(); } } diff --git a/src/metric/src/Middleware/MetricMiddleware.php b/src/metric/src/Middleware/MetricMiddleware.php index f268d5f6e..af464d707 100644 --- a/src/metric/src/Middleware/MetricMiddleware.php +++ b/src/metric/src/Middleware/MetricMiddleware.php @@ -12,8 +12,8 @@ declare(strict_types=1); namespace Hyperf\Metric\Middleware; use Hyperf\HttpServer\Router\Dispatched; +use Hyperf\Metric\CoroutineServerStats; use Hyperf\Metric\Timer; -use Hyperf\Server\CoroutineServerStats; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface;