https://github.com/profects/gormetrics
Prometheus Metrics for GORM
https://github.com/profects/gormetrics
database golang gorm metrics prometheus
Last synced: 5 months ago
JSON representation
Prometheus Metrics for GORM
- Host: GitHub
- URL: https://github.com/profects/gormetrics
- Owner: profects
- License: apache-2.0
- Created: 2019-08-16T14:01:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-08T12:03:30.000Z (almost 2 years ago)
- Last Synced: 2025-08-13T23:47:04.478Z (11 months ago)
- Topics: database, golang, gorm, metrics, prometheus
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 12
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gormetrics
[](https://goreportcard.com/report/github.com/profects/gormetrics)
[](http://godoc.org/github.com/profects/gormetrics)
A plugin for GORM providing metrics using Prometheus.
Warning: this plugin is still in an early stage of development. APIs may change.
## Usage
```go
import "github.com/profects/gormetrics"
err := gormetrics.Register(db, )
if err != nil {
// handle the error
}
```
gormetrics does not expose the metrics endpoint using promhttp, you have to do this yourself.
You can use the following snippet for exposing metrics on port 2112 at `/metrics`:
```go
go func() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":2112", nil))
}()
```
## Exported metrics
gormetrics exports the following metrics (counter vectors):
* `gormetrics_all_total`
* `gormetrics_creates_total`
* `gormetrics_deletes_total`
* `gormetrics_queries_total`
* `gormetrics_updates_total`
These all have the following labels:
* `database`: the name of the database
* `driver`: the driver for the database (e.g. pq)
* `status`: fail or success
It also export the following metrics (gauge vectors):
* `gormetrics_connections_idle`
* `gormetrics_connections_in_use`
* `gormetrics_connections_open`
These all have the following labels:
* `database`: the name of the database
* `driver`: the driver for the database (e.g. pq)