aboutsummaryrefslogtreecommitdiff
path: root/weed/stats
diff options
context:
space:
mode:
authorbingoohuang <bingoo.huang@gmail.com>2021-04-26 17:19:35 +0800
committerbingoohuang <bingoo.huang@gmail.com>2021-04-26 17:19:35 +0800
commitd861cbd81b75b6684c971ac00e33685e6575b833 (patch)
tree301805fef4aa5d0096bfb1510536f7a009b661e7 /weed/stats
parent70da715d8d917527291b35fb069fac077d17b868 (diff)
parent4ee58922eff61a5a4ca29c0b4829b097a498549e (diff)
downloadseaweedfs-d861cbd81b75b6684c971ac00e33685e6575b833.tar.xz
seaweedfs-d861cbd81b75b6684c971ac00e33685e6575b833.zip
Merge branch 'master' of https://github.com/bingoohuang/seaweedfs
Diffstat (limited to 'weed/stats')
-rw-r--r--weed/stats/disk.go8
-rw-r--r--weed/stats/disk_notsupported.go2
-rw-r--r--weed/stats/disk_supported.go2
-rw-r--r--weed/stats/disk_windows.go47
-rw-r--r--weed/stats/metrics.go103
5 files changed, 129 insertions, 33 deletions
diff --git a/weed/stats/disk.go b/weed/stats/disk.go
index e9d8baedd..a8f906213 100644
--- a/weed/stats/disk.go
+++ b/weed/stats/disk.go
@@ -1,9 +1,15 @@
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)
+ if disk.PercentUsed > 95 {
+ glog.V(0).Infof("disk status: %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..3cfa52c0b
--- /dev/null
+++ b/weed/stats/disk_windows.go
@@ -0,0 +1,47 @@
+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..3f5d851a4 100644
--- a/weed/stats/metrics.go
+++ b/weed/stats/metrics.go
@@ -2,17 +2,21 @@ package stats
import (
"fmt"
+ "log"
+ "net/http"
"os"
+ "strings"
"time"
- "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/push"
+
+ "github.com/chrislusf/seaweedfs/weed/glog"
)
var (
- FilerGather = prometheus.NewRegistry()
- VolumeServerGather = prometheus.NewRegistry()
+ Gather = prometheus.NewRegistry()
FilerRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
@@ -73,6 +77,14 @@ var (
Help: "Number of volumes or shards.",
}, []string{"collection", "type"})
+ VolumeServerReadOnlyVolumeGauge = prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Namespace: "SeaweedFS",
+ Subsystem: "volumeServer",
+ Name: "read_only_volumes",
+ Help: "Number of read only volumes.",
+ }, []string{"collection", "type"})
+
VolumeServerMaxVolumeCounter = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "SeaweedFS",
@@ -88,55 +100,84 @@ var (
Name: "total_disk_size",
Help: "Actual disk size used by volumes.",
}, []string{"collection", "type"})
-)
-func init() {
+ VolumeServerResourceGauge = prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Namespace: "SeaweedFS",
+ Subsystem: "volumeServer",
+ Name: "resource",
+ Help: "Resource usage",
+ }, []string{"name", "type"})
- FilerGather.MustRegister(FilerRequestCounter)
- FilerGather.MustRegister(FilerRequestHistogram)
- FilerGather.MustRegister(FilerStoreCounter)
- FilerGather.MustRegister(FilerStoreHistogram)
- FilerGather.MustRegister(prometheus.NewGoCollector())
+ S3RequestCounter = prometheus.NewCounterVec(
+ prometheus.CounterOpts{
+ Namespace: "SeaweedFS",
+ Subsystem: "s3",
+ Name: "request_total",
+ Help: "Counter of s3 requests.",
+ }, []string{"type", "code"})
+ S3RequestHistogram = prometheus.NewHistogramVec(
+ prometheus.HistogramOpts{
+ Namespace: "SeaweedFS",
+ Subsystem: "s3",
+ Name: "request_seconds",
+ Help: "Bucketed histogram of s3 request processing time.",
+ Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
+ }, []string{"type"})
+)
- VolumeServerGather.MustRegister(VolumeServerRequestCounter)
- VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
- VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
- VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter)
- VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge)
+func init() {
+ Gather.MustRegister(FilerRequestCounter)
+ Gather.MustRegister(FilerRequestHistogram)
+ Gather.MustRegister(FilerStoreCounter)
+ Gather.MustRegister(FilerStoreHistogram)
+ Gather.MustRegister(prometheus.NewGoCollector())
+
+ Gather.MustRegister(VolumeServerRequestCounter)
+ Gather.MustRegister(VolumeServerRequestHistogram)
+ Gather.MustRegister(VolumeServerVolumeCounter)
+ Gather.MustRegister(VolumeServerMaxVolumeCounter)
+ Gather.MustRegister(VolumeServerReadOnlyVolumeGauge)
+ Gather.MustRegister(VolumeServerDiskSizeGauge)
+ Gather.MustRegister(VolumeServerResourceGauge)
+
+ Gather.MustRegister(S3RequestCounter)
+ Gather.MustRegister(S3RequestHistogram)
}
-func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnGetMetricsDest func() (addr string, intervalSeconds int)) {
+func LoopPushingMetric(name, instance, addr string, intervalSeconds int) {
- if fnGetMetricsDest == nil {
+ if addr == "" || intervalSeconds == 0 {
return
}
- addr, intervalSeconds := fnGetMetricsDest()
- pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
- currentAddr := addr
+ glog.V(0).Infof("%s server sends metrics to %s every %d seconds", name, addr, intervalSeconds)
+
+ pusher := push.New(addr, name).Gatherer(Gather).Grouping("instance", instance)
for {
- if currentAddr != "" {
- err := pusher.Push()
- if err != nil {
- glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
- }
+ err := pusher.Push()
+ 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)
}
if intervalSeconds <= 0 {
intervalSeconds = 15
}
time.Sleep(time.Duration(intervalSeconds) * time.Second)
- addr, intervalSeconds = fnGetMetricsDest()
- if currentAddr != addr {
- pusher = push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
- currentAddr = addr
- }
}
}
-func SourceName(port int) string {
+func StartMetricsServer(port int) {
+ if port == 0 {
+ return
+ }
+ http.Handle("/metrics", promhttp.HandlerFor(Gather, promhttp.HandlerOpts{}))
+ log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
+}
+
+func SourceName(port uint32) string {
hostname, err := os.Hostname()
if err != nil {
return "unknown"