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
|
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)
|
totalObjectsFetched += len(list.Items)
|
||||||
|
|
||||||
logger.Debug("indexing batch", "kind", rt.Key.Resource, "count", len(list.Items), "namespace", namespace)
|
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
|
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
|
// record latency from when event was created to when it was indexed
|
||||||
latencySeconds := float64(time.Now().UnixMicro()-data.Value.ResourceVersion) / 1e6
|
latencySeconds := float64(time.Now().UnixMicro()-data.Value.ResourceVersion) / 1e6
|
||||||
if latencySeconds > 5 {
|
if latencySeconds > 5 {
|
||||||
|
@ -23,6 +23,7 @@ type IndexMetrics struct {
|
|||||||
IndexLatency *prometheus.HistogramVec
|
IndexLatency *prometheus.HistogramVec
|
||||||
IndexSize prometheus.Gauge
|
IndexSize prometheus.Gauge
|
||||||
IndexedDocs prometheus.Gauge
|
IndexedDocs prometheus.Gauge
|
||||||
|
IndexedKinds *prometheus.CounterVec
|
||||||
IndexCreationTime *prometheus.HistogramVec
|
IndexCreationTime *prometheus.HistogramVec
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +53,11 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
|
|||||||
Name: "indexed_docs",
|
Name: "indexed_docs",
|
||||||
Help: "Number of indexed documents by resource",
|
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{
|
IndexCreationTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Namespace: "index_server",
|
Namespace: "index_server",
|
||||||
Name: "index_creation_time_seconds",
|
Name: "index_creation_time_seconds",
|
||||||
@ -70,6 +76,7 @@ func NewIndexMetrics(indexDir string, indexServer *IndexServer) *IndexMetrics {
|
|||||||
func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
|
func (s *IndexMetrics) Collect(ch chan<- prometheus.Metric) {
|
||||||
s.IndexLatency.Collect(ch)
|
s.IndexLatency.Collect(ch)
|
||||||
s.IndexCreationTime.Collect(ch)
|
s.IndexCreationTime.Collect(ch)
|
||||||
|
s.IndexedKinds.Collect(ch)
|
||||||
|
|
||||||
// collect index size
|
// collect index size
|
||||||
totalSize, err := getTotalIndexSize(s.IndexDir)
|
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) {
|
func (s *IndexMetrics) Describe(ch chan<- *prometheus.Desc) {
|
||||||
s.IndexLatency.Describe(ch)
|
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
|
// getTotalDocCount returns the total number of documents in the index
|
||||||
func getTotalDocCount(index *Index) float64 {
|
func getTotalDocCount(index *Index) float64 {
|
||||||
var totalCount float64
|
count, _ := index.Count()
|
||||||
totalCount = 0
|
return float64(count)
|
||||||
if index == nil {
|
|
||||||
return totalCount
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, shard := range index.shards {
|
|
||||||
count, _ := shard.index.DocCount()
|
|
||||||
totalCount += float64(count)
|
|
||||||
}
|
|
||||||
|
|
||||||
return totalCount
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTotalIndexSize returns the total size of the index directory when using a file-based index
|
// getTotalIndexSize returns the total size of the index directory when using a file-based index
|
||||||
|
Loading…
Reference in New Issue
Block a user