Models are defined by creating a struct like in the most ORM's. As pg-exporter uses bun,
the same bun
tags are used.
In addition, the following pg-exporter specific tags are available and required for code-generation:
- help: defines the help text for the metric
- metric: defines metric name and type. The first, optional paramter is the name. Type could be:
- counter: for counter values
- gauge: for gauge values
- label: fo labels
run go generate .
in the root folder of the project
- create a new, empty, struct in the
collector
package, that implements theScraper
interface. - Inside the
Scrape
function, fetch your data from the database with the given database connection.- see bun for details how to do that
- use the (generated) function
ToMetrics
on your result to provide the metrics to the prometheus handler