mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
volume server: adds basic metrics
This commit is contained in:
parent
a11525fe4e
commit
5f6c9825f8
|
@ -149,6 +149,8 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
|
|
||||||
filerOptions.metricsAddress = serverOptions.metricsAddress
|
filerOptions.metricsAddress = serverOptions.metricsAddress
|
||||||
filerOptions.metricsIntervalSec = serverOptions.metricsIntervalSec
|
filerOptions.metricsIntervalSec = serverOptions.metricsIntervalSec
|
||||||
|
serverOptions.v.metricsAddress = serverOptions.metricsAddress
|
||||||
|
serverOptions.v.metricsIntervalSec = serverOptions.metricsIntervalSec
|
||||||
|
|
||||||
filerAddress := fmt.Sprintf("%s:%d", *serverIp, *filerOptions.port)
|
filerAddress := fmt.Sprintf("%s:%d", *serverIp, *filerOptions.port)
|
||||||
s3Options.filer = &filerAddress
|
s3Options.filer = &filerAddress
|
||||||
|
|
|
@ -45,6 +45,8 @@ type VolumeServerOptions struct {
|
||||||
cpuProfile *string
|
cpuProfile *string
|
||||||
memProfile *string
|
memProfile *string
|
||||||
compactionMBPerSecond *int
|
compactionMBPerSecond *int
|
||||||
|
metricsAddress *string
|
||||||
|
metricsIntervalSec *int
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -66,6 +68,8 @@ func init() {
|
||||||
v.cpuProfile = cmdVolume.Flag.String("cpuprofile", "", "cpu profile output file")
|
v.cpuProfile = cmdVolume.Flag.String("cpuprofile", "", "cpu profile output file")
|
||||||
v.memProfile = cmdVolume.Flag.String("memprofile", "", "memory profile output file")
|
v.memProfile = cmdVolume.Flag.String("memprofile", "", "memory profile output file")
|
||||||
v.compactionMBPerSecond = cmdVolume.Flag.Int("compactionMBps", 0, "limit background compaction or copying speed in mega bytes per second")
|
v.compactionMBPerSecond = cmdVolume.Flag.Int("compactionMBps", 0, "limit background compaction or copying speed in mega bytes per second")
|
||||||
|
v.metricsAddress = cmdVolume.Flag.String("metrics.address", "", "Prometheus gateway address")
|
||||||
|
v.metricsIntervalSec = cmdVolume.Flag.Int("metrics.intervalSeconds", 15, "Prometheus push interval in seconds")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -161,6 +165,8 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
||||||
v.whiteList,
|
v.whiteList,
|
||||||
*v.fixJpgOrientation, *v.readRedirect,
|
*v.fixJpgOrientation, *v.readRedirect,
|
||||||
*v.compactionMBPerSecond,
|
*v.compactionMBPerSecond,
|
||||||
|
*v.metricsAddress,
|
||||||
|
*v.metricsIntervalSec,
|
||||||
)
|
)
|
||||||
|
|
||||||
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
listeningAddress := *v.bindIp + ":" + strconv.Itoa(*v.port)
|
||||||
|
|
|
@ -88,23 +88,23 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption)
|
||||||
readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
|
readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
startPushingMetric(option.MetricsAddress, option.MetricsIntervalSec)
|
startPushingMetric("filer", filerGather, option.MetricsAddress, option.MetricsIntervalSec)
|
||||||
|
|
||||||
return fs, nil
|
return fs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startPushingMetric(addr string, intervalSeconds int) {
|
func startPushingMetric(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
|
||||||
if intervalSeconds == 0 || addr == "" {
|
if intervalSeconds == 0 || addr == "" {
|
||||||
glog.V(0).Info("disable metrics reporting")
|
glog.V(0).Info("disable metrics reporting")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)
|
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 {
|
for {
|
||||||
err := pusher.Push()
|
err := pusher.Push()
|
||||||
|
|
|
@ -3,6 +3,9 @@ package weed_server
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import "github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
filerGather = prometheus.NewRegistry()
|
||||||
|
volumeServerGather = prometheus.NewRegistry()
|
||||||
|
|
||||||
filerRequestCounter = prometheus.NewCounterVec(
|
filerRequestCounter = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: "SeaweedFS",
|
Namespace: "SeaweedFS",
|
||||||
|
@ -17,11 +20,33 @@ var (
|
||||||
Subsystem: "filer",
|
Subsystem: "filer",
|
||||||
Name: "request_seconds",
|
Name: "request_seconds",
|
||||||
Help: "Bucketed histogram of filer request processing time.",
|
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"})
|
}, []string{"type"})
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(filerRequestCounter)
|
|
||||||
prometheus.MustRegister(filerRequestHistogram)
|
filerGather.MustRegister(filerRequestCounter)
|
||||||
|
filerGather.MustRegister(filerRequestHistogram)
|
||||||
|
|
||||||
|
volumeServerGather.MustRegister(volumeServerRequestCounter)
|
||||||
|
volumeServerGather.MustRegister(volumeServerHistogram)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ type VolumeServer struct {
|
||||||
FixJpgOrientation bool
|
FixJpgOrientation bool
|
||||||
ReadRedirect bool
|
ReadRedirect bool
|
||||||
compactionBytePerSecond int64
|
compactionBytePerSecond int64
|
||||||
|
MetricsAddress string
|
||||||
|
MetricsIntervalSec int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
|
@ -36,6 +38,8 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
fixJpgOrientation bool,
|
fixJpgOrientation bool,
|
||||||
readRedirect bool,
|
readRedirect bool,
|
||||||
compactionMBPerSecond int,
|
compactionMBPerSecond int,
|
||||||
|
metricsAddress string,
|
||||||
|
metricsIntervalSec int,
|
||||||
) *VolumeServer {
|
) *VolumeServer {
|
||||||
|
|
||||||
v := viper.GetViper()
|
v := viper.GetViper()
|
||||||
|
@ -80,6 +84,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||||
}
|
}
|
||||||
|
|
||||||
go vs.heartbeat()
|
go vs.heartbeat()
|
||||||
|
startPushingMetric("volumeServer", volumeServerGather, metricsAddress, metricsIntervalSec)
|
||||||
|
|
||||||
return vs
|
return vs
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,11 @@ import (
|
||||||
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
|
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
|
||||||
|
|
||||||
func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request) {
|
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)
|
n := new(needle.Needle)
|
||||||
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)
|
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
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 {
|
if e := r.ParseForm(); e != nil {
|
||||||
glog.V(0).Infoln("form parse error:", e)
|
glog.V(0).Infoln("form parse error:", e)
|
||||||
writeJsonError(w, r, http.StatusBadRequest, 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) {
|
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)
|
n := new(needle.Needle)
|
||||||
vid, fid, _, _, _ := parseURLPath(r.URL.Path)
|
vid, fid, _, _, _ := parseURLPath(r.URL.Path)
|
||||||
volumeId, _ := needle.NewVolumeId(vid)
|
volumeId, _ := needle.NewVolumeId(vid)
|
||||||
|
|
Loading…
Reference in a new issue