feat: add Lumen support
This commit is contained in:
parent
6e874128e8
commit
70790933e1
3 changed files with 30 additions and 64 deletions
|
@ -2,63 +2,28 @@
|
|||
|
||||
namespace Superbalist\LaravelPrometheusExporter;
|
||||
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Prometheus\RenderTextFormat;
|
||||
|
||||
class MetricsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var ResponseFactory
|
||||
*/
|
||||
protected $responseFactory;
|
||||
|
||||
/**
|
||||
* @var PrometheusExporter
|
||||
*/
|
||||
protected $prometheusExporter;
|
||||
|
||||
/**
|
||||
* @param ResponseFactory $responseFactory
|
||||
* @param PrometheusExporter $prometheusExporter
|
||||
*/
|
||||
public function __construct(ResponseFactory $responseFactory, PrometheusExporter $prometheusExporter)
|
||||
{
|
||||
$this->responseFactory = $responseFactory;
|
||||
$this->prometheusExporter = $prometheusExporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseFactory
|
||||
*/
|
||||
public function getResponseFactory()
|
||||
{
|
||||
return $this->responseFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PrometheusExporter
|
||||
*/
|
||||
public function getPrometheusExporter()
|
||||
{
|
||||
return $this->prometheusExporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /metrics
|
||||
*
|
||||
* The route path is configurable in the prometheus.metrics_route_path config var, or the
|
||||
* PROMETHEUS_METRICS_ROUTE_PATH env var.
|
||||
*
|
||||
* @param PrometheusExporter $prometheusExporter
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function getMetrics()
|
||||
public function getMetrics(PrometheusExporter $prometheusExporter)
|
||||
{
|
||||
$metrics = $this->prometheusExporter->export();
|
||||
|
||||
$renderer = new RenderTextFormat();
|
||||
$result = $renderer->render($metrics);
|
||||
|
||||
return $this->responseFactory->make($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
|
||||
return response()->make(
|
||||
(new RenderTextFormat)->render(
|
||||
$prometheusExporter->export()
|
||||
),
|
||||
200,
|
||||
['Content-Type' => RenderTextFormat::MIME_TYPE]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue