mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-24 03:06:48 +01:00
c448189f69
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6943 Updates https://github.com/VictoriaMetrics/victorialogs-datasource/issues/61
53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
{% stripspace %}
|
|
|
|
// StatsQueryRangeResponse generates response for /select/logsql/stats_query_range
|
|
{% func StatsQueryRangeResponse(rows []*statsSeries) %}
|
|
{
|
|
"status":"success",
|
|
"data":{
|
|
"resultType":"matrix",
|
|
"result":[
|
|
{% if len(rows) > 0 %}
|
|
{%= formatStatsSeries(rows[0]) %}
|
|
{% code rows = rows[1:] %}
|
|
{% for i := range rows %}
|
|
,{%= formatStatsSeries(rows[i]) %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
}
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func formatStatsSeries(ss *statsSeries) %}
|
|
{
|
|
"metric":{
|
|
"__name__":{%q= ss.Name %}
|
|
{% if len(ss.Labels) > 0 %}
|
|
{% for _, label := range ss.Labels %}
|
|
,{%q= label.Name %}:{%q= label.Value %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
},
|
|
"values":[
|
|
{% code points := ss.Points %}
|
|
{% if len(points) > 0 %}
|
|
{%= formatStatsPoint(&points[0]) %}
|
|
{% code points = points[1:] %}
|
|
{% for i := range points %}
|
|
,{%= formatStatsPoint(&points[i]) %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
]
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func formatStatsPoint(p *statsPoint) %}
|
|
[
|
|
{%f= float64(p.Timestamp)/1e9 %},
|
|
{%q= p.Value %}
|
|
]
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|