mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
This feature allows to track query requests by metric names. Tracker
state is stored in-memory, capped by 1/100 of allocated memory to the
storage. If cap exceeds, tracker rejects any new items add and instead
registers query requests for already observed metric names.
This feature is disable by default and new flag:
`-storage.trackMetricNamesStats` enables it.
New API added to the select component:
* /api/v1/status/metric_names_stats - which returns a JSON
object
with usage statistics.
* /admin/api/v1/status/metric_names_stats/reset - which resets internal
state of the tracker and reset tsid/cache.
New metrics were added for this feature:
* vm_cache_size_bytes{type="storage/metricNamesUsageTracker"}
* vm_cache_size{type="storage/metricNamesUsageTracker"}
* vm_cache_size_max_bytes{type="storage/metricNamesUsageTracker"}
Related issue:
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4458
---------
Signed-off-by: f41gh7 <[email protected]>
Co-authored-by: Roman Khavronenko <[email protected]>
34 lines
1.1 KiB
Plaintext
34 lines
1.1 KiB
Plaintext
{% import (
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
|
) %}
|
|
|
|
{% stripspace %}
|
|
MetricNamesStatsResponse generates response for /api/v1/status/metric_names_stats .
|
|
{% func MetricNamesStatsResponse(stats *storage.MetricNamesStatsResponse, qt *querytracer.Tracer) %}
|
|
{
|
|
"status":"success",
|
|
"statsCollectedSince": {%dul= stats.CollectedSinceTs %},
|
|
"statsCollectedRecordsTotal": {%dul= stats.TotalRecords %},
|
|
"trackerMemoryMaxSizeBytes": {%dul= stats.MaxSizeBytes %},
|
|
"trackerCurrentMemoryUsageBytes": {%dul= stats.CurrentSizeBytes %},
|
|
"records":
|
|
[
|
|
{% for i, r := range stats.Records %}
|
|
{
|
|
"metricName":{%q= r.MetricName %},
|
|
"queryRequestsCount":{%dul= r.RequestsCount %},
|
|
"lastQueryRequestTimestamp":{%dul= r.LastRequestTs %}
|
|
}
|
|
{% if i+1 < len(stats.Records) %},{% endif %}
|
|
{% endfor %}
|
|
]
|
|
{% code qt.Done() %}
|
|
{% code traceJSON := qt.ToJSON() %}
|
|
{% if traceJSON != "" %},"trace":{%s= traceJSON %}{% endif %}
|
|
|
|
}
|
|
{% endfunc %}
|
|
|
|
{% endstripspace %}
|