「GRAFANA-ALLOY」- Grafana Alloy

认识

官网:https://grafana.com/oss/alloy-opentelemetry-collector/
文档:https://grafana.com/docs/alloy/latest/
仓库:https://github.com/grafana/alloy

Grafana Alloy combines the strengths of the leading collectors into one place. Whether observing applications, infrastructure, or both, Grafana Alloy can collect, process, and export telemetry signals to scale and future-proof your observability approach.

性质

—— 功能 | 特性

提供调试功能 Troubleshoot

https://grafana.com/docs/alloy/latest/troubleshoot/

构建

—— 配置、部署、维护

https://grafana.com/docs/alloy/latest/set-up/install/

独立安装:https://grafana.com/docs/alloy/latest/set-up/run/binary/

针对 Kubernetes 环境,例如,Pod、Events、……,需要通过 Helm Chart 部署到集群中。

通过 apt/deb 安装

Install Grafana Alloy on Linux | Grafana Alloy documentation | https://grafana.com/docs/alloy/latest/set-up/install/linux/

sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

sudo apt-get update

sudo apt-get install alloy

迁移

Migrate Grafana Agent Flow to Grafana Alloy | Grafana Alloy documentation

应用

参考 Alloy configuration syntax 文档,其简单地演示使用 Alloy 抓取日志并写入 Loki 的方法,以及相关概念。

场景 | Write to Loki

  loki.write "default" {
    endpoint {
      url = "http://loki-gateway.monitor.svc.cluster.local/loki/api/v1/push"
      headers = {
        "X-Scope-OrgID" = "<...>",
      }
      basic_auth {
          username = "<...>"
          password = "<...>"
      }
    }
    external_labels = {
      cluster = "<...>",
    }
  }

场景 | systemd Journal

  discovery.relabel "systemd_journal" {
    targets = []

    rule {
      source_labels = ["__journal__systemd_unit"]
      target_label  = "systemd_unit"
    }

    rule {
      source_labels = ["__journal__hostname"]
      target_label  = "hostname"
    }

    rule {
      source_labels = ["__journal_syslog_identifier"]
      target_label  = "syslog_identifier"
    }
  }

  loki.source.journal "systemd_journal" {
    max_age       = "12h0m0s"
    path          = "/var/log/journal"
    relabel_rules = discovery.relabel.systemd_journal.rules
    forward_to    = [loki.write.default.receiver]
    labels        = {
      job = "systemd-journal",
    }
  }

场景 | Logs | 采集 Kubernetes Pod 日志

Collect Kubernetes logs and forward them to Loki | Grafana Alloy documentation

该笔记将记录:通过 Grafana Alloy 采集 Kubernetes Logs and Events 日志的方法,以及相关问题的解决办法。

场景 | Events | 采集 Kubernetes Events 日志

该笔记将记录:通过 Grafana Alloy 采集 Kubernetes Logs and Events 日志的方法,以及相关问题的解决办法。