metrics

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultGRPCServerMetrics create default gRPC server metrics
	DefaultGRPCServerMetrics = openmetrics.NewServerMetrics(openmetrics.WithServerHandlingTimeHistogram())
	// DefaultGRPCClientMetrics create default gRPC client metrics
	DefaultGRPCClientMetrics = openmetrics.NewClientMetrics(openmetrics.WithClientHandlingTimeHistogram(),
		openmetrics.WithClientStreamSendHistogram(), openmetrics.WithClientStreamRecvHistogram())
	// DefaultHTTPServerMetrics create default HTTP server metrics
	DefaultHTTPServerMetrics = metricshttp.NewServerMetrics()
	// PanicsTotal record the number of rpc panics
	PanicsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name: "grpc_req_panics_recovered_total",
		Help: "Total number of gRPC requests recovered from internal panic.",
	}, []string{"grpc_type", "grpc_service", "grpc_method"})
)

this file is used to write metric items in sp service

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

Metrics is used to monitor sp services

func (*Metrics) Enabled

func (m *Metrics) Enabled() bool

Enabled returns whether starts prometheus metrics

func (*Metrics) Name

func (m *Metrics) Name() string

Name describes metrics service name

func (*Metrics) Start

func (m *Metrics) Start(ctx context.Context) error

Start HTTP server

func (*Metrics) Stop

func (m *Metrics) Stop(ctx context.Context) error

Stop HTTP server

type MetricsConfig

type MetricsConfig struct {
	Enabled     bool   `toml:",omitempty"`
	HTTPAddress string `toml:",omitempty"`
}

MetricsConfig contains the configuration for the metric collection.

type MetricsMonitor

type MetricsMonitor interface {
	lifecycle.Service
	Enabled() bool
}

MetricsMonitor defines abstract method

func GetMetrics

func GetMetrics() MetricsMonitor

GetMetrics gets an instance of MetricsMonitor

func NewMetrics

func NewMetrics(cfg *MetricsConfig) MetricsMonitor

NewMetrics returns a singleton instance of Metrics. Note: enable metrics should call NewMetrics with MetricsConfig and MetricsConfig.Enabled is set true. GetMetrics will return the singleton instance of Metrics to use at anywhere. If NewMetrics is not called, then the metrics is disabled when calls GetMetrics.

type NilMetrics

type NilMetrics struct{}

NilMetrics is a no-op Metrics

func (NilMetrics) Enabled

func (NilMetrics) Enabled() bool

Enabled is a no-op

func (NilMetrics) Name

func (NilMetrics) Name() string

Name is a no-op

func (NilMetrics) Start

func (NilMetrics) Start(ctx context.Context) error

Start is a no-op

func (NilMetrics) Stop

func (NilMetrics) Stop(ctx context.Context) error

Stop is a no-op

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL