2019-06-16 03:21:44 +08:00
|
|
|
package stats
|
2019-06-13 17:01:51 +08:00
|
|
|
|
2019-06-15 04:06:01 +08:00
|
|
|
import (
|
2019-06-16 12:46:55 +08:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-06-15 04:06:01 +08:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/push"
|
|
|
|
)
|
2019-06-13 17:01:51 +08:00
|
|
|
|
|
|
|
var (
|
2019-06-16 03:21:44 +08:00
|
|
|
FilerGather = prometheus.NewRegistry()
|
|
|
|
VolumeServerGather = prometheus.NewRegistry()
|
2019-06-14 15:54:56 +08:00
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
FilerRequestCounter = prometheus.NewCounterVec(
|
2019-06-13 17:01:51 +08:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filer",
|
|
|
|
Name: "request_total",
|
|
|
|
Help: "Counter of filer requests.",
|
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
FilerRequestHistogram = prometheus.NewHistogramVec(
|
2019-06-13 17:01:51 +08:00
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filer",
|
|
|
|
Name: "request_seconds",
|
|
|
|
Help: "Bucketed histogram of filer request processing time.",
|
2019-06-14 15:54:56 +08:00
|
|
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
|
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
VolumeServerRequestCounter = prometheus.NewCounterVec(
|
2019-06-14 15:54:56 +08:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "request_total",
|
|
|
|
Help: "Counter of filer requests.",
|
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
VolumeServerRequestHistogram = prometheus.NewHistogramVec(
|
2019-06-14 15:54:56 +08:00
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "request_seconds",
|
|
|
|
Help: "Bucketed histogram of filer request processing time.",
|
|
|
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
|
2019-06-13 17:01:51 +08:00
|
|
|
}, []string{"type"})
|
2019-06-15 04:06:01 +08:00
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
VolumeServerVolumeCounter = prometheus.NewGauge(
|
2019-06-15 04:06:01 +08:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "volumes",
|
|
|
|
Help: "Number of volumes.",
|
|
|
|
})
|
2019-06-16 17:24:15 +08:00
|
|
|
|
|
|
|
VolumeServerEcShardCounter = prometheus.NewGauge(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
2019-06-17 12:56:41 +08:00
|
|
|
Name: "ec_shards",
|
2019-06-16 17:24:15 +08:00
|
|
|
Help: "Number of EC shards.",
|
|
|
|
})
|
2019-06-17 12:56:41 +08:00
|
|
|
|
|
|
|
VolumeServerDiskSizeGauge = prometheus.NewGaugeVec(
|
2019-06-16 17:44:20 +08:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
2019-06-17 12:56:41 +08:00
|
|
|
Name: "total_disk_size",
|
2019-06-16 17:44:20 +08:00
|
|
|
Help: "Actual disk size used by volumes.",
|
2019-06-17 12:56:41 +08:00
|
|
|
}, []string{"collection", "type"})
|
2019-06-13 17:01:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-14 15:54:56 +08:00
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
FilerGather.MustRegister(FilerRequestCounter)
|
|
|
|
FilerGather.MustRegister(FilerRequestHistogram)
|
2019-06-14 15:54:56 +08:00
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerRequestCounter)
|
|
|
|
VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
|
|
|
|
VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
|
2019-06-16 17:24:15 +08:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerEcShardCounter)
|
2019-06-17 12:56:41 +08:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge)
|
2019-06-15 04:06:01 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
func StartPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
|
2019-06-15 04:06:01 +08:00
|
|
|
if intervalSeconds == 0 || addr == "" {
|
|
|
|
glog.V(0).Info("disable metrics reporting")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)
|
2019-06-16 03:21:44 +08:00
|
|
|
go loopPushMetrics(name, instance, gatherer, addr, intervalSeconds)
|
2019-06-15 04:06:01 +08:00
|
|
|
}
|
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
func loopPushMetrics(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
|
2019-06-15 04:06:01 +08:00
|
|
|
|
2019-06-16 03:21:44 +08:00
|
|
|
pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
|
2019-06-14 15:54:56 +08:00
|
|
|
|
2019-06-15 04:06:01 +08:00
|
|
|
for {
|
|
|
|
err := pusher.Push()
|
|
|
|
if err != nil {
|
|
|
|
glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
|
|
|
|
}
|
|
|
|
time.Sleep(time.Duration(intervalSeconds) * time.Second)
|
|
|
|
}
|
2019-06-13 17:01:51 +08:00
|
|
|
}
|
2019-06-16 12:46:55 +08:00
|
|
|
|
|
|
|
func SourceName(port int) string {
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s_%d", hostname, port)
|
|
|
|
}
|