frostfs-node/pkg/metrics/grpc.go
Anton Nikiforov 1d65a1addb
Some checks failed
Tests and linters / Lint (pull_request) Failing after 4s
Tests and linters / Tests (1.20) (pull_request) Failing after 10s
Tests and linters / Staticcheck (pull_request) Failing after 4s
Vulncheck / Vulncheck (pull_request) Failing after 3s
Build / Build Components (1.19) (pull_request) Failing after 3s
Build / Build Components (1.20) (pull_request) Failing after 3s
Tests and linters / Tests (1.19) (pull_request) Successful in 14m30s
Tests and linters / Tests with -race (pull_request) Successful in 21m47s
[#565] Add metrics for current GRPC endpoint status
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-08-09 15:01:00 +03:00

35 lines
917 B
Go

package metrics
import (
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type GrpcServerMetrics interface {
MarkHealthy(endpoint string)
MarkUnhealthy(endpoint string)
}
type grpcServerMetrics struct {
endpointHealth *prometheus.GaugeVec
}
func newGrpcServerMetrics() *grpcServerMetrics {
return &grpcServerMetrics{
endpointHealth: metrics.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: grpcServerSubsystem,
Name: "health",
Help: "GRPC Server Endpoint health",
}, []string{endpointLabel}),
}
}
func (m *grpcServerMetrics) MarkHealthy(endpoint string) {
m.endpointHealth.With(prometheus.Labels{endpointLabel: endpoint}).Set(float64(1))
}
func (m *grpcServerMetrics) MarkUnhealthy(endpoint string) {
m.endpointHealth.With(prometheus.Labels{endpointLabel: endpoint}).Set(float64(0))
}