Using Grafana flow agent - how do I add a custom label to logs being sent to Loki in river format

50 Views Asked by At

I am deploying Grafana Flow Agent to collect logs and send to Loki for log aggregation. I'm experiencing difficulty in creating a custom label to accompany logs from this agent's host for filtering and grouping with other similar servers.

I want to be able to filter the logs using {server_group="applications"|} |=''

Here is an example of the block where it is to add a new custom label from this host in the config.river file

loki.relabel "server_grouping" {
  forward_to = [loki.write.local.receiver]

  rule {
  action = "replace"
  source_labels = ["server_group"]     
  regex         = ".+" 
  target_label  = "server_group"
  replacement   = "applications"
  }
}

After adding this block and restarting the service - I am still unable to filter the logs in Grafana and the filter is not populating.

EDIT: I am also trying to use the external_labels argument in loki.write but my Grafana agent service is refusing to run - am I using the wrong syntax here?

loki.write "local" {
  endpoint {
    url = "http://loki:3100/loki/api/v1/push"
  }
  
  external_labels {
    server_group = "workstations"
  }
}

I am using the following reference Docs loki.relabel and loki.write

0

There are 0 best solutions below