mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
This commit adds new fields - `requestsCount` and `lastRequestTimestamp` to series count be metric names stats. It allows to display an additional stats at explore cardinality page. Stats will only be added if `storage.trackMetricNameStats` flag is set. This change requires an update to RPC protocol in order to properly marshal data. In addition, this commit adds integration tests to TSDB stats API. Related issue: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6145
66 lines
2.0 KiB
Plaintext
66 lines
2.0 KiB
Plaintext
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
TSDBStatusResponse generates response for /api/v1/status/tsdb .
|
|
{% func TSDBStatusResponse(status *storage.TSDBStatus, qt *querytracer.Tracer) %}
|
|
{
|
|
"status":"success",
|
|
"data":{
|
|
"totalSeries": {%dul= status.TotalSeries %},
|
|
"totalLabelValuePairs": {%dul= status.TotalLabelValuePairs %},
|
|
"seriesCountByMetricName":{%= tsdbStatusMetricNameEntries(status.SeriesCountByMetricName,status.SeriesQueryStatsByMetricName) %},
|
|
"seriesCountByLabelName":{%= tsdbStatusEntries(status.SeriesCountByLabelName) %},
|
|
"seriesCountByFocusLabelValue":{%= tsdbStatusEntries(status.SeriesCountByFocusLabelValue) %},
|
|
"seriesCountByLabelValuePair":{%= tsdbStatusEntries(status.SeriesCountByLabelValuePair) %},
|
|
"labelValueCountByLabelName":{%= tsdbStatusEntries(status.LabelValueCountByLabelName) %}
|
|
}
|
|
{% code qt.Done() %}
|
|
{%= dumpQueryTrace(qt) %}
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% func tsdbStatusEntries(a []storage.TopHeapEntry) %}
|
|
[
|
|
{% for i, e := range a %}
|
|
{
|
|
"name":{%q= e.Name %},
|
|
"value":{%d= int(e.Count) %}
|
|
}
|
|
{% if i+1 < len(a) %},{% endif %}
|
|
{% endfor %}
|
|
]
|
|
{% endfunc %}
|
|
|
|
{% func tsdbStatusMetricNameEntries(a []storage.TopHeapEntry, queryStats []storage.MetricNamesStatsRecord) %}
|
|
{% code
|
|
queryStatsByMetricName := make(map[string]storage.MetricNamesStatsRecord,len(queryStats))
|
|
for _, record := range queryStats{
|
|
queryStatsByMetricName[record.MetricName] = record
|
|
}
|
|
%}
|
|
[
|
|
{% for i, e := range a %}
|
|
{
|
|
{% code
|
|
entry, ok := queryStatsByMetricName[e.Name]
|
|
%}
|
|
"name":{%q= e.Name %},
|
|
{% if !ok %}
|
|
"value":{%d= int(e.Count) %}
|
|
{% else %}
|
|
"value":{%d= int(e.Count) %},
|
|
"requestsCount":{%d= int(entry.RequestsCount) %},
|
|
"lastRequestTimestamp":{%d= int(entry.LastRequestTs) %}
|
|
{% endif %}
|
|
}
|
|
{% if i+1 < len(a) %},{% endif %}
|
|
{% endfor %}
|
|
]
|
|
{% endfunc %}
|
|
|
|
|
|
{% endstripspace %}
|