Documentation
¶
Overview ¶
Package fdbmetrics exposes a pure-Go FDB client's operational counters (client.Database.Metrics, RFC-097) in the Prometheus text exposition format, ready to scrape — with zero dependencies.
Usage:
http.Handle("/metrics", fdbmetrics.Handler(db))
Deliberately NOT a prometheus.Collector: that would pull github.com/prometheus/client_golang into the module for 18 monotonic counters and four latency summaries. A user who wants a Collector writes a trivial one over db.Metrics():
prometheus.NewCounterFunc(opts, func() float64 {
return float64(db.Metrics().TransactionsNotCommitted)
})
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(src MetricsSource) http.Handler
Handler returns an http.Handler that renders the database's counters in the Prometheus text exposition format (text/plain; version=0.0.4). All counters are monotonic; the four latency distributions are summaries.
func WriteText ¶
func WriteText(w io.Writer, s client.ClientMetricsSnapshot) error
WriteText renders one snapshot in the Prometheus text exposition format. Returns the first writer error (the exposition itself cannot fail).
Example ¶
The live integration is one line next to any *client.Database:
http.Handle("/metrics", fdbmetrics.Handler(db))
WriteText renders a single snapshot wherever an io.Writer goes.
package main
import (
"bytes"
"fmt"
"strings"
"fdb.dev/pkg/fdbgo/client"
"fdb.dev/pkg/fdbgo/fdbmetrics"
)
func main() {
var buf bytes.Buffer
_ = fdbmetrics.WriteText(&buf, client.ClientMetricsSnapshot{TransactionsNotCommitted: 2})
for _, line := range strings.Split(buf.String(), "\n") {
if strings.HasPrefix(line, "fdb_client_transactions_not_committed_total") {
fmt.Println(line)
}
}
}
Output: fdb_client_transactions_not_committed_total 2
Types ¶
type MetricsSource ¶
type MetricsSource interface {
Metrics() client.ClientMetricsSnapshot
}
MetricsSource is the part of *client.Database this package consumes — accepted as an interface so tests and wrappers can substitute snapshots.