PUSHGATWAY

Про PUSHGATWAY очень мало написано в инете, особенно под PHP

Для установки локально PUSHGATWAY docker-compose.yml:

    pushgateway:
        image: prom/pushgateway
        restart: always
        container_name: app2022-pushgateway
        ports:
            - 9091:9091
            - 9090:9090
        networks:
            - front
            - backend

 

Есть библиотека для работы с pushgateway

https://github.com/PromPHP/prometheus_push_gateway_php ->
promphp/prometheus_push_gateway_php

 

Однако, нашел хороший простой класс, который основан на GuzzleHttp\Client:

https://github.com/markarik/wnl-platform/blob/9f4383e850373e1849f04f6d1487268cf91fa615/app/Console/PrometheusPushgateway.php

Немного модифицировал его под свои нужды, и получилось вот такое

<?php
namespace App\Handler;


use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

class PrometheusPushgateway
{
   public function notify($count, $code=200)
   {

        $url = 'http://pushgateway:9091/metrics/job/symfony/instance/sender';
        $url = getenv('PUSHGATWAY_URL');

      $client = new Client();
      try {
         $bodyLines = [
            "# HELP response_symfony_code_count",
            "# TYPE response_symfony_code_count",
            "response_symfony_code_count {code=\"${code}\"} ${count}"
         ];
         $body = implode("\n", $bodyLines) . "\n";
         $client->request('POST', $url, [
            'body' => $body
         ]);
      } catch (GuzzleException $exception) {
          exit('error');
      }
   }
}

 

 

User Deprecated: Since symfony/framework-bundle 5.1: Using type «Symfony\….» for argument 1 of method «App\Kernel: configureRoutes()» is deprecated,

User Deprecated: Since symfony/framework-bundle 5.1: Using type "Symfony\Component\Routing\RouteCollectionBuilder" for argument 1 of method "App\Kernel:configureRoutes()" is deprecated,


You need to update Kernel class to start using RoutingConfigurator instead of RouteCollectionBuilder.

You can do it automatically by updating the recipe (composer recipes:install symfony/framework-bundle --force)