mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
33 lines
882 B
Text
33 lines
882 B
Text
{% import (
|
|
"math"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
|
|
// Federate writes rs in /federate format.
|
|
// See https://prometheus.io/docs/prometheus/latest/federation/
|
|
{% func Federate(rs *netstorage.Result) %}
|
|
{% code
|
|
values := rs.Values
|
|
timestamps := rs.Timestamps
|
|
%}
|
|
{% if len(timestamps) == 0 || len(values) == 0 %}{% return %}{% endif %}
|
|
{% code
|
|
lastValue := values[len(values)-1]
|
|
%}
|
|
{% if math.IsNaN(lastValue) %}
|
|
{% comment %}
|
|
This is most likely a staleness marker.
|
|
Return nothing after the staleness marker.
|
|
See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3185
|
|
{% endcomment %}
|
|
{% return %}
|
|
{% endif %}
|
|
{%= prometheusMetricName(&rs.MetricName) %}{% space %}
|
|
{%f= lastValue %}{% space %}
|
|
{%dl= timestamps[len(timestamps)-1] %}{% newline %}
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|