Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
9b0d1b9a
Unverified
Commit
9b0d1b9a
authored
May 15, 2019
by
Anton Evangelatov
Committed by
GitHub
May 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm/metrics: collect metrics on datadir disk usage (#19576)
parent
350a87dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
flags.go
swarm/metrics/flags.go
+31
-0
No files found.
swarm/metrics/flags.go
View file @
9b0d1b9a
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment