2019-06-15 19:21:44 +00:00
|
|
|
package stats
|
2019-06-13 09:01:51 +00:00
|
|
|
|
2019-06-14 20:06:01 +00:00
|
|
|
import (
|
2019-06-16 04:46:55 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-05-15 04:08:34 +00:00
|
|
|
"strings"
|
2019-06-14 20:06:01 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/push"
|
2020-05-15 04:08:34 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2019-06-14 20:06:01 +00:00
|
|
|
)
|
2019-06-13 09:01:51 +00:00
|
|
|
|
|
|
|
var (
|
2019-06-15 19:21:44 +00:00
|
|
|
FilerGather = prometheus.NewRegistry()
|
|
|
|
VolumeServerGather = prometheus.NewRegistry()
|
2020-09-17 13:56:15 +00:00
|
|
|
S3Gather = prometheus.NewRegistry()
|
2019-06-14 07:54:56 +00:00
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
FilerRequestCounter = prometheus.NewCounterVec(
|
2019-06-13 09:01:51 +00:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filer",
|
|
|
|
Name: "request_total",
|
|
|
|
Help: "Counter of filer requests.",
|
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
FilerRequestHistogram = prometheus.NewHistogramVec(
|
2019-06-13 09:01:51 +00:00
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filer",
|
|
|
|
Name: "request_seconds",
|
|
|
|
Help: "Bucketed histogram of filer request processing time.",
|
2019-06-14 07:54:56 +00:00
|
|
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
|
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-22 19:23:25 +00:00
|
|
|
FilerStoreCounter = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filerStore",
|
|
|
|
Name: "request_total",
|
|
|
|
Help: "Counter of filer store requests.",
|
|
|
|
}, []string{"store", "type"})
|
|
|
|
|
|
|
|
FilerStoreHistogram = prometheus.NewHistogramVec(
|
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "filerStore",
|
|
|
|
Name: "request_seconds",
|
|
|
|
Help: "Bucketed histogram of filer store request processing time.",
|
|
|
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
|
|
|
|
}, []string{"store", "type"})
|
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
VolumeServerRequestCounter = prometheus.NewCounterVec(
|
2019-06-14 07:54:56 +00:00
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "request_total",
|
2019-06-24 07:26:03 +00:00
|
|
|
Help: "Counter of volume server requests.",
|
2019-06-14 07:54:56 +00:00
|
|
|
}, []string{"type"})
|
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
VolumeServerRequestHistogram = prometheus.NewHistogramVec(
|
2019-06-14 07:54:56 +00:00
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "request_seconds",
|
2019-06-24 07:26:03 +00:00
|
|
|
Help: "Bucketed histogram of volume server request processing time.",
|
2019-06-14 07:54:56 +00:00
|
|
|
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
|
2019-06-13 09:01:51 +00:00
|
|
|
}, []string{"type"})
|
2019-06-14 20:06:01 +00:00
|
|
|
|
2019-06-18 04:02:50 +00:00
|
|
|
VolumeServerVolumeCounter = prometheus.NewGaugeVec(
|
2019-06-14 20:06:01 +00:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
|
|
|
Name: "volumes",
|
2019-06-18 04:02:50 +00:00
|
|
|
Help: "Number of volumes or shards.",
|
|
|
|
}, []string{"collection", "type"})
|
2019-06-16 09:24:15 +00:00
|
|
|
|
2019-06-18 04:02:50 +00:00
|
|
|
VolumeServerMaxVolumeCounter = prometheus.NewGauge(
|
2019-06-16 09:24:15 +00:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
2019-06-20 16:56:49 +00:00
|
|
|
Name: "max_volumes",
|
2019-06-18 04:02:50 +00:00
|
|
|
Help: "Maximum number of volumes.",
|
2019-06-16 09:24:15 +00:00
|
|
|
})
|
2019-06-17 04:56:41 +00:00
|
|
|
|
|
|
|
VolumeServerDiskSizeGauge = prometheus.NewGaugeVec(
|
2019-06-16 09:44:20 +00:00
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "volumeServer",
|
2019-06-17 04:56:41 +00:00
|
|
|
Name: "total_disk_size",
|
2019-06-16 09:44:20 +00:00
|
|
|
Help: "Actual disk size used by volumes.",
|
2019-06-17 04:56:41 +00:00
|
|
|
}, []string{"collection", "type"})
|
2020-09-18 07:09:04 +00:00
|
|
|
|
|
|
|
S3RequestCounter = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: "SeaweedFS",
|
|
|
|
Subsystem: "s3",
|
|
|
|
Name: "request_total",
|
|
|
|
Help: "Counter of s3 requests.",
|
|
|
|
}, []string{"type"})
|
|
|
|
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"})
|
2019-06-13 09:01:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-14 07:54:56 +00:00
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
FilerGather.MustRegister(FilerRequestCounter)
|
|
|
|
FilerGather.MustRegister(FilerRequestHistogram)
|
2019-06-22 19:23:25 +00:00
|
|
|
FilerGather.MustRegister(FilerStoreCounter)
|
|
|
|
FilerGather.MustRegister(FilerStoreHistogram)
|
2019-06-29 10:02:28 +00:00
|
|
|
FilerGather.MustRegister(prometheus.NewGoCollector())
|
2019-06-14 07:54:56 +00:00
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerRequestCounter)
|
|
|
|
VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
|
|
|
|
VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
|
2019-06-18 04:02:50 +00:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter)
|
2019-06-17 04:56:41 +00:00
|
|
|
VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge)
|
2019-06-14 20:06:01 +00:00
|
|
|
|
2020-09-18 07:09:04 +00:00
|
|
|
S3Gather.MustRegister(S3RequestCounter)
|
|
|
|
S3Gather.MustRegister(S3RequestHistogram)
|
2019-06-14 20:06:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 08:39:30 +00:00
|
|
|
func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
|
2019-06-14 20:06:01 +00:00
|
|
|
|
2020-09-16 08:39:30 +00:00
|
|
|
if addr == "" || intervalSeconds == 0 {
|
2019-06-23 22:29:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-20 22:38:59 +00:00
|
|
|
glog.V(0).Infof("%s server sends metrics to %s every %d seconds", name, addr, intervalSeconds)
|
|
|
|
|
2019-06-15 19:21:44 +00:00
|
|
|
pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
|
2019-06-14 07:54:56 +00:00
|
|
|
|
2019-06-14 20:06:01 +00:00
|
|
|
for {
|
2020-09-16 08:39:30 +00:00
|
|
|
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)
|
2019-06-17 21:51:47 +00:00
|
|
|
}
|
|
|
|
if intervalSeconds <= 0 {
|
|
|
|
intervalSeconds = 15
|
2019-06-14 20:06:01 +00:00
|
|
|
}
|
|
|
|
time.Sleep(time.Duration(intervalSeconds) * time.Second)
|
2019-06-17 21:51:47 +00:00
|
|
|
|
2019-06-14 20:06:01 +00:00
|
|
|
}
|
2019-06-13 09:01:51 +00:00
|
|
|
}
|
2019-06-16 04:46:55 +00:00
|
|
|
|
2020-03-02 06:13:47 +00:00
|
|
|
func SourceName(port uint32) string {
|
2019-06-16 04:46:55 +00:00
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
return "unknown"
|
|
|
|
}
|
2019-06-17 04:57:32 +00:00
|
|
|
return fmt.Sprintf("%s:%d", hostname, port)
|
2019-06-16 04:46:55 +00:00
|
|
|
}
|