chore: establish local platform baseline
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package outbox
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func RegisterMetrics(pool *pgxpool.Pool) {
|
||||
for _, status := range []string{"pending", "processing", "dead"} {
|
||||
status := status
|
||||
prometheus.MustRegister(prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: "voice_platform",
|
||||
Subsystem: "outbox",
|
||||
Name: "events",
|
||||
Help: "Current outbox event count by status.",
|
||||
ConstLabels: prometheus.Labels{
|
||||
"status": status,
|
||||
},
|
||||
}, func() float64 {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
var count float64
|
||||
if err := pool.QueryRow(ctx, "SELECT count(*)::float8 FROM outbox_event WHERE status = $1", status).Scan(&count); err != nil {
|
||||
return 0
|
||||
}
|
||||
return count
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user