volume server: adds basic metrics

This commit is contained in:
Chris Lu
2019-06-14 00:54:56 -07:00
parent a11525fe4e
commit 5f6c9825f8
7 changed files with 61 additions and 8 deletions

View File

@@ -88,23 +88,23 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
}
startPushingMetric(option.MetricsAddress, option.MetricsIntervalSec)
startPushingMetric("filer", filerGather, option.MetricsAddress, option.MetricsIntervalSec)
return fs, nil
}
func startPushingMetric(addr string, intervalSeconds int) {
func startPushingMetric(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
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)
go loopPushMetrics(addr, intervalSeconds)
go loopPushMetrics(name, gatherer, addr, intervalSeconds)
}
func loopPushMetrics(addr string, intervalSeconds int) {
func loopPushMetrics(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
pusher := push.New(addr, "filer").Gatherer(prometheus.DefaultGatherer)
pusher := push.New(addr, name).Gatherer(gatherer)
for {
err := pusher.Push()

View File

@@ -3,6 +3,9 @@ package weed_server
import "github.com/prometheus/client_golang/prometheus"
var (
filerGather = prometheus.NewRegistry()
volumeServerGather = prometheus.NewRegistry()
filerRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "SeaweedFS",
@@ -17,11 +20,33 @@ var (
Subsystem: "filer",
Name: "request_seconds",
Help: "Bucketed histogram of filer request processing time.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 18),
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
}, []string{"type"})
volumeServerRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "SeaweedFS",
Subsystem: "volumeServer",
Name: "request_total",
Help: "Counter of filer requests.",
}, []string{"type"})
volumeServerHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "SeaweedFS",
Subsystem: "volumeServer",
Name: "request_seconds",
Help: "Bucketed histogram of filer request processing time.",
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
}, []string{"type"})
)
func init() {
prometheus.MustRegister(filerRequestCounter)
prometheus.MustRegister(filerRequestHistogram)
filerGather.MustRegister(filerRequestCounter)
filerGather.MustRegister(filerRequestHistogram)
volumeServerGather.MustRegister(volumeServerRequestCounter)
volumeServerGather.MustRegister(volumeServerHistogram)
}

View File

@@ -24,6 +24,8 @@ type VolumeServer struct {
FixJpgOrientation bool
ReadRedirect bool
compactionBytePerSecond int64
MetricsAddress string
MetricsIntervalSec int
}
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
@@ -36,6 +38,8 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
fixJpgOrientation bool,
readRedirect bool,
compactionMBPerSecond int,
metricsAddress string,
metricsIntervalSec int,
) *VolumeServer {
v := viper.GetViper()
@@ -80,6 +84,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
}
go vs.heartbeat()
startPushingMetric("volumeServer", volumeServerGather, metricsAddress, metricsIntervalSec)
return vs
}

View File

@@ -26,6 +26,11 @@ import (
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) {
volumeServerRequestCounter.WithLabelValues("get").Inc()
start := time.Now()
defer func() { volumeServerHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds()) }()
n := new(needle.Needle)
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)

View File

@@ -15,6 +15,11 @@ import (
)
func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {
volumeServerRequestCounter.WithLabelValues("post").Inc()
start := time.Now()
defer func() { volumeServerHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds()) }()
if e := r.ParseForm(); e != nil {
glog.V(0).Infoln("form parse error:", e)
writeJsonError(w, r, http.StatusBadRequest, e)
@@ -60,6 +65,11 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {
}
func (vs *VolumeServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
volumeServerRequestCounter.WithLabelValues("delete").Inc()
start := time.Now()
defer func() { volumeServerHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds()) }()
n := new(needle.Needle)
vid, fid, _, _, _ := parseURLPath(r.URL.Path)
volumeId, _ := needle.NewVolumeId(vid)