Is it possible (in NRQL) to calculate a rate, based on counter value from events? For example - I have K8sContainerSample events with restartCount field that is increasing over time (with every sample) and I want to calculate restarts per hour.
Hi @adam.m1, just wondering if you could explain your use case a bit more? Are you looking for the total number of restarts in the last 60 minutes? Would something like the following be along the lines of what you are looking for:
SELECT sum(restartCount) FROM K8sContainerSample SINCE 60 MINUTES AGO
Hi @rdouglas, thanks for the suggestion but it will not work -
restartCount field stores the number of restarts from the start of the container. The field value may only increase or not change over time. Currently I use the following query:
SELECT max(restartCount) - min(restartCount) FROM K8sContainerSample FACET entityName 1 hour SINCE 1 HOUR AGO
Hmmm so the counter field is accumulative is that correct? Have you tried using something like:
Yes it is accumulative. I need to detect whether the container has restarted in the last hour and I want to allow a few restarts on staging environments. The most straightforward solution (in my opinion) is to calculate rate of restarts per hour and set different rate alert thresholds for all my environments. Previously I used Graphite and Prometheus and they provide a function for converting accumulative counter metrics to rate per unit of time.
@philweber yes I tried it, but I have no idea what function I should apply on
restartCount field to get valid results (rate of restarts per hour). The function looks like it’s designed to work with whole event not with one specific event field.
Yes it solves my problem
Okay great. I think your NRQL has a slight mistake in it. For reference for other folks stumbling upon this thread:
SELECT max(restartCount) - min(restartCount) FROM K8sContainerSample FACET entityName SINCE 1 HOUR AGO