2019-05-22 21:16:55 +00:00
|
|
|
{% import (
|
|
|
|
"github.com/valyala/quicktemplate"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
|
|
|
) %}
|
|
|
|
|
|
|
|
{% stripspace %}
|
|
|
|
|
2020-09-26 01:29:45 +00:00
|
|
|
{% func ExportPrometheusLine(xb *exportBlock) %}
|
|
|
|
{% if len(xb.timestamps) == 0 %}{% return %}{% endif %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{% code bb := quicktemplate.AcquireByteBuffer() %}
|
2020-09-26 01:29:45 +00:00
|
|
|
{% code writeprometheusMetricName(bb, xb.mn) %}
|
|
|
|
{% for i, ts := range xb.timestamps %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{%z= bb.B %}{% space %}
|
2020-09-26 01:29:45 +00:00
|
|
|
{%f= xb.values[i] %}{% space %}
|
2019-10-17 15:22:56 +00:00
|
|
|
{%dl= ts %}{% newline %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% code quicktemplate.ReleaseByteBuffer(bb) %}
|
|
|
|
{% endfunc %}
|
|
|
|
|
2020-09-26 01:29:45 +00:00
|
|
|
{% func ExportJSONLine(xb *exportBlock) %}
|
|
|
|
{% if len(xb.timestamps) == 0 %}{% return %}{% endif %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{
|
2020-09-26 01:29:45 +00:00
|
|
|
"metric":{%= metricNameObject(xb.mn) %},
|
2019-05-22 21:16:55 +00:00
|
|
|
"values":[
|
2020-09-26 01:29:45 +00:00
|
|
|
{% if len(xb.values) > 0 %}
|
|
|
|
{% code values := xb.values %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{%f= values[0] %}
|
|
|
|
{% code values = values[1:] %}
|
|
|
|
{% for _, v := range values %}
|
|
|
|
,{%f= v %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
],
|
|
|
|
"timestamps":[
|
2020-09-26 01:29:45 +00:00
|
|
|
{% if len(xb.timestamps) > 0 %}
|
|
|
|
{% code timestamps := xb.timestamps %}
|
2019-10-17 15:22:56 +00:00
|
|
|
{%dl= timestamps[0] %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{% code timestamps = timestamps[1:] %}
|
|
|
|
{% for _, ts := range timestamps %}
|
2019-10-17 15:22:56 +00:00
|
|
|
,{%dl= ts %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
]
|
|
|
|
}{% newline %}
|
|
|
|
{% endfunc %}
|
|
|
|
|
2020-09-26 01:29:45 +00:00
|
|
|
{% func ExportPromAPILine(xb *exportBlock) %}
|
2019-05-22 21:16:55 +00:00
|
|
|
{
|
2020-09-26 01:29:45 +00:00
|
|
|
"metric": {%= metricNameObject(xb.mn) %},
|
|
|
|
"values": {%= valuesWithTimestamps(xb.values, xb.timestamps) %}
|
2019-05-22 21:16:55 +00:00
|
|
|
}
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% func ExportPromAPIResponse(resultsCh <-chan *quicktemplate.ByteBuffer) %}
|
|
|
|
{
|
|
|
|
"status":"success",
|
|
|
|
"data":{
|
|
|
|
"resultType":"matrix",
|
|
|
|
"result":[
|
|
|
|
{% code bb, ok := <-resultsCh %}
|
|
|
|
{% if ok %}
|
|
|
|
{%z= bb.B %}
|
|
|
|
{% code quicktemplate.ReleaseByteBuffer(bb) %}
|
|
|
|
{% for bb := range resultsCh %}
|
|
|
|
,{%z= bb.B %}
|
|
|
|
{% code quicktemplate.ReleaseByteBuffer(bb) %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% func ExportStdResponse(resultsCh <-chan *quicktemplate.ByteBuffer) %}
|
|
|
|
{% for bb := range resultsCh %}
|
|
|
|
{%z= bb.B %}
|
|
|
|
{% code quicktemplate.ReleaseByteBuffer(bb) %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfunc %}
|
|
|
|
|
|
|
|
{% func prometheusMetricName(mn *storage.MetricName) %}
|
|
|
|
{%z= mn.MetricGroup %}
|
|
|
|
{% if len(mn.Tags) > 0 %}
|
|
|
|
{
|
|
|
|
{% code tags := mn.Tags %}
|
|
|
|
{%z= tags[0].Key %}={%qz= tags[0].Value %}
|
|
|
|
{% code tags = tags[1:] %}
|
|
|
|
{% for i := range tags %}
|
|
|
|
{% code tag := &tags[i] %}
|
|
|
|
,{%z= tag.Key %}={%qz= tag.Value %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|