A common question we get from ECS users is how the Scalyr Agent can be configured to use specific parsers. The steps below explain how to configure this in detail.
Create an output directory for logs
On the host machine, create a directory (/var/log/applicationLog in this example) where logs from your application container will be stored.
- The application container requires full read/write access to this directory and any log output from the application container will be stored here.
- The Scalyr Agent container also needs full access to this directory and will upload logs which are deposited there (more in step #4).
Update the task definition of the application container
Define the host directory from step #1 as a volume:
"volumes": [ { "efsVolumeConfiguration": null, "name": "log-vol", "host": { "sourcePath": "/var/log/applicationLog" }, "dockerVolumeConfiguration": null } ]
Next, mount the host volume as the directory where the application writes its logs within the application container. Any logs that the application writes will now be stored on the host.
"mountPoints": [
{
"readOnly": null,
"containerPath": "/var/log/logtest",
"sourceVolume": "log-vol"
}
],
In this example, if your application writes to /var/log/logtest, its log events will be saved to /var/log/applicationLog on the host machine.
Update the task definition of the Scalyr Agent container
Define the host directory from step #1 as a volume:
"volumes": [
{
"efsVolumeConfiguration": null,
"name": "log-vol",
"host": {
"sourcePath": "/var/log/applicationLog"
},
"dockerVolumeConfiguration": null
}
]
Then, mount the host directory volume within the Scalyr Agent container.
"mountPoints": [
{
"readOnly": null,
"containerPath": "/var/scalyr/logtest",
"sourceVolume": "log-vol"
}
],
Modify the Scalyr Agent configuration
Update the agent.json within the Scalyr Agent container to include the path to the log file and assign a parser. For example,
"logs": [
{
"path": "/var/scalyr/logtest/app.log",
"attributes": {"parser": "appLog"}
}
]
Once you have confirmed that this works as expected, create a Docker image of the Scalyr Agent container and upload it to ECR (see: https://app.scalyr.com/help/install-agent-ecs#creating-and-uploading-custom-image). This ensures the changes you made to the Scalyr Agent configuration will persist.
Comments
0 comments
Please sign in to leave a comment.