mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/metrics: collect metrics on datadir disk usage
This commit is contained in:
parent
751effa35e
commit
b8e21d9ed4
1 changed files with 23 additions and 0 deletions
|
|
@ -17,6 +17,9 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
|
@ -89,11 +92,15 @@ func Setup(ctx *cli.Context) {
|
||||||
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
||||||
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||||
enableAccountingExport = ctx.GlobalBool(MetricsEnableInfluxDBAccountingExportFlag.Name)
|
enableAccountingExport = ctx.GlobalBool(MetricsEnableInfluxDBAccountingExportFlag.Name)
|
||||||
|
datadir = ctx.GlobalString("datadir")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go gethmetrics.CollectProcessMetrics(4 * time.Second)
|
go gethmetrics.CollectProcessMetrics(4 * time.Second)
|
||||||
|
|
||||||
|
// Start collecting disk metrics
|
||||||
|
go datadirDiskUsage(datadir, 4*time.Second)
|
||||||
|
|
||||||
gethmetrics.RegisterRuntimeMemStats(metrics.DefaultRegistry)
|
gethmetrics.RegisterRuntimeMemStats(metrics.DefaultRegistry)
|
||||||
go gethmetrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 4*time.Second)
|
go gethmetrics.CaptureRuntimeMemStats(metrics.DefaultRegistry, 4*time.Second)
|
||||||
|
|
||||||
|
|
@ -110,3 +117,19 @@ func Setup(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func datadirDiskUsage(dir string, d time.Duration) {
|
||||||
|
for range time.Tick(d) {
|
||||||
|
cmd := exec.Command("du", "-s", dir)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("cannot get disk space", "err", err)
|
||||||
|
}
|
||||||
|
res := strings.Split(string(out), "\t")[0]
|
||||||
|
bytes, err := strconv.ParseInt(res, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("cannot parse disk space", "err", err, "out", string(out))
|
||||||
|
}
|
||||||
|
metrics.GetOrRegisterGauge("datadir.usage", nil).Update(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue