sqlmetrics

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBStatsCollector

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

DBStatsCollector implements the prometheus.Collector interface.

func NewDBStatsCollector

func NewDBStatsCollector(dbName string, sg DBStatsGetter, opts ...DBStatsCollectorOption) *DBStatsCollector

NewDBStatsCollector creates a new DBStatsCollector.

Example
package main

import (
	"database/sql"

	"github.com/prometheus/client_golang/prometheus"
	"gitlab.com/gitlab-org/labkit/metrics/sqlmetrics"
)

func main() {
	// Open connection to database
	db, err := sql.Open("postgres", "postgres://postgres:postgres@localhost:5432/mydb")
	if err != nil {
		panic(err)
	}

	// Create a new collector
	collector := sqlmetrics.NewDBStatsCollector("mydb", db)

	// Register collector with Prometheus
	prometheus.MustRegister(collector)
}
Output:

func (*DBStatsCollector) Collect

func (c *DBStatsCollector) Collect(ch chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (*DBStatsCollector) Describe

func (c *DBStatsCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

type DBStatsCollectorOption

type DBStatsCollectorOption func(*dbStatsCollectorConfig)

DBStatsCollectorOption is used to pass options in NewDBStatsCollector.

func WithExtraLabels

func WithExtraLabels(labelValues map[string]string) DBStatsCollectorOption

WithExtraLabels will configure extra label values to apply to the DBStats metrics. A label named db_name will be ignored, as this is set internally.

type DBStatsGetter

type DBStatsGetter interface {
	Stats() sql.DBStats
}

DBStatsGetter is an interface for sql.DBStats. It's implemented by sql.DB.

Jump to

Keyboard shortcuts

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