_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Grafana Loki — Log Aggregation

09. 11. 2024 1 min read intermediate

DevOps Intermediate

Grafana Loki — Log Aggregation

LokiLoggingGrafanaObservability 6 min read

Grafana Loki pro centralizovaný sběr logů. Architektura, LogQL dotazy, label design a integrace.

Proč Loki

Loki je „Prometheus pro logy” — indexuje pouze labels, ne obsah logů. Řádově nižší náklady než Elasticsearch.

  • Label-based indexing
  • Kompatibilní s Prometheus labels
  • Object storage backend
  • Nativní integrace s Grafana

Promtail Agent

server:
  http_listen_port: 9080
clients:
  - url: http://loki:3100/loki/api/v1/push
scrape_configs:
  - job_name: kubernetes-pods
    kubernetes_sd_configs:
      - role: pod
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_app]
        target_label: app
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
    pipeline_stages:
      - json:
          expressions:
            level: level
      - labels:
          level:

LogQL

# Základní filtr
{namespace="production", app="api-server"} |= "error"

# JSON parsing + filtr
{app="api-server"} | json | level="error" | status >= 500

# Metriky z logů
sum(rate({app="api-server"} |= "error" [5m])) by (namespace)

# Top 10 nejčastějších chyb
topk(10, sum by (error_type) (
  count_over_time({app="api-server"} | json | level="error" [1h])))

Label Design

  • ✅ Nízká kardinalita: namespace, app, environment, level
  • ❌ Vysoká kardinalita: user_id, request_id, IP
  • Pravidlo: max 10-15 unikátních label kombinací per stream

Summary

Loki nabízí cost-effective log aggregation díky label-based indexingu. LogQL a nativní Grafana integrace umožňují korelaci logů s metrikami a traces.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.