Grafana Loki Integration 🔥

Integrate Gonzo with Grafana Loki for powerful live log tailing and analysis. Use Loki as your log store and Gonzo as your real-time terminal lens.

Overview

Grafana Loki is a powerful log aggregation system designed for storing and querying logs at scale. While Loki excels at long-term retention and powerful queries via LogQL, live tailing logs for debugging and troubleshooting can be challenging. Gonzo fills this gap by providing a real-time, terminal-based interface for Loki logs.

Why use Gonzo with Loki?

  • Debug in real time: Watch logs as code changes roll out

  • Validate pipelines: Ensure OpenTelemetry agents ship logs correctly to Loki

  • Shorten feedback loops: Catch issues instantly without switching tools

  • Stay in-flow: Operate inside your terminal alongside kubectl, stern, and k9s

  • AI-powered insights: Optional AI analysis of Loki logs

Integration Methods

Gonzo supports two primary methods for accessing Loki logs:

  1. logcli - Using Loki's official CLI tool

  2. Live Tail API - Direct connection to Loki's live tailing endpoint

Method 1: Using logcli

The easiest way to get started is using Loki's official logcli tool.

Install logcli

Configure logcli

Set up your Loki connection:

Query and Tail with Gonzo

Common LogQL Queries

By application:

By severity:

Exclude patterns:

JSON parsing:

Regular expressions:

Method 2: Live Tail API

For more direct integration, use Loki's Live Tail API with Gonzo's custom format support.

Set Up Custom Format

Gonzo includes a built-in Loki format. Download the format file to your config directory:

Live Tail API Connection

Using a Shell Function

Create a convenient shell function for repeated use:

Loki Log Format

Loki outputs logs in a specific JSON structure. Gonzo's Loki format handles:

Gonzo extracts:

  • Labels (stream) → Attributes panel

  • Timestamp → Log timestamp

  • Log line → Message

  • Severity → Detected from message

Kubernetes + Loki Workflow

Combine Loki with Kubernetes for powerful log analysis:

1. Query Kubernetes Logs in Loki

2. Compare with kubectl

Use both tools side by side:

3. Integration with Stern

For multi-pod analysis:

Advanced Use Cases

Pipeline Validation

Verify that logs are flowing correctly into Loki:

Pattern Detection

Use Gonzo's pattern detection on Loki logs:

AI Analysis

Combine Loki queries with AI analysis:

Time-Range Analysis

Analyze specific time periods:

Configuration Examples

Persistent Configuration

Create a config for Loki integration:

Use with:

Shell Aliases

Add to ~/.bashrc or ~/.zshrc:

Troubleshooting

logcli Not Connecting

Check Loki address:

Test connection:

No Logs Appearing in Gonzo

Verify logcli output:

Check Gonzo format:

Authentication Issues

Grafana Cloud:

TLS Issues:

Performance Issues

Reduce query scope:

Adjust Gonzo buffers:

Best Practices

1. Use Specific Label Selectors

2. Combine with Filters

3. Leverage Gonzo's Features

  • Pause (Space) during investigation

  • Filter (/) to narrow further

  • AI Analysis (i) for complex errors

  • Patterns (Counts modal) for trends

4. Save Common Queries

Complete Tutorial

For a comprehensive walkthrough of using Gonzo with Loki, including:

  • Detailed setup instructions

  • Real-world examples

  • Advanced LogQL patterns

  • Custom format configuration

  • Integration patterns

Read the full guide: Live Tailing Grafana Loki Logs with Gonzoarrow-up-right

Documentation

  • Custom Formats - Creating format parsers

  • Kubernetes Integration - K8s log tailing

  • AI Integration - AI-powered analysis

Blog Posts

Support

Having issues with Loki integration?

circle-check
circle-info

Learn More: Read the complete tutorial on Live Tailing Grafana Loki Logs with Gonzoarrow-up-right for advanced patterns and real-world examples.

Last updated