Grafana 13 & LGTM Stack — Xây dựng hệ thống Observability toàn diện năm 2026

Posted on: 4/26/2026 11:14:56 PM

Khi hệ thống phần mềm phức tạp hơn — microservices, container, serverless, edge computing — thì khả năng quan sát (observability) trở thành yêu cầu sống còn. Không còn đơn giản là xem log hay check CPU — bạn cần tương quan metrics, logs, traces và profiles trong cùng một giao diện thống nhất. Grafana 13, vừa ra mắt tại GrafanaCON 2026 (21/04/2026), cùng với stack LGTM (Loki + Grafana + Tempo + Mimir) và Grafana Alloy chính là câu trả lời open-source mạnh mẽ nhất cho bài toán này.

35M+Người dùng Grafana toàn cầu
7.000+Doanh nghiệp sử dụng (NVIDIA, Microsoft, Anthropic...)
170+Data sources được hỗ trợ
77%Tổ chức chọn open-source cho observability

1. LGTM Stack là gì?

LGTM là tên gọi không chính thức cho bộ công cụ observability open-source của Grafana Labs, mỗi thành phần đảm nhận một tín hiệu (signal) riêng:

Thành phầnTín hiệuVai tròTương đương
LokiLogsHệ thống lưu trữ và truy vấn log, chỉ index labels thay vì full-text → tiết kiệm storage cực lớnElasticsearch, Splunk
GrafanaVisualizationDashboard, alerting, exploration — giao diện thống nhất cho mọi tín hiệuKibana, Datadog Dashboard
TempoTracesDistributed tracing backend, lưu trace không cần index → chi phí thấpJaeger, Zipkin, Datadog APM
MimirMetricsLong-term Prometheus storage, horizontal scaling, multi-tenantThanos, Cortex, VictoriaMetrics

Ngoài bốn thành phần chính, stack còn có Pyroscope (continuous profiling), Beyla (eBPF auto-instrumentation), Faro (frontend observability) và quan trọng nhất — Grafana Alloy làm collector trung tâm.

