Grafana Alloy

repository·main·Indexed 11 days ago

https://github.com/grafana/alloy

An OpenTelemetry Collector distribution with built-in Prometheus pipelines, designed for collecting and processing metrics, logs, traces, and profiles using a programmable configuration syntax.

Tokens
461.1K
Snippets
1.1K
Records
1.9K
Agent score
85%

What's inside Grafana Alloy

  1. What is the Alloy Collector Distro?

    main
    The Alloy Collector Distro is an OpenTelemetry (OTel) Collector distribution that embeds Alloy's OTel components and integrates them directly with the Alloy CLI. It is built using the OpenTelemetry Collector Builder (OCB), which uses a configuration file to define metadata and the specific set of receivers, processors, and exporters to include in the distribution.
  2. Introduction to Grafana Alloy

    main

    Grafana Alloy is an open-source telemetry collector designed to simplify the gathering and sending of observability data. It is an OpenTelemetry Collector distribution that includes built-in Prometheus pipelines and native support for Loki (logs), Pyroscope (profiles), and other observability backends.

    Key benefits include:

    • Unified Collection: Collects metrics, logs, traces, and profiles in a single tool, reducing the operational complexity of running separate collectors for each signal type.
    • Vendor Neutrality: Provides the flexibility to send data to any compatible backend, such as Grafana Cloud, self-managed Grafana stacks, or other observability platforms.
    • Pipeline-based Architecture: Uses a component-based model where small building blocks are connected in a configuration file to create continuous data pipelines.
  3. Overview of the Grafana Alloy CLI commands

    main
    The alloy binary provides a command-line interface for managing the lifecycle, configuration, and debugging of Alloy. The primary way to use Alloy is via the run subcommand, which starts the service using an Alloy syntax configuration file. Other commands allow for configuration formatting, validation, conversion, and interacting with the running instance via GraphQL or OTel engines.
  4. Overview of Grafana Alloy

    main

    Grafana Alloy is an open-source OpenTelemetry Collector distribution that includes built-in Prometheus pipelines. It is designed to handle metrics, logs, traces, and profiles using a programmable, expression-based syntax.

    Key capabilities include:

    • OpenTelemetry Support: Acts as a distribution of the OpenTelemetry Collector, supporting many existing OTel components.
    • Multi-Ecosystem Integration: Supports OpenTelemetry, Prometheus, Grafana Loki, and Grafana Pyroscope.
    • Kubernetes-Native: Includes components to interact directly with Kubernetes resources.
    • Scalability: Supports automatic workload distribution via clustering and centralized configuration via a remote server.
    • Extensibility: Allows sharing pipelines using modules.
    • Observability: Features a built-in UI for visualizing and debugging pipelines.
  5. Use `otelcol.exporter.file` to write telemetry to disk

    main

    otelcol.exporter.file accepts metrics, logs, and traces telemetry data from other otelcol components and writes them to files on disk. It supports both JSON (JSONL) and Protocol Buffers (proto) formats.

    This component is a wrapper over the upstream OpenTelemetry Collector Contrib fileexporter.

    otelcol.exporter.file "<LABEL>" {
      path = "<PATH>"
    }
  6. Use `database_observability.sql_server` to monitor Microsoft SQL Server

    main

    The database_observability.sql_server component connects to a Microsoft SQL Server instance and collects observability data across all accessible user databases. It forwards log entries to Loki receivers and exports targets for Prometheus scraping.

    Core Functionality

    • Schema Details: Collects schemas and tables from information_schema.
    • Query Metrics: Collects per-query executions, errors, and duration counters from Query Store.
    • Query Details: Collects query text and parsed table names from Query Store.

    Requirements

    • Permissions: The login requires VIEW DATABASE STATE on the connected database. On SQL Server 2022 and later, VIEW DATABASE PERFORMANCE STATE is also sufficient.
    • Query Store: For query_metrics and query_details to work, Query Store must be enabled on the database specified in the data_source_name.
    database_observability.sql_server "orders_db" {
      data_source_name = "sqlserver://user:pass@server:1433"
      forward_to       = [loki.write.logs_service.receiver]
    }
    
    loki.write "logs_service" {
      endpoint {
        url = sys.env("<GRAFANA_CLOUD_HOSTED_LOGS_URL>")
        basic_auth {
          username = sys.env("<GRAFANA_CLOUD_HOSTED_LOGS_ID>")
          password = sys.env("<GRAFANA_CLOUD_RW_API_KEY>")
        }
      }
    }
  7. Use `otelcol.exporter.googlecloudpubsub` to export telemetry to Google Cloud Pub/Sub

    main

    The otelcol.exporter.googlecloudpubsub component accepts metrics, traces, and logs from other otelcol components and sends them to a Google Cloud Pub/Sub Topic. It acts as a wrapper over the upstream OpenTelemetry Collector googlecloudpubsub exporter.

    You can define multiple instances of this component by using different labels.

    otelcol.exporter.googlecloudpubsub "<LABEL>" {
        project = "<PROJECT-ID>"
        topic   = "projects/<PROJECT-ID>/topics/<TOPIC-NAME>"
    }
  8. Use `prometheus.operator.probes` to scrape Kubernetes Probes

    main

    The prometheus.operator.probes component discovers Probe resources in a Kubernetes cluster and scrapes the targets they reference.

    It performs three main functions:

    1. Discovers Probe resources from the Kubernetes cluster.
    2. Discovers targets or ingresses that match those Probes.
    3. Scrapes metrics from those endpoints and forwards them to a specified receiver.

    By default, it uses the in-cluster configuration to access the Kubernetes API. If running outside the cluster, you must provide connection information via the client block, and ensure network access to the target pods is available.

    prometheus.operator.probes "<LABEL>" {
        forward_to = <RECEIVER_LIST>
    }
  9. Understand the beyla.ebpf component

    main

    The beyla.ebpf component runs Grafana Beyla (eBPF auto-instrumentation) as a child process of Alloy.

    Alloy automates the lifecycle by translating the Alloy component configuration into a Beyla YAML configuration, spawning the embedded Beyla binary, ingesting Beyla's OTLP telemetry, and forwarding it to your configured downstream outputs.

    Platform Support:

    • Supported on linux/amd64 and linux/arm64.
    • On any other platform, the component acts as a no-op (does nothing) and logs a warning.
  10. Use otelcol.processor.span to transform traces

    main

    The otelcol.processor.span component allows you to manipulate OpenTelemetry trace spans. You can rename spans based on attribute values or regex patterns, add new attributes extracted from the span name, filter spans using inclusion/exclusion rules, and modify the span status (e.g., setting it to Error).

    Note: This component only supports traces. Logs and metrics are not supported.

    otelcol.processor.span "default" {
      # Configuration blocks go here
    
      output {
          traces = [otelcol.exporter.otlphttp.default.input]
      }
    }