Search code examples
grafanafluentdgrafana-loki

Fluentd Dynamic Labeling for Grafana Loki


I set up fluentd with grafana loki, Since I have multiple microservices propagate logs to the fluentd I am unable to distinguish and filter the logs in Grafana. Could anyone help me to add my tag as a label so that I can query it like in grafana {tag:"tag.name"}. My fluentd config added below.

<match TEST.**>
  @type loki  
  url "http://localhost:3100" 
 flush_interval 1s 
 flush_at_shutdown true 
 buffer_chunk_limit 1m  
extra_labels {"job":"TEST", "host":"ward_workstation", "agent":"fluentd"}  
<label>    
  filename  
</label>
</match>

Solution

  • Use Dynamic Labeling

    <filter TEST.**>
        @Type record_transformer
          <record>
            tag_name ${tag}
    </record>
    </filter>
    
    
    
    <match TEST.**>
      @type loki  
      url "http://localhost:3100" 
     flush_interval 1s 
     flush_at_shutdown true 
     buffer_chunk_limit 1m  
    extra_labels {"job":"TEST", "host":"ward_workstation", "agent":"fluentd"}  
    <label>    
      tag_name
    </label>
    </match>