LoginSignup
8
3

More than 5 years have passed since last update.

CloudWatch AgentでCloudWatch Logsに転送するログファイルのエンコードを指定する

Posted at

結論

パラメータストアのjsonに encoding を追加して適用します。

{
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "C:\\Application\\appname\\logs\\logfile.log",
                        "log_group_name": "logfile.log",
                        "encoding": "shift_jis",
                        "timestamp_format": "%m/%d/%y %H:%M:%S"
                    }
                ]
            }
        }
    }
}

ドキュメントにはエンコード指定の方法が載っていない?

WindowsインスタンスからShift JISのログをそのままCloudWatch Logsに転送したところAWSコンソール上で文字化けしてしまったので、エンコード指定の方法を調べたのですがCloudWatch Agentのドキュメントには記載がありませんでした。CloudWatch Logsのドキュメントには encoding を指定するように記載があります。

そこでCloudWatch Logsのドキュメントを参考に、冒頭のようにパラメータストアのjsonに encoding を追加するとうまく表示されるようになりました。ドキュメントに記載はありませんがある程度の互換性はあるようです。
CloudWatch Logsで出来ていたあの設定、CloudWatch Agentではどうするんだろう?という時はLogsを参考に値を入れてみると良さそうです。

対応していない設定はRun Commandでパラメータ適用時にちゃんと怒られるので大丈夫です。(Agentにdatetime_formatでタイムスタンプを指定しようとして弾かれました)

Start configuration validation...

Invalid Json input schema.

Under path : /logs/logs_collected/files/collect_list/0 | Error : Additional property datetime_format is not allowed

Configuration validation first phase failed. Agent version: 1.208.0. Verify the JSON input is only using features supported by this version.

----------ERROR-------

2018/02/21 12:28:25 I! AmazonCloudWatchAgent Version 1.208.0.

failed to run commands: exit status 1
8
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
8
3