mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
app/vmselect/netstorage: properly aggregate seriesCountByLabelName and seriesCountByFocusLabelValue obtained from multiple vmselect nodes at /api/v1/status/tsdb
This commit is contained in:
parent
45fa9d798d
commit
ee9954082f
@ -977,34 +977,44 @@ func GetTSDBStatus(qt *querytracer.Tracer, at *auth.Token, denyPartialResponse b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mergeTSDBStatuses(statuses []*storage.TSDBStatus, topN int) *storage.TSDBStatus {
|
func mergeTSDBStatuses(statuses []*storage.TSDBStatus, topN int) *storage.TSDBStatus {
|
||||||
seriesCountByMetricName := make(map[string]uint64)
|
|
||||||
labelValueCountByLabelName := make(map[string]uint64)
|
|
||||||
seriesCountByLabelValuePair := make(map[string]uint64)
|
|
||||||
totalSeries := uint64(0)
|
totalSeries := uint64(0)
|
||||||
totalLabelValuePairs := uint64(0)
|
totalLabelValuePairs := uint64(0)
|
||||||
|
seriesCountByMetricName := make(map[string]uint64)
|
||||||
|
seriesCountByLabelName := make(map[string]uint64)
|
||||||
|
seriesCountByFocusLabelValue := make(map[string]uint64)
|
||||||
|
seriesCountByLabelValuePair := make(map[string]uint64)
|
||||||
|
labelValueCountByLabelName := make(map[string]uint64)
|
||||||
for _, st := range statuses {
|
for _, st := range statuses {
|
||||||
|
totalSeries += st.TotalSeries
|
||||||
|
totalLabelValuePairs += st.TotalLabelValuePairs
|
||||||
for _, e := range st.SeriesCountByMetricName {
|
for _, e := range st.SeriesCountByMetricName {
|
||||||
seriesCountByMetricName[e.Name] += e.Count
|
seriesCountByMetricName[e.Name] += e.Count
|
||||||
}
|
}
|
||||||
for _, e := range st.LabelValueCountByLabelName {
|
for _, e := range st.SeriesCountByLabelName {
|
||||||
// Label values are copied among vmstorage nodes,
|
seriesCountByLabelName[e.Name] += e.Count
|
||||||
// so select the maximum label values count.
|
}
|
||||||
if e.Count > labelValueCountByLabelName[e.Name] {
|
for _, e := range st.SeriesCountByFocusLabelValue {
|
||||||
labelValueCountByLabelName[e.Name] = e.Count
|
seriesCountByFocusLabelValue[e.Name] += e.Count
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, e := range st.SeriesCountByLabelValuePair {
|
for _, e := range st.SeriesCountByLabelValuePair {
|
||||||
seriesCountByLabelValuePair[e.Name] += e.Count
|
seriesCountByLabelValuePair[e.Name] += e.Count
|
||||||
}
|
}
|
||||||
totalSeries += st.TotalSeries
|
for _, e := range st.LabelValueCountByLabelName {
|
||||||
totalLabelValuePairs += st.TotalLabelValuePairs
|
// The same label values may exist in multiple vmstorage nodes.
|
||||||
|
// So select the maximum label values count in order to get the value close to reality.
|
||||||
|
if e.Count > labelValueCountByLabelName[e.Name] {
|
||||||
|
labelValueCountByLabelName[e.Name] = e.Count
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &storage.TSDBStatus{
|
return &storage.TSDBStatus{
|
||||||
SeriesCountByMetricName: toTopHeapEntries(seriesCountByMetricName, topN),
|
TotalSeries: totalSeries,
|
||||||
LabelValueCountByLabelName: toTopHeapEntries(labelValueCountByLabelName, topN),
|
TotalLabelValuePairs: totalLabelValuePairs,
|
||||||
SeriesCountByLabelValuePair: toTopHeapEntries(seriesCountByLabelValuePair, topN),
|
SeriesCountByMetricName: toTopHeapEntries(seriesCountByMetricName, topN),
|
||||||
TotalSeries: totalSeries,
|
SeriesCountByLabelName: toTopHeapEntries(seriesCountByLabelName, topN),
|
||||||
TotalLabelValuePairs: totalLabelValuePairs,
|
SeriesCountByFocusLabelValue: toTopHeapEntries(seriesCountByFocusLabelValue, topN),
|
||||||
|
SeriesCountByLabelValuePair: toTopHeapEntries(seriesCountByLabelValuePair, topN),
|
||||||
|
LabelValueCountByLabelName: toTopHeapEntries(labelValueCountByLabelName, topN),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user