1
0
Fork 0

Add basic stats for Snapshot store

master
Philip O'Toole 1 year ago
parent 302d669c8c
commit 225b5346f5

@ -236,6 +236,48 @@ func (s *Store) Dir() string {
return s.rootDir
}
// Stats returns stats about the Snapshot Store.
func (s *Store) Stats() (map[string]interface{}, error) {
ng, err := s.GetNextGeneration()
if err != nil {
return nil, err
}
dirSize, err := dirSize(s.rootDir)
if err != nil {
return nil, err
}
stats := map[string]interface{}{
"root_dir": s.rootDir,
"size": dirSize,
"full_needed": s.FullNeeded(),
"next_generation": ng,
"auto_reap": !s.noAutoreap,
}
snaps, err := s.List()
if err != nil {
return nil, err
}
if len(snaps) > 0 {
var snapsAvailable []string
for i := range snaps {
snapsAvailable = append(snapsAvailable, snaps[i].ID)
}
stats["available"] = snapsAvailable
}
generations, err := s.GetGenerations()
if err != nil {
return nil, err
}
if len(generations) > 0 {
stats["generations"] = generations
}
return stats, nil
}
// FullNeeded returns true if the next type of snapshot needed
// by the Store is a full snapshot.
func (s *Store) FullNeeded() bool {
@ -743,3 +785,23 @@ func (s metaSlice) Contains(id string) bool {
}
return false
}
// dirSize returns the total size of all files in the given directory
func dirSize(path string) (int64, error) {
var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if err != nil {
// If the file doesn't exist, we can ignore it. Snapshot files might
// disappear during walking.
if os.IsNotExist(err) {
return nil
}
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}

@ -886,6 +886,11 @@ func (s *Store) Stats() (map[string]interface{}, error) {
return nil, err
}
snapsStats, err := s.snapshotStore.Stats()
if err != nil {
return nil, err
}
leaderAddr, err := s.LeaderAddr()
if err != nil {
return nil, err
@ -914,6 +919,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
"apply_timeout": s.ApplyTimeout.String(),
"heartbeat_timeout": s.HeartbeatTimeout.String(),
"election_timeout": s.ElectionTimeout.String(),
"snapshot_store": snapsStats,
"snapshot_threshold": s.SnapshotThreshold,
"snapshot_interval": s.SnapshotInterval.String(),
"reap_timeout": s.ReapTimeout.String(),

Loading…
Cancel
Save