最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add AWS labels to Loki logs with Alloy? - Stack Overflow

programmeradmin0浏览0评论

I have an alloy config that takes docker logs, adds a container label using the provided meta data from discovery.docker, and dispatches them to Loki -- this works great.

However, I'm struggling to find out how to add other labels to my logs, such as the instanceId of my AWS EC2 instance, or other relevant info about the machine it's running on.

Here is my config:

discovery.docker "local" {
  host = "unix:///var/run/docker.sock"
}

// Add a "container" label
discovery.relabel "docker" {
  targets = []
  
  rule {
      source_labels = ["__meta_docker_container_name"]
      regex = "/(.*)"
      target_label = "container"
  }
}

// Read logs from docker containers
loki.source.docker "local" {
  host = "unix:///var/run/docker.sock"
  targets = discovery.docker.local.targets
  forward_to = [loki.write.grafana_cloud.receiver]
  relabel_rules = discovery.relabel.docker.rules
}

// Send to Loki
loki.write "grafana_cloud" {
  endpoint {
    url = "loki:3100/loki/api/v1/push"

    basic_auth {
      username = sys.env("LOKI_USER")
      password = sys.env("LOKI_TOKEN")
    }
  }
}

My question

How can I modify this to add additional labels to my logs about the EC2 server? I can see there's an discovery.ec2 component, but not sure how I can get that to link up with my logs.

发布评论

评论列表(0)

  1. 暂无评论