metric

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConnInUse = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_in_use",
			Help: "The number of connections currently in use",
		},
		[]string{sqlInstance},
	)
	ConnIdle = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_idle",
			Help: "The number of idle connections",
		},
		[]string{sqlInstance},
	)
	ConnWait = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_wait",
			Help: "The total number of connections wait for",
		},
		[]string{sqlInstance},
	)
	ConnIdleClosed = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_idle_closed",
			Help: "The total number of connections closed because of SetMaxIdleConns",
		},
		[]string{sqlInstance},
	)
	ConnIdleTimeClosed = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_idle_time_closed",
			Help: "The total number of connections closed because of SetConnMaxIdleTime",
		},
		[]string{sqlInstance},
	)
	ConnLifetimeClosed = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_lifetime_closed",
			Help: "The total number of connections closed becase of SetConnMaxLifetime",
		},
		[]string{sqlInstance},
	)
	ConnWaitMS = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "go_sql_conn_wait_ms",
			Help: "The total time blocked by waiting for a new connection, millisecond.",
		},
		[]string{sqlInstance},
	)
)
View Source
var (
	DefaultLatency = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "go_sql_latency",
			Help: "The latency of sql calls in milliseconds.",
		},
		[]string{sqlInstance, sqlDatabase, sqlMethod, sqlStatus},
	)
)

Functions

func Stats

func Stats(ctx context.Context, db *sql.DB, name string, every time.Duration)

Stats, monitor db connection pool with interval every.

Types

type Hook

type Hook struct {
	*Options
}

func New

func New(opts ...Option) (*Hook, error)

func (*Hook) After

func (hook *Hook) After(ctx context.Context, evt *otsql.Event)

func (*Hook) Before

func (hook *Hook) Before(ctx context.Context, evt *otsql.Event) context.Context

type Option

type Option func(*Options)

func WithLatency

func WithLatency(latency *prometheus.HistogramVec) Option

WithLatency

func WithRegisterer

func WithRegisterer(registerer prometheus.Registerer) Option

WithRegisterer

type Options

type Options struct {
	// Regiterer is prometheus Registerer, default prometheus.DefaultRegisterer
	Registerer prometheus.Registerer

	// Latency histogram, default DefaultLatency
	Latency *prometheus.HistogramVec
}

Options

Jump to

Keyboard shortcuts

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