configure raft metrics (#3798)

This commit is contained in:
Konstantin Lebedev 2022-10-07 16:20:34 +05:00 committed by GitHub
parent b9933d5589
commit a522507f95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 20 deletions

View file

@ -6,10 +6,13 @@ package weed_server
import ( import (
"fmt" "fmt"
transport "github.com/Jille/raft-grpc-transport" transport "github.com/Jille/raft-grpc-transport"
"github.com/armon/go-metrics"
"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/raft" "github.com/hashicorp/raft"
boltdb "github.com/hashicorp/raft-boltdb/v2" boltdb "github.com/hashicorp/raft-boltdb/v2"
"github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/stats"
"google.golang.org/grpc" "google.golang.org/grpc"
"math/rand" "math/rand"
"os" "os"
@ -182,5 +185,18 @@ func NewHashicorpRaftServer(option *RaftServerOption) (*RaftServer, error) {
}() }()
} }
// Configure a prometheus sink as the raft metrics sink
if sink, err := prometheus.NewPrometheusSinkFrom(prometheus.PrometheusOpts{
Registerer: stats.Gather,
}); err != nil {
return nil, fmt.Errorf("NewPrometheusSink: %v", err)
} else {
metricsConf := metrics.DefaultConfig(stats.Namespace)
metricsConf.EnableRuntimeMetrics = false
if _, err = metrics.NewGlobal(metricsConf, sink); err != nil {
return nil, fmt.Errorf("metrics.NewGlobal: %v", err)
}
}
return s, nil return s, nil
} }

View file

