agenticmorf/fluxui-loki
Livewire/Flux UI dashboard for querying Grafana Loki logs from your Laravel Sail/Docker services. Configurable Loki URL, service label, route and layout; includes logs page at /logs with auth middleware support.
composer require agenticmorf/fluxui-loki livewire/flux-pro
php artisan flux:publish date-picker time-picker chart
.env:
LOKI_URL=http://loki:3100 # Default for Sail/Docker
php artisan vendor:publish --tag=fluxui-loki-config
resources/views/components/layouts/app/sidebar.blade.php):
<x-flux.nav-item href="{{ route('logs') }}" icon="document-text">
Logs
</x-flux.nav-item>
/logs (or your configured route) to query logs.Query Logs:
The dashboard auto-populates a service dropdown using the service_label config (default: compose_service). Select a service, then use Flux Pro’s date/time pickers to filter logs.
// Example: Customize the service dropdown in a published view
// resources/views/vendor/fluxui-loki/logs.blade.php
<x-flux.select name="service" :options="$services" label="Service" />
Log Display:
Logs render in a Flux Pro chart (line/bar) or raw table (customizable via published views). Use the chart component for visualizations:
<x-flux.chart :data="$logs" type="line" />
Real-Time Updates:
Leverage Livewire’s reactivity. Modify the LogsController to refresh logs on demand:
public function updatedService($service)
{
$this->fetchLogs($service);
}
Integration with Sail/Docker:
For Laravel Sail, ensure your docker-compose.yml includes Loki:
services:
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
service_label in config if using non-standard Loki labels (e.g., job or container_name).middleware in config:
'middleware' => ['web', 'auth', 'verified'], // Example: Add 'verified'
LOKI_URL per tenant by extending the LogsController:
protected function getLokiUrl()
{
return Tenant::current()->lokiUrl ?? config('fluxui-loki.url');
}
Flux Pro Dependencies:
date-picker, time-picker, chart) will break the UI. Run:
php artisan flux:publish date-picker time-picker chart
livewire/flux-pro is installed and published.Loki URL Mismatch:
LOKI_URL matches your Loki instance (e.g., http://localhost:3100 for local dev)./loki/api/v1/query.Label Mismatch:
service_label doesn’t match Loki’s labels. Defaults to compose_service (common in Sail).config/fluxui-loki.php or adjust your Loki label query.Livewire Caching:
php artisan cache:clear
php artisan view:clear
Log Queries:
Enable debug mode in config/fluxui-loki.php to log raw Loki queries:
'debug' => env('APP_DEBUG', false),
Custom Views: Publish and override views for granular control:
php artisan vendor:publish --tag=fluxui-loki-views
Modify resources/views/vendor/fluxui-loki/logs.blade.php to add/remove fields.
Performance:
limit in queries:
$query->limit(1000); // Reduce log volume
time-picker to constrain queries to recent data.Custom Controllers:
Extend the default LogsController to add features (e.g., log search):
namespace App\Http\Controllers;
use AgenticMorf\FluxUILoki\Http\Controllers\LogsController as BaseController;
class LogsController extends BaseController
{
public function search($query)
{
$this->logs = $this->queryLogs()->where('line', 'like', "%{$query}%")->get();
}
}
Dynamic Labels: Fetch labels dynamically from Loki’s API:
public function getServices()
{
$response = Http::get(config('fluxui-loki.url').'/api/v1/series', [
'limit' => 100,
'match' => ['job' => '.*'],
]);
return collect($response->json()['data'])->pluck('values.0')->unique()->toArray();
}
Alerting: Integrate with Laravel Notifications to alert on critical logs:
if (str_contains($log, 'ERROR')) {
Notification::route('mail', $user)->notify(new LogAlert($log));
}
Theming:
Customize Flux Pro components via Tailwind CSS. Override styles in your app.css:
/* Target Flux Pro components */
.flux-chart { --chart-bg: #1a202c; }
docker-compose.yml exposes Loki’s port (3100) and networks match:
services:
loki:
networks:
- sail
LOKI_URL (e.g., https://loki.yourdomain.com).timeout in config/fluxui-loki.php:
'timeout' => 30, // Seconds
loki-config.yml to manage storage costs.limit and offset to paginate logs efficiently.services:
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
How can I help you explore Laravel packages today?