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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user