Documentation ¶
Overview ¶
Package promdb is a quick library for adding prometheus metrics to your service for your databases, utilizing the sql.DBStats struct results.
Exable without labels
db, _ := sql.Open("postgres", "") collector := promdb.NewDatabaseCollector(db) prometheus.MustRegister(collector)
Example with labels
var labels prometheus.Labels var collector *promdb.DatabaseCollector authdb, _ := sql.Open("mysql", "") labels = prometheus.Labels{"driver": "mysql", "backend": "authdb"} collector = promdb.NewDatabaseCollectorWithLabels(authdb, labels) prometheus.MustRegister(collector) billingdb, _ := sql.Open("postgres", "") labels = prometheus.Labels{"driver": "postgres"} collector = promdb.NewDatabaseCollectorWithLabels(billingdb, labels) prometheus.MustRegister(collector.WithLabel("backend", "billingdb")) eventsdb, _ := sql.Open("postgres", "") labels = prometheus.Labels{"driver": "postgres", "backend": "eventsdb"} collector = promdb.NewDatabaseCollector(eventsdb) prometheus.MustRegister(collector.With(labels)) statsdb, _ := sql.Open("bigquery", "") collector = promdb.NewDatabaseCollector(statsdb).WithLabel("driver", "bigquery") prometheus.MustRegister(collector.WithLabel("backend", "statsdb"))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBWithStats ¶
DBWithStats is an interface used by DatabaseCollector
type DatabaseCollector ¶
type DatabaseCollector struct {
// contains filtered or unexported fields
}
DatabaseCollector implements prometheus.Collector interface
func NewDatabaseCollector ¶
func NewDatabaseCollector(db DBWithStats) *DatabaseCollector
NewDatabaseCollector creates a new instance of DatabaseCollector with no labels
func NewDatabaseCollectorWithLabels ¶
func NewDatabaseCollectorWithLabels(db DBWithStats, labels prometheus.Labels) *DatabaseCollector
NewDatabaseCollectorWithLabels creates a new instance of DatabaseCollector with the specified prometheus labels
func (*DatabaseCollector) Collect ¶
func (c *DatabaseCollector) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector interface
func (*DatabaseCollector) Describe ¶
func (c *DatabaseCollector) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector interface
func (*DatabaseCollector) With ¶
func (c *DatabaseCollector) With(labels prometheus.Labels) *DatabaseCollector
With returns a new instance of DatabaseCollector with the specified labels merging with any previous labels that may have been defined
func (*DatabaseCollector) WithLabel ¶
func (c *DatabaseCollector) WithLabel(name, value string) *DatabaseCollector
WithLabel is a shortcut to With for providing a single label and value