Amazon CloudWatch
Send logs and metrics to Amazon CloudWatch
The Amazon CloudWatch output plugin allows to ingest your records into the CloudWatch Logs service. Support for CloudWatch Metrics is also provided via EMF.
This is the documentation for the core Fluent Bit CloudWatch plugin written in C. It can replace the aws/amazon-cloudwatch-logs-for-fluent-bit Golang Fluent Bit plugin released last year. The Golang plugin was named cloudwatch
; this new high performance CloudWatch plugin is called cloudwatch_logs
to prevent conflicts/confusion. Check the amazon repo for the Golang plugin for details on the deprecation/migration plan for the original plugin.
See here for details on how AWS credentials are fetched.
Configuration Parameters
Getting Started
In order to send records into Amazon Cloudwatch, you can run the plugin from the command line or through the configuration file:
Command Line
The cloudwatch plugin, can read the parameters from the command line through the -p argument (property), e.g:
Configuration File
In your main configuration file append the following Output section:
Permissions
The following AWS IAM permissions are required to use this plugin:
Worker support
Fluent Bit 1.7 adds a new feature called workers
which enables outputs to have dedicated threads. This cloudwatch_logs
plugin has partial support for workers. The plugin can support a single worker; enabling multiple workers will lead to errors/indeterminate behavior.
Example:
If you enable a single worker, you are enabling a dedicated thread for your CloudWatch output. We recommend starting without workers, evaluating the performance, and then enabling a worker if needed. For most users, the plugin can provide sufficient throughput without workers.
Log Stream and Group Name templating using record_accessor syntax
Sometimes, you may want the log group or stream name to be based on the contents of the log record itself. This plugin supports templating log group and stream names using Fluent Bit record_accessor syntax.
Here is an example usage, for a common use case- templating log group and stream names based on Kubernetes metadata.
Recall that the kubernetes filter can add metadata which will look like the following:
Using record_accessor, we can build a template based on this object.
Here is our output configuration:
With the above kubernetes metadata, the log group name will be application-logs-ip-10-1-128-166.us-east-2.compute.internal.my-namespace
. And the log stream name will be myapp-5468c5d4d7-n2swr.myapp
.
If the kubernetes structure is not found in the log record, then the log_group_name
and log_stream_prefix
will be used instead, and Fluent Bit will log an error like:
Limitations of record_accessor syntax
Notice in the example above, that the template values are separated by dot characters. This is important; the Fluent Bit record_accessor library has a limitation in the characters that can separate template variables- only dots and commas (.
and ,
) can come after a template variable. This is because the templating library must parse the template and determine the end of a variable.
Assume that your log records contain the metadata keys container_name
and task
. The following would be invalid templates because the two template variables are not separated by commas or dots:
$task-$container_name
$task/$container_name
$task_$container_name
$taskfooo$container_name
However, the following are valid:
$task.$container_name
$task.resource.$container_name
$task.fooo.$container_name
And the following are valid since they only contain one template variable with nothing after it:
fooo$task
fooo____$task
fooo/bar$container_name
Metrics Tutorial
Fluent Bit has different input plugins (cpu, mem, disk, netif) to collect host resource usage metrics. cloudwatch_logs
output plugin can be used to send these host metrics to CloudWatch in Embedded Metric Format (EMF). If data comes from any of the above mentioned input plugins, cloudwatch_logs
output plugin will convert them to EMF format and sent to CloudWatch as JSON log. Additionally, if we set json/emf
as the value of log_format
config option, CloudWatch will extract custom metrics from embedded JSON payload.
Note: Right now, only cpu
and mem
metrics can be sent to CloudWatch.
For using the mem
input plugin and sending memory usage metrics to CloudWatch, we can consider the following example config file. Here, we use the aws
filter which adds ec2_instance_id
and az
(availability zone) to the log records. Later, in the output config section, we set ec2_instance_id
as our metric dimension.
The following config will set two dimensions to all of our metrics- ec2_instance_id
and az
.
AWS for Fluent Bit
Amazon distributes a container image with Fluent Bit and these plugins.
GitHub
github.com/aws/aws-for-fluent-bit
Amazon ECR Public Gallery
Our images are available in Amazon ECR Public Gallery. You can download images with different tags by following command:
For example, you can pull the image with latest version by:
If you see errors for image pull limits, try log into public ECR with your AWS credentials:
You can check the Amazon ECR Public official doc for more details
Docker Hub
Amazon ECR
You can use our SSM Public Parameters to find the Amazon ECR image URI in your region:
For more see the AWS for Fluent Bit github repo.
Last updated