Grafana Agent

repository·main·Indexed 11 days ago

https://github.com/grafana/agent

An OpenTelemetry Collector distribution featuring a Terraform-inspired configuration model and component-based architecture for programmable pipelines. It collects and processes metrics, logs, traces, and profiles. The project includes a Grafana Agent Operator supporting Prometheus Operator CRDs (ServiceMonitor, PodMonitor, and Probe) and integrations for Windows Certificate Store and CloudWatch.

Tokens
428.6K
Snippets
1K
Records
1.6K
Agent score
76%

What's inside Grafana Agent

  1. What is Grafana Agent Flow

    main

    Grafana Agent Flow is a component-based revision of Grafana Agent designed for ease-of-use, debuggability, and adaptability. It functions as a distribution of the OpenTelemetry Collector, meaning it includes dozens of OpenTelemetry-native components while adding features like programmable pipelines, clustering support, and first-class support for the Prometheus and Loki ecosystems.

    Key characteristics of the Flow model include:

    • Reusability: The output of one component can be used as the input for multiple other components.
    • Composability: Components can be chained together to form a complete data pipeline.
    • Single task focus: Each component is scoped to a narrow task to minimize side effects.

    Users write declarative configurations using a Terraform-inspired language called River.

  2. Understand the Flow Mode documentation structure

    main

    The Flow mode documentation is organized into five distinct types of content to help users navigate from onboarding to deep technical reference:

    1. Get started: Onboarding content for new users, including installation guides and "hello world" configurations to help decide if Flow mode is a good fit.
    2. Concepts: High-level overviews that answer "What is it?" and provide the background information necessary to understand Agent abstractions.
    3. Tutorials: Broad, learning-oriented procedures that answer "Can you teach me to...?" These may use non-production-ready examples for educational purposes.
    4. Tasks: Focused, objective-oriented guides that answer "How do I?" These provide production-ready solutions and best practices. They are designed to be followed step-by-step but may use branching paths instead of strict numbering.
    5. Reference: The exhaustive source of truth describing Agent components and configuration options. This is the most detailed section and should not be paraphrased in Tasks or Tutorials; instead, those sections should link to the Reference pages.
  3. Retrieve GCP logs with loki.source.gcplog

    main

    loki.source.gcplog retrieves logs from Google Cloud Platform (GCP) resources (such as GCS buckets, load balancers, or Kubernetes clusters) by consuming logs from GCP Pub/Sub.

    It supports two mutually exclusive strategies:

    1. Pull: The component actively reads logs from a specified GCP Pub/Sub subscription.
    2. Push: The component hosts a server that receives logs via push requests from GCP Pub/Sub.

    To use the pull strategy, you must first configure your GCP project to forward cloud resource logs to a Pub/Sub topic. Additionally, the host system must have GCP credentials configured (e.g., via the GOOGLE_APPLICATION_CREDENTIALS environment variable).

    loki.source.gcplog "LABEL" {
      pull {
        project_id   = "PROJECT_ID"
        subscription = "SUB_ID"
      }
    
      forward_to = RECEIVER_LIST
    }
  4. What is Agent Flow and how does it work?

    main

    Agent Flow is a system designed to describe a programmable pipeline for telemetry data. It moves away from a single hierarchical configuration file toward a model of reusable, composable components connected in a node graph or flowchart.

    Key characteristics include:

    • Component-based: The configuration is broken into discrete components (e.g., Service Discovery, Integrations, Filters, Remote Write).
    • Programmable Pipeline: Components are connected to allow telemetry data to move through the system.
    • Introspection: Designed to allow users to understand how data moves, how rules apply, and how filtering works.
    • Visual/Machine Friendly: Aimed at being both machine-readable/writable (for GUIs and formatters) and visually representable as a node graph.

    Conceptually, the data flow follows a pattern where a source (like Service Discovery) feeds into a filter, which feeds into an integration, which eventually reaches a destination (like Remote Write).

  5. What is Grafana Agent?

    main

    Grafana Agent is an OpenTelemetry Collector distribution with a Terraform-inspired configuration. It is designed to be a flexible, performant, and vendor-neutral telemetry collector.

    Core concepts:

    • Components: The fundamental building blocks of the agent.
    • Pipelines: Programmable observability pipelines formed by wiring components together to collect, process, and deliver telemetry.

    Grafana Agent supports multiple ecosystems, including:

    • Prometheus
    • OpenTelemetry
    • Grafana Open Source (Loki, Grafana, Tempo, Mimir, Pyroscope)
    • Telemetry Signals: Metrics, logs, traces, and continuous profiles.
  6. What is River and how does it work in Grafana Agent Flow?

    main

    River is a declarative, HCL-inspired expression language designed specifically for Grafana Agent Flow. Unlike static configuration formats like YAML, River is an embedded language intended for continuous runtime evaluation.

    Key Characteristics

    • Declarative: Users define the desired state of the configuration, which maps naturally to configuration files.
    • Expression-based: Settings for components are derived from expressions that can reference and mutate the outputs of other components.
    • Go Integration: River natively supports passing around and invoking real Go values (such as interfaces and channels) and Go functions. This allows users to construct complex data pipelines using Go APIs without needing to understand the underlying implementation.
    • Continuous Evaluation: Because it is an embedded language, the configuration can adapt dynamically to a changing environment at runtime.

    Use Cases for Expressions

    Instead of requiring dedicated components for every possible task, River expressions allow you to:

    • Merge Metadata: Combine labels from distinct sources (e.g., merging Kubernetes namespace labels with pod labels).
    • Chain Discoveries: Feed the output of one service discovery mechanism (like Kubernetes Service Discovery) into another (like HTTP Service Discovery).
    • Conditional Logic: Implement custom logic, such as adjusting rate limits based on specific timeframes or business logic.
  7. What is the Grafana Agent Operator?

    main

    The Grafana Agent Operator is a Kubernetes operator designed for the static mode of Grafana Agent. It automates the deployment and configuration of Grafana Agents to collect telemetry data from Kubernetes resources.

    Supported Telemetry Collection

    The operator consumes several custom resources to discover and collect data:

    • ServiceMonitor (Prometheus Operator): Collects metrics from Kubernetes Services.
    • PodMonitor (Prometheus Operator): Collects metrics from Kubernetes Pods.
    • Probe (Prometheus Operator): Collects metrics from Kubernetes Ingresses.
    • PodLogs (Custom resource): Collects logs from Kubernetes Pods.

    Key Limitations and Notes

    • No Traces: The Grafana Agent Operator does not collect traces.
    • Beta Status: The operator is currently in Beta and is subject to changes or removal.
    • Grafana Cloud Users: If you are sending data to Grafana Cloud, it is recommended to use the Kubernetes Monitoring solution instead, as it provides a simplified setup with preconfigured dashboards and alerts.
  8. Use module.git to load components from a Git repository

    main

    module.git is a module loader component that retrieves a module from a Git repository and executes the components defined within it.

    To use it, specify the repository and the path to the .river file within that repository. You can also pass configuration values to the module using an arguments block.

    module.git "LABEL" {
      repository = "GIT_REPOSTORY"
      path       = "PATH_TO_MODULE"
    
      arguments {
        MODULE_ARGUMENT_1 = VALUE_1
        MODULE_ARGUMENT_2 = VALUE_2
        ...
      }
    }
  9. Convert OTLP attributes to Loki labels using hint attributes

    main

    By default, otelcol.exporter.loki does not convert OTLP attributes into Loki labels. To enable this conversion, you must inject specific "hint" attributes into the OTLP log using an otelcol.processor.attributes component:

    • Resource Attributes: To convert OTLP resource attributes to Loki labels, use the loki.resource.labels hint attribute.
    • Log Attributes: To convert OTLP log attributes to Loki labels, use the loki.attribute.labels hint attribute.

    Label Translation: Labels are translated into a Prometheus-compatible format. For example, host.name becomes host_name and 2 cents becomes key_2_cents.

    otelcol.processor.attributes "default" {
      action {
        key = "loki.attribute.labels"
        action = "insert"
        value = "event.domain, event.name"
      }
      
      action {
        key = "loki.resource.labels"
        action = "insert"
        value = "service.name, service.namespace"
      }
      
      output {
        logs = [otelcol.exporter.loki.default.input]
      }
    }