@ -19,6 +19,7 @@ import (
// Readonly volume types // Readonly volume types
const ( const (
Namespace = "SeaweedFS"
IsReadOnly = "IsReadOnly" IsReadOnly = "IsReadOnly"
NoWriteOrDelete = "noWriteOrDelete" NoWriteOrDelete = "noWriteOrDelete"
NoWriteCanDelete = "noWriteCanDelete" NoWriteCanDelete = "noWriteCanDelete"
@ -32,7 +33,7 @@ var (
MasterClientConnectCounter = prometheus.NewCounterVec( MasterClientConnectCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "wdclient", Subsystem: "wdclient",
Name: "connect_updates", Name: "connect_updates",
Help: "Counter of master client leader updates.", Help: "Counter of master client leader updates.",
@ -40,7 +41,7 @@ var (
MasterRaftIsleader = prometheus.NewGauge( MasterRaftIsleader = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "master", Subsystem: "master",
Name: "is_leader", Name: "is_leader",
Help: "is leader", Help: "is leader",
@ -48,7 +49,7 @@ var (
MasterReceivedHeartbeatCounter = prometheus.NewCounterVec( MasterReceivedHeartbeatCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "master", Subsystem: "master",
Name: "received_heartbeats", Name: "received_heartbeats",
Help: "Counter of master received heartbeat.", Help: "Counter of master received heartbeat.",
@ -56,7 +57,7 @@ var (
MasterReplicaPlacementMismatch = prometheus.NewGaugeVec( MasterReplicaPlacementMismatch = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "master", Subsystem: "master",
Name: "replica_placement_mismatch", Name: "replica_placement_mismatch",
Help: "replica placement mismatch", Help: "replica placement mismatch",
@ -64,7 +65,7 @@ var (
MasterLeaderChangeCounter = prometheus.NewCounterVec( MasterLeaderChangeCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "master", Subsystem: "master",
Name: "leader_changes", Name: "leader_changes",
Help: "Counter of master leader changes.", Help: "Counter of master leader changes.",
@ -72,7 +73,7 @@ var (
FilerRequestCounter = prometheus.NewCounterVec( FilerRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "filer", Subsystem: "filer",
Name: "request_total", Name: "request_total",
Help: "Counter of filer requests.", Help: "Counter of filer requests.",
@ -80,7 +81,7 @@ var (
FilerRequestHistogram = prometheus.NewHistogramVec( FilerRequestHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
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.",
@ -89,7 +90,7 @@ var (
FilerServerLastSendTsOfSubscribeGauge = prometheus.NewGaugeVec( FilerServerLastSendTsOfSubscribeGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "filer", Subsystem: "filer",
Name: "last_send_timestamp_of_subscribe", Name: "last_send_timestamp_of_subscribe",
Help: "The last send timestamp of the filer subscription.", Help: "The last send timestamp of the filer subscription.",
@ -97,7 +98,7 @@ var (
FilerStoreCounter = prometheus.NewCounterVec( FilerStoreCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "filerStore", Subsystem: "filerStore",
Name: "request_total", Name: "request_total",
Help: "Counter of filer store requests.", Help: "Counter of filer store requests.",
@ -105,7 +106,7 @@ var (
FilerStoreHistogram = prometheus.NewHistogramVec( FilerStoreHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "filerStore", Subsystem: "filerStore",
Name: "request_seconds", Name: "request_seconds",
Help: "Bucketed histogram of filer store request processing time.", Help: "Bucketed histogram of filer store request processing time.",
@ -114,7 +115,7 @@ var (
FilerSyncOffsetGauge = prometheus.NewGaugeVec( FilerSyncOffsetGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "filerSync", Subsystem: "filerSync",
Name: "sync_offset", Name: "sync_offset",
Help: "The offset of the filer synchronization service.", Help: "The offset of the filer synchronization service.",
@ -122,7 +123,7 @@ var (
VolumeServerRequestCounter = prometheus.NewCounterVec( VolumeServerRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "request_total", Name: "request_total",
Help: "Counter of volume server requests.", Help: "Counter of volume server requests.",
@ -130,7 +131,7 @@ var (
VolumeServerRequestHistogram = prometheus.NewHistogramVec( VolumeServerRequestHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "request_seconds", Name: "request_seconds",
Help: "Bucketed histogram of volume server request processing time.", Help: "Bucketed histogram of volume server request processing time.",
@ -139,7 +140,7 @@ var (
VolumeServerVolumeCounter = prometheus.NewGaugeVec( VolumeServerVolumeCounter = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "volumes", Name: "volumes",
Help: "Number of volumes or shards.", Help: "Number of volumes or shards.",
@ -147,7 +148,7 @@ var (
VolumeServerReadOnlyVolumeGauge = prometheus.NewGaugeVec( VolumeServerReadOnlyVolumeGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "read_only_volumes", Name: "read_only_volumes",
Help: "Number of read only volumes.", Help: "Number of read only volumes.",
@ -155,7 +156,7 @@ var (
VolumeServerMaxVolumeCounter = prometheus.NewGauge( VolumeServerMaxVolumeCounter = prometheus.NewGauge(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "max_volumes", Name: "max_volumes",
Help: "Maximum number of volumes.", Help: "Maximum number of volumes.",
@ -163,7 +164,7 @@ var (
VolumeServerDiskSizeGauge = prometheus.NewGaugeVec( VolumeServerDiskSizeGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "total_disk_size", Name: "total_disk_size",
Help: "Actual disk size used by volumes.", Help: "Actual disk size used by volumes.",
@ -171,7 +172,7 @@ var (
VolumeServerResourceGauge = prometheus.NewGaugeVec( VolumeServerResourceGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "volumeServer", Subsystem: "volumeServer",
Name: "resource", Name: "resource",
Help: "Resource usage", Help: "Resource usage",
@ -179,7 +180,7 @@ var (
S3RequestCounter = prometheus.NewCounterVec( S3RequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "s3", Subsystem: "s3",
Name: "request_total", Name: "request_total",
Help: "Counter of s3 requests.", Help: "Counter of s3 requests.",
@ -187,7 +188,7 @@ var (
S3RequestHistogram = prometheus.NewHistogramVec( S3RequestHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Namespace: "SeaweedFS", Namespace: Namespace,
Subsystem: "s3", Subsystem: "s3",
Name: "request_seconds", Name: "request_seconds",
Help: "Bucketed histogram of s3 request processing time.", Help: "Bucketed histogram of s3 request processing time.",