Metric - show last consecutive values

Hi there,

We have data coming in from a health check we preform on our services, and i am trying to figure out a way to create a metric that will show the last consecutive fails.

The data field for the health-check is a binary 1 or 0 for the health of the service.

The metric should turn from green to yellow to red according to the number of consecutive fails, and if the last value was 1 (success) then it should turn back to green, since the consecutive number of fails is 0.

Example:

3 consecutive fails -> turn yellow.
1 success -> turn back to green.

Thanks in advance,
Itiel