mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
aadbd014ff
The data can be exported via [/api/v1/export/native](https://victoriametrics.github.io/#how-to-export-data-in-native-format) handler and imported via [/api/v1/import/native](https://victoriametrics.github.io/#how-to-import-data-in-native-format) handler.
95 lines
2.3 KiB
Text
95 lines
2.3 KiB
Text
{% import (
|
|
"github.com/valyala/quicktemplate"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
|
|
{% func ExportPrometheusLine(xb *exportBlock) %}
|
|
{% if len(xb.timestamps) == 0 %}{% return %}{% endif %}
|
|
{% code bb := quicktemplate.AcquireByteBuffer() %}
|
|
{% code writeprometheusMetricName(bb, xb.mn) %}
|
|
{% for i, ts := range xb.timestamps %}
|
|
{%z= bb.B %}{% space %}
|
|
{%f= xb.values[i] %}{% space %}
|
|
{%dl= ts %}{% newline %}
|
|
{% endfor %}
|
|
{% code quicktemplate.ReleaseByteBuffer(bb) %}
|
|
{% endfunc %}
|
|
|
|
{% func ExportJSONLine(xb *exportBlock) %}
|
|
{% if len(xb.timestamps) == 0 %}{% return %}{% endif %}
|
|
{
|
|
"metric":{%= metricNameObject(xb.mn) %},
|
|
"values":[
|
|
{% if len(xb.values) > 0 %}
|
|
{% code values := xb.values %}
|
|
{%f= values[0] %}
|
|
{% code values = values[1:] %}
|
|
{% for _, v := range values %}
|
|
,{%f= v %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
],
|
|
"timestamps":[
|
|
{% if len(xb.timestamps) > 0 %}
|
|
{% code timestamps := xb.timestamps %}
|
|
{%dl= timestamps[0] %}
|
|
{% code timestamps = timestamps[1:] %}
|
|
{% for _, ts := range timestamps %}
|
|
,{%dl= ts %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
}{% newline %}
|
|
{% endfunc %}
|
|
|
|
{% func ExportPromAPILine(xb *exportBlock) %}
|
|
{
|
|
"metric": {%= metricNameObject(xb.mn) %},
|
|
"values": {%= valuesWithTimestamps(xb.values, xb.timestamps) %}
|
|
}
|
|
{% 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 %}
|