Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
66da2ddc
Commit
66da2ddc
authored
May 22, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Du() to DiskUsage() for more expressive
parent
7cbee06a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
8 deletions
+11
-8
metrics_du.go
pkg/volume/metrics_du.go
+5
-5
fs.go
pkg/volume/util/fs/fs.go
+2
-1
fs_unsupported.go
pkg/volume/util/fs/fs_unsupported.go
+2
-1
fs_windows.go
pkg/volume/util/fs/fs_windows.go
+2
-1
No files found.
pkg/volume/metrics_du.go
View file @
66da2ddc
...
...
@@ -25,7 +25,7 @@ import (
var
_
MetricsProvider
=
&
metricsDu
{}
// metricsDu represents a MetricsProvider that calculates the used and
// available Volume space by
executing the "du" command
and gathering
// available Volume space by
calling fs.DiskUsage()
and gathering
// filesystem info for the Volume path.
type
metricsDu
struct
{
// the directory path the volume is mounted to.
...
...
@@ -46,7 +46,7 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
return
metrics
,
NewNoPathDefinedError
()
}
err
:=
md
.
runD
u
(
metrics
)
err
:=
md
.
runD
iskUsage
(
metrics
)
if
err
!=
nil
{
return
metrics
,
err
}
...
...
@@ -64,9 +64,9 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
return
metrics
,
nil
}
// runD
u executes the "du" command
and writes the results to metrics.Used
func
(
md
*
metricsDu
)
runD
u
(
metrics
*
Metrics
)
error
{
used
,
err
:=
fs
.
D
u
(
md
.
path
)
// runD
iskUsage gets disk usage of md.path
and writes the results to metrics.Used
func
(
md
*
metricsDu
)
runD
iskUsage
(
metrics
*
Metrics
)
error
{
used
,
err
:=
fs
.
D
iskUsage
(
md
.
path
)
if
err
!=
nil
{
return
err
}
...
...
pkg/volume/util/fs/fs.go
View file @
66da2ddc
...
...
@@ -54,7 +54,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
return
available
,
capacity
,
usage
,
inodes
,
inodesFree
,
inodesUsed
,
nil
}
func
Du
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
// DiskUsage gets disk usage of specified path.
func
DiskUsage
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
// Uses the same niceness level as cadvisor.fs does when running du
// Uses -B 1 to always scale to a blocksize of 1 byte
out
,
err
:=
exec
.
Command
(
"nice"
,
"-n"
,
"19"
,
"du"
,
"-s"
,
"-B"
,
"1"
,
path
)
.
CombinedOutput
()
...
...
pkg/volume/util/fs/fs_unsupported.go
View file @
66da2ddc
...
...
@@ -29,7 +29,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
return
0
,
0
,
0
,
0
,
0
,
0
,
fmt
.
Errorf
(
"FsInfo not supported for this build."
)
}
func
Du
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
// DiskUsage gets disk usage of specified path.
func
DiskUsage
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"Du not supported for this build."
)
}
...
...
pkg/volume/util/fs/fs_windows.go
View file @
66da2ddc
...
...
@@ -56,7 +56,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
return
freeBytesAvailable
,
totalNumberOfBytes
,
totalNumberOfBytes
-
freeBytesAvailable
,
0
,
0
,
0
,
nil
}
func
Du
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
// DiskUsage gets disk usage of specified path.
func
DiskUsage
(
path
string
)
(
*
resource
.
Quantity
,
error
)
{
_
,
_
,
usage
,
_
,
_
,
_
,
err
:=
FsInfo
(
path
)
if
err
!=
nil
{
return
nil
,
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