Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudWatch input metrics start time calculated from period, not interval, leading to missing data #4643

Closed
jcmcken opened this issue Sep 6, 2018 · 5 comments
Labels
area/aws AWS plugins including cloudwatch, ecs, kinesis feature request Requests for new plugin and for new features to existing plugins
Milestone

Comments

@jcmcken
Copy link
Contributor

jcmcken commented Sep 6, 2018

Here's something I'm trying to accomplish:

I want to retrieve certain EC2 metrics every 15 minutes. I want to retrieve the metrics in 5 minute periods, so that for a single metric and dimension, I should have 3 data points. Here's an example using AWSCLI:

# aws cloudwatch get-metric-statistics --namespace AWS/EC2 --region us-east-1 --period 300 --start-time $(date -d '15 minutes ago' --iso-8601=s) --end-time $(date --iso-8601=s) --statistics Average --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-deadbeef
{
    "Datapoints": [
        {
            "Timestamp": "2018-09-06T17:48:00Z",
            "Average": 12.0,
            "Unit": "Percent"
        },
        {
            "Timestamp": "2018-09-06T17:58:00Z",
            "Average": 37.0,
            "Unit": "Percent"
        },
        {
            "Timestamp": "2018-09-06T17:53:00Z",
            "Average": 25.0,
            "Unit": "Percent"
        }
    ],
    "Label": "CPUUtilization"
}

Looking at the plugin code, though, the "start time" is calculated using the period. So, assuming we ignore the delay setting just to simplify, setting period to 5m and interval to 15m gives me a single data point aggregated over 5 minutes from 5 minutes ago (with 2 data points at 10 and 15 minutes ago skipped entirely).

I'm not sure if this is a bug or not, but it seems like the start time should be using the interval. In such a case, setting period to 5m and interval to 15m gives me exactly what I want: a single API call issued every 15 minutes that contains 3 data points (5, 10, 15 minutes ago)

@danielnelson
Copy link
Contributor

Interval is not exposed to the plugin, but I think the idea is good. Instead of always taking the last point, collect all points since the last call. Is this something you could work on?

@danielnelson danielnelson added feature request Requests for new plugin and for new features to existing plugins area/aws AWS plugins including cloudwatch, ecs, kinesis labels Sep 6, 2018
@jcmcken
Copy link
Contributor Author

jcmcken commented Sep 6, 2018

I'm not super experienced with Go, but I can give it a whirl. Would you want a new parameter added, since interval isn't exposed to the plugin? Or were you thinking to memoize the last retrieval time and use that as the new start time?

@danielnelson
Copy link
Contributor

I think the later method would work best. On the first time Gather is called we would just grab a single period and save the end-time in the plugin struct, then on subsequent calls we would use the previous value for the start-time. If an error occurs during Gather, we should still update the end-time so that we don't fall behind.

@jcmcken
Copy link
Contributor Author

jcmcken commented Sep 10, 2018

I need to inquire about the CLA with my company before signing, but the PR is up for review.

I decided to store the full window info in the plugin struct, and modify a few things with that assumption in mind. But I can change it if there's a different preferred way of doing it

Is there anything I need to update in the README?

@jcmcken
Copy link
Contributor Author

jcmcken commented Sep 10, 2018

All the PR requirements are completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/aws AWS plugins including cloudwatch, ecs, kinesis feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
Development

No branches or pull requests

2 participants