Merge pull request #738 from abhinavdangeti/scorch-stats
Add support for certain disk stats
This commit is contained in:
commit
c24f8944c4
|
@ -76,11 +76,11 @@ func NewScorch(storeName string,
|
|||
version: Version,
|
||||
config: config,
|
||||
analysisQueue: analysisQueue,
|
||||
stats: &Stats{},
|
||||
nextSnapshotEpoch: 1,
|
||||
closeCh: make(chan struct{}),
|
||||
ineligibleForRemoval: map[string]bool{},
|
||||
}
|
||||
rv.stats = &Stats{i: rv}
|
||||
rv.root = &IndexSnapshot{parent: rv, refs: 1}
|
||||
ro, ok := config["read_only"].(bool)
|
||||
if ok {
|
||||
|
@ -363,7 +363,8 @@ func (s *Scorch) Stats() json.Marshaler {
|
|||
return s.stats
|
||||
}
|
||||
func (s *Scorch) StatsMap() map[string]interface{} {
|
||||
return s.stats.statsMap()
|
||||
m, _ := s.stats.statsMap()
|
||||
return m
|
||||
}
|
||||
|
||||
func (s *Scorch) Analyze(d *document.Document) *index.AnalysisResult {
|
||||
|
|
|
@ -16,6 +16,7 @@ package scorch
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
|
@ -28,9 +29,10 @@ type Stats struct {
|
|||
numPlainTextBytesIndexed uint64
|
||||
numItemsIntroduced uint64
|
||||
numItemsPersisted uint64
|
||||
i *Scorch
|
||||
}
|
||||
|
||||
func (s *Stats) statsMap() map[string]interface{} {
|
||||
func (s *Stats) statsMap() (map[string]interface{}, error) {
|
||||
m := map[string]interface{}{}
|
||||
m["updates"] = atomic.LoadUint64(&s.updates)
|
||||
m["deletes"] = atomic.LoadUint64(&s.deletes)
|
||||
|
@ -44,11 +46,33 @@ func (s *Stats) statsMap() map[string]interface{} {
|
|||
m["num_items_introduced"] = atomic.LoadUint64(&s.numItemsIntroduced)
|
||||
m["num_items_persisted"] = atomic.LoadUint64(&s.numItemsPersisted)
|
||||
|
||||
return m
|
||||
if s.i.path != "" {
|
||||
finfos, err := ioutil.ReadDir(s.i.path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var numFilesOnDisk, numBytesUsedDisk uint64
|
||||
|
||||
for _, finfo := range finfos {
|
||||
if !finfo.IsDir() {
|
||||
numBytesUsedDisk += uint64(finfo.Size())
|
||||
numFilesOnDisk++
|
||||
}
|
||||
}
|
||||
|
||||
m["num_bytes_used_disk"] = numBytesUsedDisk
|
||||
m["num_files_on_disk"] = numFilesOnDisk
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler
|
||||
func (s *Stats) MarshalJSON() ([]byte, error) {
|
||||
m := s.statsMap()
|
||||
m, err := s.statsMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue