PromPHP / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
415 stars 91 forks source link

Call to undefined method Illuminate\Support\Facades\Redis::connect() #115

Open chis0m opened 1 year ago

chis0m commented 1 year ago

So installed the package in a Laravel 8.x application and I tried testing by running this part of the example

$adapter = new Redis(config('prometheus.redis'));
$registry = new CollectorRegistry($adapter, false);
$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
return response()->json(['data' => $result]);

And I am getting the error Call to undefined method Illuminate\Support\Facades\Redis::connect() Which occurs in the package vendor/promphp/prometheus_client_php/src/Prometheus/Storage/Redis.php:225

How do I fix this? Thanks

Alitindrawan24 commented 1 year ago

Same issue here, Is this because I'm using a certain Laravel version or is there another problem?

Alitindrawan24 commented 1 year ago

@chis0m I am already solved this issue by installing PHP Redis extension, you can following this to phpredis installation https://github.com/phpredis/phpredis/blob/develop/INSTALL.md

Goopil commented 8 months ago

if you're using this package in laravel. Prefer to reuse the defined connection.

$connection = $this->app->make('redis')->connection(config('prometheus.redis'))->client();
$adapter = Redis::fromExistingConnection($connection);
$registry = new CollectorRegistry($adapter, false);
$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
return response()->json(['data' => $result]);