File: examples_test.go

package info (click to toggle)
golang-gitlab-gitlab-org-labkit 1.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,092 kB
  • sloc: sh: 210; javascript: 49; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 504 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package sqlmetrics_test

import (
	"database/sql"

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

func ExampleNewDBStatsCollector() {
	// 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)
}