Permalink
Browse files

Send up free space from nodes.

I can't figure out how to get free space on Windows, but the user can
override in any case.

Closes #22
  • Loading branch information...
dustin committed Sep 21, 2012
1 parent 5d12f1f commit 8bca46f51af1b8820e103359b2f25a6600e6568d
Showing with 40 additions and 0 deletions.
  1. +13 −0 freespace_unix.go
  2. +11 −0 freespace_windows.go
  3. +15 −0 heartbeat.go
  4. +1 −0 nodes.go
View
@@ -0,0 +1,13 @@
+// +build !windows
+
+package main
+
+import (
+ "syscall"
+)
+
+func filesystemFree() (uint64, error) {
+ fs := syscall.Statfs_t{}
+ err := syscall.Statfs(*root, &fs)
+ return fs.Bfree * uint64(fs.Bsize), err
+}
View
@@ -0,0 +1,11 @@
+// +build windows !darwin !freebsd !linux !openbsd !netbsd
+
+package main
+
+import (
+ "math"
+)
+
+func filesystemFree() (uint64, error) {
+ return uint64(math.MaxFloat64), noFSFree
+}
View
@@ -3,6 +3,7 @@ package main
import (
"encoding/hex"
"encoding/json"
+ "errors"
"flag"
"fmt"
"io"
@@ -30,6 +31,10 @@ var maxStartupObjects = flag.Int("maxStartObjs", 1000,
"Maximum number of objects to pull on start")
var maxStartupRepls = flag.Int("maxStartRepls", 3,
"Blob replication limit for startup objects.")
+var maxStorage = flag.Uint64("maxSize", 0,
+ "Approximate maximum amount of space to allocate")
+
+var noFSFree = errors.New("no filesystemFree")
type PeriodicJob struct {
period func() time.Duration
@@ -100,11 +105,21 @@ func heartbeat() {
c.Close()
}
+ freeSpace, err := filesystemFree()
+ if err != nil && err != noFSFree {
+ log.Printf("Error getting filesystem info: %v", err)
+ }
+
+ if *maxStorage > 0 && freeSpace > *maxStorage {
+ freeSpace = *maxStorage
+ }
+
aboutMe := StorageNode{
Addr: localAddr,
Type: "node",
Time: time.Now().UTC(),
BindAddr: *bindAddr,
+ Free: freeSpace,
}
err = couchbase.Set("/"+serverId, aboutMe)
View
@@ -21,6 +21,7 @@ type StorageNode struct {
Time time.Time `json:"time"`
BindAddr string `json:"bindaddr"`
Hash string `json:"hash"`
+ Free uint64 `json:"free"`
name string
storageSize int64

0 comments on commit 8bca46f

Please sign in to comment.