Add total Raft directory size to Store stats
@@ -498,6 +498,11 @@ func (s *Store) Stats() (map[string]interface{}, error) {
return nil, err
}
+ dirSz, err := dirSize(s.raftDir)
+ if err != nil {
+ return nil, err
+ }
+
status := map[string]interface{}{
"node_id": s.raftID,
"raft": raftStats,
@@ -516,6 +521,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
"metadata": s.meta,
"nodes": nodes,
"dir": s.raftDir,
+ "dir_size": dirSz,
"sqlite3": dbStatus,
"db_conf": s.dbConf,
}
@@ -1421,3 +1427,18 @@ func pathExists(p string) bool {
}
return true
}
+
+// 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 {
+ return err
+ }
+ if !info.IsDir() {
+ size += info.Size()
+ }
+ return err
+ })
+ return size, err
+}
