Skip to content

Commit

Permalink
Export prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezcasas committed Jul 18, 2020
1 parent 9b34597 commit 7fe7376
Show file tree
Hide file tree
Showing 16 changed files with 853 additions and 54 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ reload: composer-env-file
@docker-compose exec nginx nginx -s reload

test: composer-env-file
@docker exec codelytv-php_ddd_skeleton-php make run-tests
docker exec codelytv-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite mooc
docker exec codelytv-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite shared
docker exec codelytv-php_ddd_skeleton-mooc_backend-php ./vendor/bin/behat -p mooc_backend --format=progress -v
docker exec codelytv-php_ddd_skeleton-backoffice_backend-php ./vendor/bin/phpunit --testsuite backoffice

run-tests: composer-env-file
mkdir -p build/test_results/phpunit
Expand Down Expand Up @@ -69,4 +72,6 @@ ping-mysql:

clean-cache:
@rm -rf apps/*/*/var

@docker exec codelytv-php_ddd_skeleton-backoffice_backend-php ./apps/backoffice/backend/bin/console cache:warmup
@docker exec codelytv-php_ddd_skeleton-backoffice_frontend-php ./apps/backoffice/frontend/bin/console cache:warmup
@docker exec codelytv-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console cache:warmup
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ The [Event Bus](src/Shared/Infrastructure/Bus/Event/InMemory/InMemorySymfonyEven
The [MySql Bus](src/Shared/Infrastructure/Bus/Event/MySql/MySqlDoctrineEventBus.php) uses a MySql+Pulling as a bus.
The [RabbitMQ Bus](src/Shared/Infrastructure/Bus/Event/RabbitMq/RabbitMqEventBus.php) uses RabbitMQ C extension.

## 📱 Monitoring
Every time a domain event is published it's exported to Prometheus. You can access to the Prometheus panel [here](http://localhost:9999/)

## 🤔 Contributing
There are some things missing (add swagger, improve documentation...), feel free to add this if you want! If you want
some guidelines feel free to contact us :)
Expand Down
4 changes: 4 additions & 0 deletions apps/backoffice/backend/config/routes/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metrics_get:
path: /metrics
controller: CodelyTv\Apps\Backoffice\Backend\Controller\Metrics\MetricsController
methods: [GET]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Apps\Backoffice\Backend\Controller\Metrics;

use CodelyTv\Shared\Infrastructure\Monitoring\PrometheusMonitor;
use Prometheus\RenderTextFormat;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class MetricsController
{
private PrometheusMonitor $monitor;

public function __construct(PrometheusMonitor $monitor)
{
$this->monitor = $monitor;
}

public function __invoke(Request $request): Response
{
$renderer = new RenderTextFormat();
$result = $renderer->render($this->monitor->registry()->getMetricFamilySamples());

return new Response($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
}
}
4 changes: 4 additions & 0 deletions apps/backoffice/frontend/config/routes/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metrics_get:
path: /metrics
controller: CodelyTv\Apps\Backoffice\Frontend\Controller\Metrics\MetricsController
methods: [GET]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Apps\Backoffice\Frontend\Controller\Metrics;

use CodelyTv\Shared\Infrastructure\Monitoring\PrometheusMonitor;
use Prometheus\RenderTextFormat;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class MetricsController
{
private PrometheusMonitor $monitor;

public function __construct(PrometheusMonitor $monitor)
{
$this->monitor = $monitor;
}

public function __invoke(Request $request): Response
{
$renderer = new RenderTextFormat();
$result = $renderer->render($this->monitor->registry()->getMetricFamilySamples());

return new Response($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
}
}
4 changes: 4 additions & 0 deletions apps/mooc/backend/config/routes/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metrics_get:
path: /metrics
controller: CodelyTv\Apps\Mooc\Backend\Controller\Metrics\MetricsController
methods: [GET]
28 changes: 28 additions & 0 deletions apps/mooc/backend/src/Controller/Metrics/MetricsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace CodelyTv\Apps\Mooc\Backend\Controller\Metrics;

use CodelyTv\Shared\Infrastructure\Monitoring\PrometheusMonitor;
use Prometheus\RenderTextFormat;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class MetricsController
{
private PrometheusMonitor $monitor;

public function __construct(PrometheusMonitor $monitor)
{
$this->monitor = $monitor;
}

public function __invoke(Request $request): Response
{
$renderer = new RenderTextFormat();
$result = $renderer->render($this->monitor->registry()->getMetricFamilySamples());

return new Response($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
}
}
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

"doctrine/dbal": "^2.10",
"doctrine/orm": "^2.7",
"ocramius/proxy-manager": "^2.9",
"ocramius/proxy-manager": "2.8.1",

"elasticsearch/elasticsearch": "^7.3",
"monolog/monolog": "^2.1"
"monolog/monolog": "^2.1",

"endclothing/prometheus_client_php": "^1.0"
},
"require-dev": {
"ext-xdebug": "*",
Expand Down
Loading

0 comments on commit 7fe7376

Please sign in to comment.