VictoriaMetrics/app/vmselect/prometheus/util.qtpl

47 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-05-22 23:16:55 +02:00
{% import (
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
) %}
{% stripspace %}
{% func metricNameObject(mn *storage.MetricName) %}
{
{% if len(mn.MetricGroup) > 0 %}
"__name__":{%qz= mn.MetricGroup %}{% if len(mn.Tags) > 0 %},{% endif %}
{% endif %}
{% for j := range mn.Tags %}
{% code tag := &mn.Tags[j] %}
{%qz= tag.Key %}:{%qz= tag.Value %}{% if j+1 < len(mn.Tags) %},{% endif %}
{% endfor %}
}
{% endfunc %}
{% func metricRow(timestamp int64, value float64) %}
[{%f= float64(timestamp)/1e3 %},"{%f= value %}"]
{% endfunc %}
{% func valuesWithTimestamps(values []float64, timestamps []int64) %}
[
{% if len(values) > 0 %}
2020-07-13 20:31:19 +02:00
{% code /* inline metricRow call here for the sake of performance optimization */ %}
[{%f= float64(timestamps[0])/1e3 %},"{%f= values[0] %}"]
{% code
timestamps = timestamps[1:]
values = values[1:]
2019-05-22 23:16:55 +02:00
%}
2020-07-13 20:31:19 +02:00
{% if len(values) > 0 %}
{%code
// Remove bounds check inside the loop below
_ = timestamps[len(values)-1]
%}
{% for i, v := range values %}
{% code /* inline metricRow call here for the sake of performance optimization */ %}
,[{%f= float64(timestamps[i])/1e3 %},"{%f= v %}"]
{% endfor %}
{% endif %}
2019-05-22 23:16:55 +02:00
{% endif %}
]
{% endfunc %}
{% endstripspace %}