GCP Stackdriver Monitoring Cumulative custom metric start and end time errors
Asked Answered
B

0

6

EDIT: I think I figured out the issue. It's only the start time that needs to stay the same up until the accumulated number needs to be reset, so in my case the start of the day will reset after midnight but the end time will always be the current time. I'm still testing this so I'll close this question as soon as I get more results.

EDIT2: So with the time interval set to start at the beginning of each day and end at the time of sending, the charts still display a spike for every call to client.create_time_series. Here's an example of what I'm looking for (ignore the right axis, the numbers should be higher but my photoshop skills are not great): enter image description here And this is what I currently get: enter image description here

Before I explain the error, here is what I'm trying to achieve with this custom monitoring metric. My program logs a number of processed data every so often, and I want to see the total number processed every day. So I thought the Cumulative metric was the right choice, having the interval reset every day. The problem is that I'm unsure how to achieve this.

Here is what I'm doing. Every time some new data is processed, I have that added to the metric using client.create_time_series(project_name, [series]) where [series] contains a single point.value.int64_value of the number of data processed at that time. Now the issue I have is with the interval. I thought that the interval should be the start and end time of each day, which I thought would have the metric start over from 0 at the end of the day. So I did this:

point                             = series.points.add()
point.value.int64_value           = num
startDay                          = time.mktime(datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0).timetuple())
endDay                            = time.mktime(datetime.datetime.now().replace(hour=23, minute=59, second=59, microsecond=0).timetuple())
point.interval.start_time.seconds = int(startDay)
point.interval.start_time.nanos   = int((startDay - point.interval.start_time.seconds) * 10**9)
point.interval.end_time.seconds   = int(endDay)
point.interval.end_time.nanos     = int((endDay - point.interval.end_time.seconds) * 10**9)
client.create_time_series(project_name, [series])

And I get this error:

400 Field timeSeries[0].points[0].interval.end had an invalid value of \"2018-10-04T16:59:59-07:00\": The end time is too far in the future. A point cannot be written more than 5 minutes into the future.

If I set the time interval to just the current time, I just get a bunch of spikes in my chart for each metric sent. What I want to see is a single line that accumulates over the course of 1 day, from 00:00:00 to 23:59:59, and then resets at 00:00:00 again. I want this so that I can see how much data is processed in a day in relation to every other day so I can see if there are any abnormalities in my process.

So I think I may have misunderstood how the cumulative metric works. Is there a better way to achieve what I'm trying to do?

Botch answered 4/10, 2018 at 19:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.