Add Indexer.Size() and index_size metric
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
type Indexer interface {
|
||||
Index(entry *Entry) error
|
||||
Size() int64
|
||||
Search(q string, p int) (*bleve.SearchResult, error)
|
||||
}
|
||||
|
||||
@@ -40,6 +41,15 @@ func NewIndexer(conf *Config) (Indexer, error) {
|
||||
return &indexer{conf: conf, idx: idx}, nil
|
||||
}
|
||||
|
||||
func (i *indexer) Size() int64 {
|
||||
count, err := i.idx.DocCount()
|
||||
if err != nil {
|
||||
log.WithError(err).Warn("error getting index size")
|
||||
return 0
|
||||
}
|
||||
return int64(count)
|
||||
}
|
||||
|
||||
func (i *indexer) Index(entry *Entry) error {
|
||||
return i.idx.Index(entry.Hash(), entry)
|
||||
}
|
||||
|
||||
371
internal/rice-box.go
Normal file
371
internal/rice-box.go
Normal file
File diff suppressed because one or more lines are too long
@@ -217,6 +217,15 @@ func (s *Server) setupMetrics() {
|
||||
"Duration of crawler tasks",
|
||||
)
|
||||
|
||||
// Index stats
|
||||
metrics.NewGaugeFunc(
|
||||
"index", "size",
|
||||
"Size of index (number of indexed entries)",
|
||||
func() float64 {
|
||||
return float64(s.indexer.Size())
|
||||
},
|
||||
)
|
||||
|
||||
// server info
|
||||
metrics.NewGaugeVec(
|
||||
"server", "info",
|
||||
|
||||
Reference in New Issue
Block a user