diff options
Diffstat (limited to 'weed/stats')
| -rw-r--r-- | weed/stats/disk.go | 6 | ||||
| -rw-r--r-- | weed/stats/disk_notsupported.go | 2 | ||||
| -rw-r--r-- | weed/stats/disk_supported.go | 2 | ||||
| -rw-r--r-- | weed/stats/disk_windows.go | 46 | ||||
| -rw-r--r-- | weed/stats/metrics.go | 8 |
5 files changed, 59 insertions, 5 deletions
diff --git a/weed/stats/disk.go b/weed/stats/disk.go index e9d8baedd..813c08f7b 100644 --- a/weed/stats/disk.go +++ b/weed/stats/disk.go @@ -1,9 +1,13 @@ package stats -import "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" +import ( + "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" +) func NewDiskStatus(path string) (disk *volume_server_pb.DiskStatus) { disk = &volume_server_pb.DiskStatus{Dir: path} fillInDiskStatus(disk) + glog.V(0).Infof("read disk size: %v", disk) return } diff --git a/weed/stats/disk_notsupported.go b/weed/stats/disk_notsupported.go index ace662f6a..3d99e6ce7 100644 --- a/weed/stats/disk_notsupported.go +++ b/weed/stats/disk_notsupported.go @@ -1,4 +1,4 @@ -// +build windows openbsd netbsd plan9 solaris +// +build openbsd netbsd plan9 solaris package stats diff --git a/weed/stats/disk_supported.go b/weed/stats/disk_supported.go index 0537828b0..dff580b5b 100644 --- a/weed/stats/disk_supported.go +++ b/weed/stats/disk_supported.go @@ -17,5 +17,7 @@ func fillInDiskStatus(disk *volume_server_pb.DiskStatus) { disk.All = fs.Blocks * uint64(fs.Bsize) disk.Free = fs.Bfree * uint64(fs.Bsize) disk.Used = disk.All - disk.Free + disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100) + disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100) return } diff --git a/weed/stats/disk_windows.go b/weed/stats/disk_windows.go new file mode 100644 index 000000000..1185e129c --- /dev/null +++ b/weed/stats/disk_windows.go @@ -0,0 +1,46 @@ +package stats + +import ( + "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" + "golang.org/x/sys/windows" + "syscall" + "unsafe" +) +var ( + kernel32 = windows.NewLazySystemDLL("Kernel32.dll") + getDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW") +) + +func fillInDiskStatus(disk *volume_server_pb.DiskStatus) { + + ptr, err := syscall.UTF16PtrFromString(disk.Dir) + + if err != nil { + return + } + var _temp uint64 + /* #nosec */ + r, _, e := syscall.Syscall6( + getDiskFreeSpaceEx.Addr(), + 4, + uintptr(unsafe.Pointer(ptr)), + uintptr(unsafe.Pointer(&disk.Free)), + uintptr(unsafe.Pointer(&disk.All)), + uintptr(unsafe.Pointer(&_temp)), + 0, + 0, + ) + + if r == 0 { + if e != 0 { + return + } + + return + } + disk.Used = disk.All - disk.Free + disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100) + disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100) + + return +} diff --git a/weed/stats/metrics.go b/weed/stats/metrics.go index a9624cd86..7ff09a388 100644 --- a/weed/stats/metrics.go +++ b/weed/stats/metrics.go @@ -3,11 +3,13 @@ package stats import ( "fmt" "os" + "strings" "time" - "github.com/chrislusf/seaweedfs/weed/glog" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/push" + + "github.com/chrislusf/seaweedfs/weed/glog" ) var ( @@ -119,7 +121,7 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnG for { if currentAddr != "" { err := pusher.Push() - if err != nil { + if err != nil && !strings.HasPrefix(err.Error(), "unexpected status code 200") { glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err) } } @@ -136,7 +138,7 @@ func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnG } } -func SourceName(port int) string { +func SourceName(port uint32) string { hostname, err := os.Hostname() if err != nil { return "unknown" |
