mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-29 06:28:23 +02:00
* feat: add daemon websocket task wakeups * feat: fan out daemon wakeups across nodes * fix: dedupe daemon wakeup loopback events * fix: lengthen daemon polling fallback interval --------- Co-authored-by: Eve <eve@multica.ai>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package metrics
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
|
|
|
"github.com/multica-ai/multica/server/internal/daemonws"
|
|
"github.com/multica-ai/multica/server/internal/realtime"
|
|
)
|
|
|
|
type RegistryOptions struct {
|
|
Pool *pgxpool.Pool
|
|
Realtime *realtime.Metrics
|
|
DaemonWS *daemonws.Metrics
|
|
Version string
|
|
Commit string
|
|
}
|
|
|
|
type Registry struct {
|
|
Gatherer prometheus.Gatherer
|
|
HTTP *HTTPMetrics
|
|
}
|
|
|
|
func NewRegistry(opts RegistryOptions) *Registry {
|
|
reg := prometheus.NewRegistry()
|
|
reg.MustRegister(collectors.NewGoCollector())
|
|
reg.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
|
|
|
|
buildInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
Name: "multica_build_info",
|
|
Help: "Build information for the Multica server binary.",
|
|
}, []string{"version", "commit"})
|
|
buildInfo.WithLabelValues(defaultLabel(opts.Version, "dev"), defaultLabel(opts.Commit, "unknown")).Set(1)
|
|
reg.MustRegister(buildInfo)
|
|
|
|
httpMetrics := NewHTTPMetrics()
|
|
reg.MustRegister(httpMetrics.Collectors()...)
|
|
|
|
if opts.Pool != nil {
|
|
reg.MustRegister(NewDBCollector(opts.Pool))
|
|
}
|
|
if opts.Realtime != nil {
|
|
reg.MustRegister(NewRealtimeCollector(opts.Realtime))
|
|
}
|
|
if opts.DaemonWS != nil {
|
|
reg.MustRegister(NewDaemonWSCollector(opts.DaemonWS))
|
|
}
|
|
|
|
return &Registry{
|
|
Gatherer: reg,
|
|
HTTP: httpMetrics,
|
|
}
|
|
}
|
|
|
|
func defaultLabel(value, fallback string) string {
|
|
value = strings.TrimSpace(value)
|
|
if value == "" {
|
|
return fallback
|
|
}
|
|
return value
|
|
}
|