33 lines
842 B
Go
33 lines
842 B
Go
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
|
||
|
|
}))
|
||
|
|
}
|
||
|
|
}
|