1. Go to this page and download the library: Download ensi/laravel-prometheus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ensi / laravel-prometheus example snippets
# app/Providers/AppServiceProvider.php
public function boot() {
Prometheus::counter('http_requests_count')->labels(['endpoint', 'code']);
Prometheus::summary('http_requests_duration_seconds', 60, [0.5, 0.95, 0.99]);
}
# app/Providers/AppServiceProvider.php
public function boot() {
// создаём метрики в конкретном bag
Prometheus::bag('business')->counter('orders_count')->labels(['delivery_type', 'payment_method'])
}
# app/Actions/CreateOrder.php
public function execute(Order $order) {
// ...
Prometheus::bag('business')->update('orders_count', 1, [$order->delivery_type, $order->payment_method]);
}
class TenantLabelMiddleware implements LabelMiddleware
{
public function labels(): array
{
return ['tenant'];
}
public function values(): array
{
return [Tenant::curent()->id];
}
}
class QueueLengthOnDemandMetric extends OnDemandMetric {
public function register(MetricsBag $metricsBag): void
{
$metricsBag->gauge('queue_length');
}
public function update(MetricsBag $metricsBag): void
{
$metricsBag->update('queue_length', Queue::size());
}
}