admin管理员组

文章数量:1429940

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.

本文标签: How to add AWS labels to Loki logs with AlloyStack Overflow