mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Unified Storage: Adds metric to count indexed docs by kind (#96056)
Adds metric to count indexed docs by kind
This commit is contained in:
parent
1fdc48faba
commit
d023cb5931
@ -205,6 +205,9 @@ func (i *Index) InitForTenant(ctx context.Context, namespace string) (int, error
|
||||
return totalObjectsFetched, err
|
||||
}
|
||||
|
||||
// Record the number of objects indexed for the kind
|
||||
IndexServerMetrics.IndexedKinds.WithLabelValues(rt.Key.Resource).Add(float64(len(list.Items)))
|
||||
|
||||
totalObjectsFetched += len(list.Items)
|
||||
|
||||
logger.Debug("indexing batch", "kind", rt.Key.Resource, "count", len(list.Items), "namespace", namespace)
|
||||
@ -277,6 +280,9 @@ func (i *Index) Index(ctx context.Context, data *Data) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//record the kind of resource that was indexed
|
||||
IndexServerMetrics.IndexedKinds.WithLabelValues(res.Kind).Inc()
|
||||
|
||||
// record latency from when event was created to when it was indexed
|
||||
latencySeconds := float64(time.Now().UnixMicro()-data.Value.ResourceVersion) / 1e6
|
||||
if latencySeconds > 5 {
|
||||
|
@ -23,6 +23,7 @@ type IndexMetrics struct {
|
||||
IndexLatency *prometheus.HistogramVec
|
||||
IndexSize prometheus.Gauge
|
||||
IndexedDocs prometheus.Gauge
|
||||
IndexedKinds *prometheus.CounterVec
|
||||
IndexCreationTime *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
@ -52,6 +53,11 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
|
||||
Name: "indexed_docs",
|
||||
Help: "Number of indexed documents by resource",
|
||||
}),
|
||||
IndexedKinds: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: "index_server",
|
||||
Name: "indexed_kinds",
|
||||
Help: "Number of indexed documents by kind",
|
||||
}, []string{"kind"}),
|
||||
IndexCreationTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "index_server",
|
||||
Name: "index_creation_time_seconds",
|
||||
@ -70,6 +76,7 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
|
||||
func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
|
||||
s.IndexLatency.Collect(ch)
|
||||
s.IndexCreationTime.Collect(ch)
|
||||
s.IndexedKinds.Collect(ch)
|
||||
|
||||
// collect index size
|
||||
totalSize, err := getTotalIndexSize(s.IndexDir)
|
||||
@ -85,22 +92,16 @@ func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
func (s *IndexMetrics) Describe(ch chan<- *prometheus.Desc) {
|
||||
s.IndexLatency.Describe(ch)
|
||||
s.IndexSize.Describe(ch)
|
||||
s.IndexedDocs.Describe(ch)
|
||||
s.IndexedKinds.Describe(ch)
|
||||
s.IndexCreationTime.Describe(ch)
|
||||
}
|
||||
|
||||
// getTotalDocCount returns the total number of documents in the index
|
||||
func getTotalDocCount(index *Index) float64 {
|
||||
var totalCount float64
|
||||
totalCount = 0
|
||||
if index == nil {
|
||||
return totalCount
|
||||
}
|
||||
|
||||
for _, shard := range index.shards {
|
||||
count, _ := shard.index.DocCount()
|
||||
totalCount += float64(count)
|
||||
}
|
||||
|
||||
return totalCount
|
||||
count, _ := index.Count()
|
||||
return float64(count)
|
||||
}
|
||||
|
||||
// getTotalIndexSize returns the total size of the index directory when using a file-based index
|
||||
|
Loading…
Reference in New Issue
Block a user