cors / prometheus
CORS - Prometheus
1.1.0
2024-02-21 15:50 UTC
Requires
- php: >=8.1
- coreshop/registry: ^2.2.9 || ^3.0 || ^4.0
- pimcore/admin-ui-classic-bundle: ^1.1
- pimcore/pimcore: ^11.0
- promphp/prometheus_client_php: ^2.4
- symfony/dotenv: ^6.3
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpstan/phpstan-symfony: ^1.3.2
- symplify/easy-coding-standard: ^11.1
- vimeo/psalm: ^4.10
README
CORS Pimcore Prometheus
将 Pimcore 指标暴露给 Prometheus。这包括以下指标
- 已安装包及其版本
- Pimcore 网站
- 表及其行数
- Symfony Messenger 处理的消息数
安装
- 安装并启用该包
composer require cors/prometheus bin/console pimcore:bundle:enable CORSPrometheusBundle
- 配置路由
# app/routes.yaml _cors_prometheus: resource: "@CORSPrometheusBundle/Resources/config/routing.yaml"
请确保不要将 /metrics
路由公开访问!我们通过 nginx 配置来实现这一点
location ~* /metrics { deny all; return 403; }
您还可以添加一个使用密钥保护路由的事件监听器
<?php declare(strict_types=1); namespace App\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\KernelEvent; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Security\Core\Exception\AccessDeniedException; final class MetricsListener implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ KernelEvents::REQUEST => 'request', ]; } public function request(KernelEvent $event): void { if ('cors_prometheus' === $event->getRequest()->attributes->get('_route')) { if ($event->getRequest()->query->get('apiKey') !== 'your-super-secret-key') { throw new NotFoundHttpException('Access denied'); } } } }
存储
同时,请确保您有某种类型的存储来临时存储指标。我们使用 Redis 实例来实现。
Prometheus\Storage\Adapter: factory: [ 'CORS\Bundle\PrometheusBundle\StorageFactory', 'create' ] arguments: $dsn: 'redis://redis:6379'