3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DogStatsD(Datadog)でUTF-8文字列を送る場合

Last updated at Posted at 2016-02-17

APIやfluendでこちらのPluginを使ってローカルのDogStatsDに対してEvent形式で送信する場合、デフォルトだと以下の様なエラーが発生する

2016-02-17 22:14:54 JST | ERROR | dd.dogstatsd | dogstatsd(dogstatsd.py:174) | Error flushing metrics
Traceback (most recent call last):
  File "/opt/datadog-agent/agent/dogstatsd.py", line 144, in flush
    self.submit_events(events)
  File "/opt/datadog-agent/agent/dogstatsd.py", line 202, in submit_events
    self.submit_http(url, json.dumps(payload), headers)
  File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/simplejson/__init__.py", line 370, in dumps
    return _default_encoder.encode(obj)
  File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/simplejson/encoder.py", line 269, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/simplejson/encoder.py", line 348, in iterencode
    return _iterencode(o, 0)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe5 in position 105: unexpected end of data

デフォルトではパフォーマンスの問題で、UTF-8のデコードを行わない設定となっている模様

設定変更はよく見ればわかるが、以下の様な所を変更する必要がある

/etc/dd-agent/datadog.conf
# 大体131行目

# By default, dogstatsd supports only plain ASCII packets. However, most
# (dog)statsd client support UTF8 by encoding packets before sending them
# this option enables UTF8 decoding in case you need it.
# However, it comes with a performance overhead of ~10% in the dogstatsd
# server. This will be taken care of properly in the new gen agent core.
# utf8_decoding: false
utf8_decoding: true <-- # これでUTF-8デコード有効化

備考

上記で送信可能なようになるが、
もし type: event でログをペイロードとして載せている場合、
送信可能なペイロードに4000bytesの上限がある模様。
# dd-agentのどこかにマジックナンバー的に制限が記載されてたはず

受付時にその辺のチェックをして切り落としてくれたりしないので、
fluentdを使う時はこんな感じにして切り落としてからDogstatsdに送ってる。

<match dd.event.error>
  type record_reformer
  tag reformed.dd.event.error
  renew_record false
  enable_ruby true

  <record>
    type event
    key production
    title production
    text ${message[0, 4000].gsub(/(\n)/, '')}
  </record>
</match>

<match reformed.dd.event.error>
  type dogstatsd

  host localhost
  port 8125

  use_tag_as_key false

  flat_tags true
</match>
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?