Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89165eb
commit d961456
Showing
8 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/colinmarc/hdfs" | ||
) | ||
|
||
func df(humanReadable bool) { | ||
client, err := getClient("") | ||
if err != nil { | ||
fatal(err) | ||
} | ||
|
||
var fs hdfs.FsInfo | ||
|
||
fs, err = client.StatFs() | ||
if err != nil { | ||
fatal(err) | ||
} | ||
|
||
tw := tabwriter.NewWriter(os.Stdout, 3, 8, 0, ' ', tabwriter.AlignRight) | ||
fmt.Fprintf(tw, "Filesystem \tSize \tUsed \tAvailable \t Use%%\n") | ||
if humanReadable { | ||
fmt.Fprintf(tw, "%v \t%v \t%v \t%v \t%d%%\n", | ||
os.Getenv("HADOOP_NAMENODE"), | ||
formatBytes(fs.Capacity), | ||
formatBytes(fs.Used), | ||
formatBytes(fs.Remaining), | ||
100 * fs.Used / fs.Capacity) | ||
} else { | ||
fmt.Fprintf(tw, "%v \t%v \t %v \t %v \t%d%%\n", | ||
os.Getenv("HADOOP_NAMENODE"), | ||
fs.Capacity, | ||
fs.Used, | ||
fs.Remaining, | ||
100 * fs.Used / fs.Capacity) | ||
} | ||
tw.Flush() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helper | ||
|
||
@test "df" { | ||
run $HDFS df | ||
assert_success | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package hdfs | ||
|
||
import ( | ||
"errors" | ||
|
||
hdfs "github.com/colinmarc/hdfs/protocol/hadoop_hdfs" | ||
"github.com/colinmarc/hdfs/rpc" | ||
) | ||
|
||
var StatFsError = errors.New("Failed to get HDFS usage") | ||
|
||
// FsInfo provides information about HDFS | ||
type FsInfo struct { | ||
Capacity uint64 | ||
Used uint64 | ||
Remaining uint64 | ||
UnderReplicated uint64 | ||
CorruptBlocks uint64 | ||
MissingBlocks uint64 | ||
MissingReplOneBlocks uint64 | ||
BlocksInFuture uint64 | ||
PendingDeletionBlocks uint64 | ||
} | ||
|
||
func (c *Client) StatFs() (FsInfo, error) { | ||
req := &hdfs.GetFsStatusRequestProto{} | ||
resp := &hdfs.GetFsStatsResponseProto{} | ||
|
||
err := c.namenode.Execute("getFsStats", req, resp) | ||
if err != nil { | ||
if nnErr, ok := err.(*rpc.NamenodeError); ok { | ||
err = interpretException(nnErr.Exception, err) | ||
} | ||
return FsInfo{}, err | ||
} | ||
|
||
var fs FsInfo | ||
fs.Capacity = resp.GetCapacity() | ||
fs.Used = resp.GetUsed() | ||
fs.Remaining = resp.GetRemaining() | ||
fs.UnderReplicated = resp.GetUnderReplicated() | ||
fs.CorruptBlocks = resp.GetCorruptBlocks() | ||
fs.MissingBlocks = resp.GetMissingBlocks() | ||
fs.MissingReplOneBlocks = resp.GetMissingReplOneBlocks() | ||
fs.BlocksInFuture = resp.GetBlocksInFuture() | ||
fs.PendingDeletionBlocks = resp.GetPendingDeletionBlocks() | ||
|
||
return fs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package hdfs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStatFs(t *testing.T) { | ||
client := getClient(t) | ||
|
||
_, err := client.StatFs() | ||
require.NoError(t, err) | ||
} |