[ARVADOS] updated: dcea5126ac48ecb3916bc8c245d59b1ca4439677
git at public.curoverse.com
git at public.curoverse.com
Mon Apr 14 14:15:15 EDT 2014
Summary of changes:
services/keep/keep.go | 86 ++++++++++++++++++++------------------------
services/keep/keep_test.go | 8 +++-
2 files changed, 45 insertions(+), 49 deletions(-)
via dcea5126ac48ecb3916bc8c245d59b1ca4439677 (commit)
from ea6dd70f3178eb38afa4eda7ce49e1bfe8328c40 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit dcea5126ac48ecb3916bc8c245d59b1ca4439677
Author: Tim Pierce <twp at curoverse.com>
Date: Mon Apr 14 14:14:22 2014 -0400
Simplify GetNodeStatus to return only disk usage stats for volumes (refs #2561)
GetNodeStatus now only collects volume mount point, bytes free and bytes used.
More stats will be added as we find them necessary.
diff --git a/services/keep/keep.go b/services/keep/keep.go
index 3856fa5..6906610 100644
--- a/services/keep/keep.go
+++ b/services/keep/keep.go
@@ -210,6 +210,9 @@ func PutBlockHandler(w http.ResponseWriter, req *http.Request) {
}
}
+// IndexHandler
+// A HandleFunc to address /index and /index/{prefix} requests.
+//
func IndexHandler(w http.ResponseWriter, req *http.Request) {
prefix := mux.Vars(req)["prefix"]
@@ -232,46 +235,17 @@ func IndexHandler(w http.ResponseWriter, req *http.Request) {
// * last_error_time
//
type VolumeStatus struct {
- Space string
- LastErr string
- LastErrTime time.Time
+ MountPoint string `json:"mount_point"`
+ BytesFree uint64 `json:"bytes_free"`
+ BytesUsed uint64 `json:"bytes_used"`
}
type NodeStatus struct {
- LastUpdate time.Time
- DfOutput string
- DiskDev []string
- Volumes map[string]VolumeStatus
+ Volumes map[string]*VolumeStatus `json:"volumes"`
}
func StatusHandler(w http.ResponseWriter, req *http.Request) {
- st := new(NodeStatus)
- st.LastUpdate = time.Now()
-
- // Get a list of disk devices on this system.
- st.DiskDev = make([]string, 1)
- if devdir, err := os.Open("/dev"); err != nil {
- log.Printf("StatusHandler: opening /dev: %s\n", err)
- } else {
- devs, err := devdir.Readdirnames(0)
- if err == nil {
- for _, d := range devs {
- if strings.HasPrefix(d, "sd") ||
- strings.HasPrefix(d, "hd") ||
- strings.HasPrefix(d, "xvd") {
- st.DiskDev = append(st.DiskDev, d)
- }
- }
- } else {
- log.Printf("Readdirnames: %s", err)
- }
- }
-
- st.Volumes = make(map[string]VolumeStatus)
- for _, vol := range KeepVolumes {
- st.Volumes[vol] = GetVolumeStatus(vol)
- }
-
+ st := GetNodeStatus()
if jstat, err := json.Marshal(st); err == nil {
w.Write(jstat)
} else {
@@ -281,23 +255,37 @@ func StatusHandler(w http.ResponseWriter, req *http.Request) {
}
}
-// GetVolumeStatus
-// Returns a VolumeStatus describing the requested volume.
-func GetVolumeStatus(volume string) VolumeStatus {
- var isfull, lasterr string
- var lasterrtime time.Time
+// GetNodeStatus
+// Returns a NodeStatus struct describing this Keep
+// node's current status.
+//
+func GetNodeStatus() NodeStatus {
+ st := new(NodeStatus)
- if IsFull(volume) {
- isfull = fmt.Sprintf("full %d", time.Now().Unix())
- } else {
- isfull = fmt.Sprintf("ok %d", time.Now().Unix())
+ st.Volumes = make(map[string]*VolumeStatus)
+ for _, vol := range KeepVolumes {
+ st.Volumes[vol] = GetVolumeStatus(vol)
}
+ return st
+}
- // Not implemented yet
- lasterr = ""
- lasterrtime = time.Unix(0, 0)
+// GetVolumeStatus
+// Returns a VolumeStatus describing the requested volume.
+//
+func GetVolumeStatus(volume string) *VolumeStatus {
+ var fs syscall.Statfs_t
- return VolumeStatus{isfull, lasterr, lasterrtime}
+ err := syscall.Statfs(volume, &fs)
+ if err != nil {
+ log.Printf("GetVolumeStatus: statfs: %s\n", err)
+ return nil
+ }
+ // These calculations match the way df calculates disk usage:
+ // "free" space is measured by fs.Bavail, but "used" space
+ // uses fs.Blocks - fs.Bfree.
+ free := fs.Bavail * uint64(fs.Bsize)
+ used := (fs.Blocks - fs.Bfree) * uint64(fs.Bsize)
+ return &VolumeStatus{volume, free, used}
}
// IndexLocators
@@ -524,6 +512,10 @@ func IsFull(volume string) (isFull bool) {
// Returns the amount of available disk space on VOLUME,
// as a number of 1k blocks.
//
+// TODO(twp): consider integrating this better with
+// VolumeStatus (e.g. keep a NodeStatus object up-to-date
+// periodically and use it as the source of info)
+//
func FreeDiskSpace(volume string) (free uint64, err error) {
var fs syscall.Statfs_t
err = syscall.Statfs(volume, &fs)
diff --git a/services/keep/keep_test.go b/services/keep/keep_test.go
index 7dea47d..508e0cd 100644
--- a/services/keep/keep_test.go
+++ b/services/keep/keep_test.go
@@ -25,11 +25,11 @@ var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.")
// TODO(twp): Tests still to be written
//
-// * PutBlockFull
+// * TestPutBlockFull
// - test that PutBlock returns 503 Full if the filesystem is full.
// (must mock FreeDiskSpace or Statfs? use a tmpfs?)
//
-// * PutBlockWriteErr
+// * TestPutBlockWriteErr
// - test the behavior when Write returns an error.
// - Possible solutions: use a small tmpfs and a high
// MIN_FREE_KILOBYTES to trick PutBlock into attempting
@@ -37,6 +37,10 @@ var BAD_BLOCK = []byte("The magic words are squeamish ossifrage.")
// - use an interface to mock ioutil.TempFile with a File
// object that always returns an error on write
//
+// * TestNodeStatus
+// - test that GetNodeStatus returns a structure with expected
+// values: need to mock FreeDiskSpace or Statfs, or use a tmpfs
+//
// ========================================
// GetBlock tests.
// ========================================
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list