graph TD
    subgraph Applications
        A1[".NET App"]
        A2["Vue.js SPA"]
        A3["Background Workers"]
    end

    subgraph "Grafana Alloy (Collector)"
        AL["Alloy
OTLP + Prometheus"] end subgraph "LGTM Backend" M["Mimir
Metrics"] L["Loki
Logs"] T["Tempo
Traces"] P["Pyroscope
Profiles"] end G["Grafana 13
Dashboard + Alerting"] A1 -->|OTLP| AL A2 -->|Faro SDK| AL A3 -->|OTLP| AL AL -->|remote_write| M AL -->|loki.write| L AL -->|otlp| T AL -->|pyroscope.write| P M --> G L --> G T --> G P --> G style AL fill:#e94560,stroke:#fff,color:#fff style G fill:#2c3e50,stroke:#fff,color:#fff style M fill:#f8f9fa,stroke:#e94560,color:#2c3e50 style L fill:#f8f9fa,stroke:#e94560,color:#2c3e50 style T fill:#f8f9fa,stroke:#e94560,color:#2c3e50 style P fill:#f8f9fa,stroke:#e94560,color:#2c3e50

Kiến trúc LGTM Stack với Grafana Alloy làm collector trung tâm

2. Grafana Alloy — Collector thế hệ mới

Grafana Alloy là bản phân phối (distribution) open-source của OpenTelemetry Collector, kế thừa từ Grafana Agent nhưng mạnh mẽ hơn nhiều. Alloy được cộng đồng OpenTelemetry bình chọn là vendor distribution được sử dụng nhiều nhất trong khảo sát 2026.

2.1. Tại sao chọn Alloy thay vì OTel Collector gốc?

Tiêu chíOTel Collector gốcGrafana Alloy
Cấu hìnhYAML tĩnhRiver language (programmable) + hỗ trợ YAML qua OTel Engine mode
PipelineReceivers → Processors → ExportersComponent graph linh hoạt, có thể branch/merge
PrometheusCần thêm receiverNative Prometheus scraping + remote_write
Auto-discoveryHạn chếKubernetes service discovery, Docker, Consul tích hợp sẵn
DebuggingCLI flagsBuilt-in UI tại port 12345 hiển thị component graph
ProfilesKhông hỗ trợNative Pyroscope integration

2.2. Cấu hình Alloy cơ bản

File cấu hình Alloy sử dụng River language — declarative nhưng có khả năng lập trình (biến, điều kiện, hàm):

// Nhận telemetry qua OTLP (gRPC + HTTP)
otelcol.receiver.otlp "default" {
  grpc { endpoint = "0.0.0.0:4317" }
  http { endpoint = "0.0.0.0:4318" }

  output {
    metrics = [otelcol.processor.batch.default.input]
    logs    = [otelcol.processor.batch.default.input]
    traces  = [otelcol.processor.batch.default.input]
  }
}

// Batch để giảm network calls
otelcol.processor.batch "default" {
  timeout = "5s"
  send_batch_size = 1000

  output {
    metrics = [otelcol.exporter.otlphttp.mimir.input]
    logs    = [otelcol.exporter.otlphttp.loki.input]
    traces  = [otelcol.exporter.otlp.tempo.input]
  }
}

// Export metrics sang Mimir
otelcol.exporter.otlphttp "mimir" {
  client {
    endpoint = "http://mimir:9009/otlp"
  }
}

// Export logs sang Loki
otelcol.exporter.otlphttp "loki" {
  client {
    endpoint = "http://loki:3100/otlp"
  }
}

// Export traces sang Tempo
otelcol.exporter.otlp "tempo" {
  client {
    endpoint = "tempo:4317"
    tls { insecure = true }
  }
}

OTel Engine Mode — Mới trong 2026

Nếu team đã quen với YAML của OTel Collector, Alloy giờ hỗ trợ OpenTelemetry Engine mode — cho phép dùng trực tiếp file cấu hình YAML chuẩn OTel Collector mà không cần viết lại sang River. Điều này giúp migration từ OTel Collector sang Alloy trở nên gần như zero-effort.

3. Grafana 13 — Những cải tiến đáng chú ý

Grafana 13 được công bố tại GrafanaCON 2026 với hàng loạt tính năng mới tập trung vào ba trục: tốc độ khai thác dữ liệu, quản trị ở quy mô lớnmở rộng hệ sinh thái.

3.1. Dynamic Dashboards (GA)

Trước đây, mỗi khi cần dashboard cho một environment/team/service khác, bạn phải clone và sửa thủ công. Dynamic Dashboards giờ là mặc định — dashboard tự thích ứng dựa trên biến (variables) và ngữ cảnh người dùng. Layout engine mới tự động migrate tất cả dashboard cũ sang schema mới.

3.2. Git Sync (GA) — Dashboard as Code

Tính năng được chờ đợi nhất: đồng bộ hai chiều giữa Grafana và Git repositories (GitHub, GitLab, Bitbucket). Mọi thay đổi dashboard trên UI tự động commit, và ngược lại — push từ Git sẽ cập nhật dashboard. Kết hợp với dashboard schema mới và versioned API, đây là bước ngoặt cho teams áp dụng GitOps cho observability.

sequenceDiagram
    participant Dev as Developer
    participant Git as GitHub/GitLab
    participant G13 as Grafana 13
    participant Alert as Alert Manager

    Dev->>Git: Push dashboard JSON
    Git->>G13: Webhook trigger sync
    G13->>G13: Validate & deploy dashboard
    G13->>Alert: Update alert rules
    Note over G13: Dashboard live ngay lập tức

    G13->>G13: User chỉnh sửa trên UI
    G13->>Git: Auto-commit changes
    Git->>Dev: PR notification

Luồng Git Sync hai chiều trong Grafana 13

3.3. Suggested Dashboards & Templates

Grafana 13 giải quyết vấn đề "blank page" — khi bạn kết nối data source mới, hệ thống sẽ gợi ý dashboard template dựa trên loại dữ liệu. Hỗ trợ sẵn các phương pháp luận chuẩn:

  • USE Method (Utilization, Saturation, Errors) — cho infrastructure monitoring
  • RED Method (Rate, Errors, Duration) — cho service monitoring
  • DORA Metrics — cho DevOps performance (deployment frequency, lead time, MTTR, change failure rate)

3.4. Các tính năng đáng chú ý khác

Tính năngTrạng tháiMô tả
Grafana AdvisorGAHealth check tự động: phát hiện data source lỗi, plugin cũ, SSO cấu hình sai
Panel StylesPreviewÁp dụng preset style cho time series, gauge, stat, bar chart chỉ bằng 1 click
Annotation ClusteringGAGom nhóm annotation dày đặc thành tooltip cuộn được
Graphviz PanelPrivate PreviewVẽ diagram DOT language với data mapping trực tiếp
Assistant On-PremisesGAAI assistant chạy trên Enterprise/OSS, hỗ trợ SQL expressions
IBM DB2 Data SourcePreviewKết nối trực tiếp với IBM DB2 — mở rộng sang enterprise legacy

4. Loki — Kiến trúc mới với Kafka-backed Ingestion

Loki luôn nổi bật bởi triết lý "like Prometheus, but for logs" — chỉ index labels, không index nội dung log, giúp chi phí storage giảm đáng kể so với Elasticsearch. Tại GrafanaCON 2026, Grafana Labs công bố bản thiết kế lại kiến trúc Loki với những cải tiến lớn:

4.1. Kafka-backed Ingestion

Lớp ingestion mới sử dụng Kafka làm buffer trung gian. Lợi ích:

  • Durability: Log không bị mất khi Loki ingester restart hoặc crash
  • Backpressure handling: Kafka tự nhiên xử lý burst traffic mà không cần over-provision ingester
  • Replay: Có thể replay log từ Kafka offset nếu cần re-index

4.2. Query Engine & Scheduler mới

Query planner mới phân phối công việc theo partition và thực thi song song (parallel), cho kết quả:

20xÍt dữ liệu phải scan hơn
10xNhanh hơn trên aggregated queries

Logline Acquisition

Grafana Labs vừa mua lại Logline — công nghệ precision search cho tập dữ liệu log quy mô lớn. Kỳ vọng tính năng này sẽ tích hợp vào Loki trong các phiên bản tiếp theo, mang lại khả năng full-text search mà không cần index full-text truyền thống.

5. Triển khai LGTM Stack với Docker Compose

Dưới đây là cấu hình Docker Compose tối giản để chạy toàn bộ LGTM stack trên một máy chủ:

version: "3.8"

services:
  # Grafana Alloy - Collector
  alloy:
    image: grafana/alloy:latest
    volumes:
      - ./alloy-config.river:/etc/alloy/config.river
    ports:
      - "4317:4317"   # OTLP gRPC
      - "4318:4318"   # OTLP HTTP
      - "12345:12345" # Alloy UI
    command: run --server.http.listen-addr=0.0.0.0:12345 /etc/alloy/config.river

  # Mimir - Metrics
  mimir:
    image: grafana/mimir:latest
    command: -config.file=/etc/mimir/mimir.yaml
    volumes:
      - ./mimir.yaml:/etc/mimir/mimir.yaml
      - mimir-data:/data
    ports:
      - "9009:9009"

  # Loki - Logs
  loki:
    image: grafana/loki:latest
    command: -config.file=/etc/loki/loki.yaml
    volumes:
      - ./loki.yaml:/etc/loki/loki.yaml
      - loki-data:/loki
    ports:
      - "3100:3100"

  # Tempo - Traces
  tempo:
    image: grafana/tempo:latest
    command: -config.file=/etc/tempo/tempo.yaml
    volumes:
      - ./tempo.yaml:/etc/tempo/tempo.yaml
      - tempo-data:/var/tempo
    ports:
      - "3200:3200"   # Tempo API
      - "9095:9095"   # gRPC

  # Grafana - Visualization
  grafana:
    image: grafana/grafana:13.0.0
    environment:
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    volumes:
      - ./grafana-datasources.yaml:/etc/grafana/provisioning/datasources/ds.yaml
      - grafana-data:/var/lib/grafana
    ports:
      - "3000:3000"

volumes:
  mimir-data:
  loki-data:
  tempo-data:
  grafana-data:

5.1. Provisioning Data Sources

File grafana-datasources.yaml tự động kết nối Grafana với backend:

apiVersion: 1
datasources:
  - name: Mimir
    type: prometheus
    access: proxy
    url: http://mimir:9009/prometheus
    isDefault: true
    jsonData:
      httpMethod: POST

  - name: Loki
    type: loki
    access: proxy
    url: http://loki:3100
    jsonData:
      derivedFields:
        - name: TraceID
          matcherRegex: "traceID=(\\w+)"
          url: "$${__value.raw}"
          datasourceUid: tempo
          urlDisplayLabel: "View Trace"

  - name: Tempo
    type: tempo
    access: proxy
    uid: tempo
    url: http://tempo:3200
    jsonData:
      tracesToLogsV2:
        datasourceUid: loki
        filterByTraceID: true
      tracesToMetrics:
        datasourceUid: mimir
        spanStartTimeShift: "-1h"
        spanEndTimeShift: "1h"

Cross-signal correlation

Cấu hình trên tạo liên kết hai chiều giữa logs ↔ traces ↔ metrics. Khi xem một trace trong Tempo, bạn có thể nhảy sang log tương ứng trong Loki (qua traceID) và sang metrics trong Mimir (qua thời gian). Đây là sức mạnh cốt lõi của LGTM — tương quan tín hiệu trong cùng một giao diện.

6. Instrument ứng dụng .NET với OpenTelemetry

Để gửi telemetry từ ứng dụng .NET sang LGTM stack qua Alloy, chỉ cần cài đặt các NuGet packages:

dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
dotnet add package OpenTelemetry.Instrumentation.SqlClient

Cấu hình trong Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetry()
    .ConfigureResource(r => r.AddService("my-api"))
    .WithTracing(tracing => tracing
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddSqlClientInstrumentation(o => o.SetDbStatementForText = true)
        .AddOtlpExporter(o => o.Endpoint = new Uri("http://alloy:4317")))
    .WithMetrics(metrics => metrics
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddRuntimeInstrumentation()
        .AddOtlpExporter(o => o.Endpoint = new Uri("http://alloy:4317")));

builder.Logging.AddOpenTelemetry(logging =>
{
    logging.IncludeFormattedMessage = true;
    logging.AddOtlpExporter(o => o.Endpoint = new Uri("http://alloy:4317"));
});

Chỉ với đoạn code trên, ứng dụng sẽ tự động gửi metrics, traces và logs qua OTLP đến Alloy, từ đó fan-out đến Mimir, Tempo và Loki.

7. Beyla — Auto-instrumentation không cần sửa code

Không phải lúc nào cũng có thể (hoặc muốn) thêm SDK vào ứng dụng. Grafana Beyla sử dụng eBPF để tự động thu thập metrics và traces ở kernel level — hoàn toàn không cần thay đổi source code hay restart service.

graph LR
    subgraph "Host / Kubernetes Node"
        K["Kernel (eBPF probes)"]
        APP1["Service A
(bất kỳ ngôn ngữ)"] APP2["Service B
(bất kỳ ngôn ngữ)"] B["Beyla Agent"] end K -.->|hook syscalls| B APP1 -.->|"HTTP/gRPC calls"| K APP2 -.->|"HTTP/gRPC calls"| K B -->|OTLP| AL["Grafana Alloy"] style B fill:#e94560,stroke:#fff,color:#fff style AL fill:#2c3e50,stroke:#fff,color:#fff style K fill:#f8f9fa,stroke:#e94560,color:#2c3e50

Beyla sử dụng eBPF hooks để thu thập telemetry không cần instrumentation

Beyla đặc biệt hữu ích khi:

  • Cần monitor service của bên thứ ba mà không có source code
  • Muốn có baseline metrics/traces ngay lập tức trước khi thêm instrumentation chi tiết
  • Chạy polyglot microservices (Go, Java, .NET, Node.js, Python...) và muốn uniform telemetry

8. Chiến lược Alerting hiệu quả

Có dashboard đẹp mà không có alerting tốt thì chỉ là "nhìn cho vui". Grafana 13 cải thiện alerting với provenance support (Kubernetes-style API) và tích hợp chặt hơn với Git Sync. Dưới đây là các nguyên tắc thiết kế alert:

8.1. Alert Pyramid

graph TD
    P1["🔴 P1 — Page ngay
Service down, error rate > 5%
Gọi điện + Slack"] P2["🟠 P2 — Cần xử lý trong giờ
Latency p99 > 2s, disk > 85%
Slack channel"] P3["🟡 P3 — Xem khi rảnh
Memory trending up, cert sắp hết hạn
Email digest"] P4["⚪ P4 — Informational
Deployment success, scaling events
Dashboard annotation"] P1 --> P2 --> P3 --> P4 style P1 fill:#e94560,stroke:#fff,color:#fff style P2 fill:#ff9800,stroke:#fff,color:#fff style P3 fill:#f8f9fa,stroke:#e94560,color:#2c3e50 style P4 fill:#f8f9fa,stroke:#e0e0e0,color:#888

Alert Pyramid — phân tầng mức độ nghiêm trọng

Alert Fatigue — Kẻ thù số 1

Nếu team nhận hơn 10 alert P1/P2 mỗi ngày, người ta sẽ bắt đầu ignore tất cả — kể cả alert thật sự quan trọng. Nguyên tắc: mỗi alert P1 phải đi kèm một runbook link rõ ràng và chỉ fire khi cần hành động ngay. Nếu không cần hành động → nó không phải P1.

9. Vận hành LGTM Stack trong Production

9.1. Sizing tham khảo

Quy môMetrics/sLogs GB/ngàyTraces span/sCấu hình đề xuất
Small (≤ 20 services)50K105KSingle-node Docker Compose, 4 vCPU, 16GB RAM
Medium (20-100 services)500K10050KKubernetes, 3-node cluster, object storage (S3/GCS)
Large (100+ services)5M+1TB+500K+Microservices mode, dedicated read/write path, Kafka ingestion

9.2. Object Storage cho Long-term Retention

Cả Loki, Mimir và Tempo đều hỗ trợ object storage (S3, GCS, Azure Blob, MinIO) cho long-term retention. Đây là key để giữ chi phí thấp — local disk chỉ dùng làm cache/WAL, data chính nằm trên object storage với giá ~$0.023/GB/tháng (S3 Standard).

9.3. Retention Strategy

# Loki — giữ log 30 ngày
limits_config:
  retention_period: 720h

# Mimir — giữ metrics 1 năm
limits:
  compactor_blocks_retention_period: 8760h

# Tempo — giữ traces 14 ngày (traces thường query gần)
compactor:
  compaction:
    block_retention: 336h

10. So sánh chi phí: LGTM Stack vs. SaaS

Giải phápChi phí ước tính / tháng (Medium)Ghi chú
Datadog$3.000 - $8.000Tính theo host + log volume + APM span
New Relic$2.000 - $5.000Tính theo GB ingested + user seat
Elastic Cloud$1.500 - $4.000Tính theo capacity (RAM + storage)
Self-hosted LGTM$200 - $500Chỉ trả infra (VMs/K8s + object storage). Cần team vận hành
Grafana Cloud (Free tier)$010K metrics, 50GB logs, 50GB traces/tháng — đủ cho small projects

Grafana Cloud Free Tier

Nếu bạn chưa sẵn sàng tự vận hành, Grafana Cloud cung cấp free tier khá rộng rãi: 10.000 active metrics, 50GB logs, 50GB traces mỗi tháng. Đủ cho side projects hoặc startup giai đoạn đầu — và bạn có thể migrate sang self-hosted bất kỳ lúc nào vì toàn bộ stack là open-source.

11. Kết luận

LGTM Stack cùng Grafana 13 mang đến một giải pháp observability toàn diện, open-source, với chi phí thấp hơn đáng kể so với các nền tảng SaaS. Những cải tiến trong Grafana 13 — Dynamic Dashboards, Git Sync, Suggested Templates — giúp giảm thời gian setup và tăng tốc khả năng khai thác dữ liệu. Loki với kiến trúc Kafka-backed mới và query engine song song đã thu hẹp khoảng cách hiệu năng với Elasticsearch nhưng vẫn giữ chi phí lưu trữ rẻ hơn nhiều lần.

Chìa khóa thành công khi triển khai: bắt đầu nhỏ với Docker Compose, instrument bằng OpenTelemetry chuẩn (để không bị vendor lock-in), sử dụng Alloy làm collector trung tâm, và scale ra Kubernetes khi cần. Observability không phải thứ bạn "thêm vào sau" — nó nên là citizen đầu tiên trong kiến trúc hệ thống của bạn.

Nguồn tham khảo: