fluent-plugin-prometheus icon indicating copy to clipboard operation
fluent-plugin-prometheus copied to clipboard

fluent prometheus metric-label bring unreadable code

Open zhboseu opened this issue 4 years ago • 0 comments

  • description

In our scenario, fluentd-plugin-prometheus was used to collect metrics, some metrics label parsed from regexp, while some fields are not ASCII. Result show unreadble code

  • fluentd conf
<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

<source>
  @type prometheus
  port 24231
  bind 0.0.0.0
  metrics_path /metrics
  aggregated_metrics_path /aggregated_metrics
</source>

<filter **>
  @type record_transformer
  char_encoding utf-8
</filter>

<filter test.log>
  @type parser
  key_name log
  reserve_time true
  reserve_data true
  emit_invalid_record_to_error true
  <parse>
    @type regexp
    expression /(?<logTime>^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}),(?<spi>.*),(?<spiDesc>.*),(?<duration>\d+)$/
    time_key logTime
    time_format %Y-%m-%d %H:%M:%S.%L
    keep_time_key true
    null_empty_string true
    types duration:integer,spiDesc:string
  </parse>
</filter>

<match test.log>
  @type copy
  <store>
    @type stdout
  </store>
  <store>
    @type prometheus
    <metric>
        name message_log_counter
        type counter
        desc The total number of log in message.
        <labels>
            spi ${spi}
            spiDesc ${spiDesc}
        </labels>
    </metric>
    <metric>
        name message_log_gauge
        type gauge
        desc The gauge number of log in message.
        key duration
        <labels>
            spi ${spi}
            spiDesc ${spiDesc}
        </labels>
    </metric>
  </store>
</match>
  • reproduce scription
echo '{"log":"2020-05-05 11:17:53.755,test,テスト,49"}' |fluent-cat  test.log
  • result

we get correct stdout

2020-05-06 15:00:18.062825596 +0800 test.log: {"log":"2020-05-05 11:17:53.755,test,テスト,49","logTime":"2020-05-05 11:17:53.755","spi":"test","spiDesc":"テスト","duration":49}

but metric labels are unreadble

# TYPE message_log_counter counter # HELP message_log_counter The total number of log in message. message_log_counter{spi="test",spiDesc="銉嗐偣銉�"} 1.0 # TYPE message_log_gauge gauge # HELP message_log_gauge The gauge number of log in message. message_log_gauge{spi="test",spiDesc="銉嗐偣銉�"} 49.0

what's wrong?

  • version fluent-plugin-prometheus 1.7.3 fluentd 1.10.3 ruby 2.7.1p83

zhboseu avatar May 06 '20 07:05 zhboseu