Help us understand the problem. What is going on with this article?

td-agentをインストールしてRailsのログを見やすくする(後編)

More than 3 years have passed since last update.

前回
fluentdをインストールしてRailsのログを見やすくする(前編)

fluentdとtd-agentの違い

fluentdとtd-agentの違い

- td-agentはFluentdの安定版
- gem installするのはFluentd、RPMインストールするのはtd-agent
- gem installでもRPMインストールもfluent-catが同梱される

インストール手順

RPMインストール
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh

インストールバージョンの確認

$ td-agent --version
td-agent 0.12.29

実行ユーザの変更
$ vi /etc/td-agent/td-agent.conf

- TD_AGENT_USER=td-agent
- TD_AGENT_GROUP=td-agent
+ TD_AGENT_USER=root
+ TD_AGENT_GROUP=root

起動、リロード、停止

$sudo service td-agent start
$sudo service td-agent reload
$sudo service td-agent stop

fluent-catの使い方

fluent-catの場所

/opt/td-agent/embedded/bin/fluent-cat

環境変数に追加

export PATH=$PATH:/opt/td-agent/embedded/bin/

ログ出力テスト

echo '{"first":"hello"}' | fluent-cat debug.test

残りタスク

  • gem install fluent-plugin-rewrite
  • $ vi /vagrant/config/environments/development.rb設定変更
    • config.logger = Logger.new(config.paths["log"].first)
    • config.logger.formatter = Logger::Formatter.new
  • $ vi /vagrant/config/environment.rb設定変更(*1)
  • /etc/td-agent/td-agent.conf設定変更(<source><match>追加)
  • ログ確認

*1

class Logger
  class Formatter
    def call(severity, time, progname, msg)
      if msg.class.to_s == "String"
        msg = msg.gsub(/\n/, "")
        if msg.present? && !msg.include?("assets") && !msg.include?("erb")
          format = "[%s %d] %5s -- %s: \'%s\'\n"
          format % ["#{time.strftime('%Y-%m-%d %H:%M:%S')}.#{'%06d' % time.usec.to_s}",$$, severity, progname, msg2str(msg)]
        end
      end
    end
  end
end 
fk_2000
最近の関心事:YouTube、aws、IoT、マイコンボード エンジニア採用、IT導入担当、ブログメディア編集長( https://avatarworld.info/ )、 ↓こちらのYouTubeチャンネルで動画をアップしています。 https://www.youtube.com/channel/UCFM7KsJZC8uGJ1BRMT-4dFg
https://twitter.com/fk_2000
orylab
オリィ研究所は距離や身体的問題を克服し、あいたい人に会え、行きたいところに行ける未来を実現します。
http://orylab.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした