cors / prometheus
CORS - Prometheus
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Type:pimcore-bundle
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
Expose Pimcore Metrics to Prometheus. This includes the following metrics:
- Installed Bundles and Versions
- Pimcore Sites
- Tables and row Counts
- Symfony Messenger Processed Messages Count
Installation
- Install and enable the bundle
composer require cors/prometheus bin/console pimcore:bundle:enable CORSPrometheusBundle
- Configure the routes
# app/routes.yaml _cors_prometheus: resource: "@CORSPrometheusBundle/Resources/config/routing.yaml"
Make sure to not expose the /metrics
route to public access! We do that with nginx configs:
location ~* /metrics { deny all; return 403; }
You can also add a event listener that uses a Key to protect the route:
<?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'); } } } }
Storage
Also make sure you have some kind of storage to temporarily store the metrics. We use a Redis instance for that.
Prometheus\Storage\Adapter: factory: [ 'CORS\Bundle\PrometheusBundle\StorageFactory', 'create' ] arguments: $dsn: 'redis://redis:6379'