- record: stat__change__timestamp
# timestamp of when the metric last changed
expr:
timestamp(changes({exported_job=~"visor_.*", alertname="", offset="", original_name!="", original_stat=""}[${SCRAPE_INTERVAL_AND_A_HALF}]) > 0)
or ignoring(stat, monitor, original_stat)
stat__change__timestamp
labels:
stat: true
original_stat: stat__change__timestamp # This keeps the stat__offset of this metric unique from the original
- record: stat__change__seconds_since
# number of seconds since the metric value changed # this will highlight whether a script is not recording correctly or if a metric is stagnant
expr:
time() - stat__change__timestamp
labels:
stat: true
original_stat: stat__change__seconds_since # This keeps the stat__offset of this metric unique from the original
```
An alternative to `changes()` (pulled from a different prometheus server I manage, hence the different label criteria):
```rules.yaml
timestamp(
(
kafka_consumer_group_lag{topic!~".*verification_id|.*submission_id|.*__leader|.*-changelog|.*_Internal.*", group!="BifrostMonitor_Bifrost_MongoTopicDumper"}
-
kafka_consumer_group_lag{topic!~".*verification_id|.*submission_id|.*__leader|.*-changelog|.*_Internal.*", group!="BifrostMonitor_Bifrost_MongoTopicDumper"} offset ${SCRAPE_INTERVAL_DOUBLE}
) != 0
)
```
When I say `SCRAPE_INTERVAL`, I mean
```prometheus.yaml
global:
scrape_interval: ${SCRAPE_INTERVAL} # Default is every minute.
evaluation_interval: ${EVALUATION_INTERVAL} # default is every minute.
alerting:
...
```
I can't remember why I chose `_AND_A_HALF` for `changes()` and yet `_DOUBLE` for subtracting the offset. Don't think it much matters.