good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 9b0d1b9a authored by Anton Evangelatov's avatar Anton Evangelatov Committed by GitHub
Browse files

swarm/metrics: collect metrics on datadir disk usage (#19576)

parent 350a87dd
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@
package metrics
import (
"os"
"path/filepath"
"time"
"github.com/ethereum/go-ethereum/cmd/utils"
......@@ -89,11 +91,15 @@ func Setup(ctx *cli.Context) {
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
enableAccountingExport = ctx.GlobalBool(MetricsEnableInfluxDBAccountingExportFlag.Name)
datadir = ctx.GlobalString("datadir")
)
// Start system runtime metrics collection
go gethmetrics.CollectProcessMetrics(4 * time.Second)
// Start collecting disk metrics
go datadirDiskUsage(datadir, 4*time.Second)
gethmetrics.RegisterRuntimeMemStats(metrics.DefaultRegistry)
go gethmetrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 4*time.Second)
......@@ -110,3 +116,28 @@ func Setup(ctx *cli.Context) {
}
}
}
func datadirDiskUsage(path string, d time.Duration) {
for range time.Tick(d) {
bytes, err := dirSize(path)
if err != nil {
log.Warn("cannot get disk space", "err", err)
}
metrics.GetOrRegisterGauge("datadir.usage", nil).Update(bytes)
}
}
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment