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 ¶
DBStatsGetter is an interface for sql.DBStats. It's implemented by sql.DB.
Click to show internal directories.
Click to hide internal directories.