I manage several apps that write various pieces of data to the local file system and rely on Fluentd to ship them to s3. There is solid monitoring around the fluentd aggregator process, but I wanted better visibility and alerting when things aren’t written to s3 as expected.
The solution I came up with was a custom Datadog check. The files I am monitoring are written into a bucket named something like example-logs/data/event-files/year/month/day
. A new path is set up in the s3 bucket for the current day’s date, e.g. logs/data/example-log/2018/08/15
each day. The Datadog check sends the count of objects in the current date’s directory as a gauge. You can then monitor that objects are created each day as expected and at a normal rate.
![]({{ site.url }}/assets/img/screen-shot-2018-08-28-at-8-41-07-pm.png)
Here is an example config
init_config:
instances:
# this will monitor s3://example-logs/data/production/event-log/<year>/<month>/<day>
- bucket: example-logs
prefix: data/production/event-log
tags:
- 'env:production'
- 'log:event-log'
- bucket: example-logs
prefix: data/staging/event-log
tags:
- 'env:staging'
- 'log:event-log'
The check will add the current date path to the prefix automatically.
How to Set it Up for Yourself Link to heading
- Install boto3 via the Datadog embedded pip
/opt/datadog-agent/embedded/bin/pip install boto3
- add s3_object_count.py to /etc/datadog-agent/checks.d
- add your config file to /etc/datadog-agent/conf.d/s3_object_count.d
The code for the check is pretty simple.
See https://github.com/dschaaff/datadog-checks for the full source.