feat(metrics): moved back the metrics endpoint to support the undocumented functionality
This commit is contained in:
parent
1cca40d4c5
commit
160b5ac2c8
2 changed files with 30 additions and 40 deletions
|
|
@ -1,10 +1,38 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"openreplay/backend/pkg/logger"
|
"openreplay/backend/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricServer struct{}
|
type MetricServer struct {
|
||||||
|
registry *prometheus.Registry
|
||||||
|
}
|
||||||
|
|
||||||
func New(log logger.Logger, cs []prometheus.Collector) {}
|
func New(log logger.Logger, cs []prometheus.Collector) {
|
||||||
|
registry := prometheus.NewRegistry()
|
||||||
|
// Add go runtime metrics and process collectors.
|
||||||
|
registry.MustRegister(
|
||||||
|
collectors.NewGoCollector(),
|
||||||
|
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||||
|
)
|
||||||
|
// Add extra metrics
|
||||||
|
registry.MustRegister(cs...)
|
||||||
|
// Expose /metrics HTTP endpoint using the created custom registry.
|
||||||
|
http.Handle(
|
||||||
|
"/metrics", promhttp.HandlerFor(
|
||||||
|
registry,
|
||||||
|
promhttp.HandlerOpts{
|
||||||
|
EnableOpenMetrics: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
go func() {
|
||||||
|
log.Error(context.Background(), "%v", http.ListenAndServe(":8888", nil))
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package metrics
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
||||||
|
|
||||||
"openreplay/backend/pkg/logger"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MetricServer struct {
|
|
||||||
registry *prometheus.Registry
|
|
||||||
}
|
|
||||||
|
|
||||||
func New(log logger.Logger, cs []prometheus.Collector) {
|
|
||||||
registry := prometheus.NewRegistry()
|
|
||||||
// Add go runtime metrics and process collectors.
|
|
||||||
registry.MustRegister(
|
|
||||||
collectors.NewGoCollector(),
|
|
||||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
|
||||||
)
|
|
||||||
// Add extra metrics
|
|
||||||
registry.MustRegister(cs...)
|
|
||||||
// Expose /metrics HTTP endpoint using the created custom registry.
|
|
||||||
http.Handle(
|
|
||||||
"/metrics", promhttp.HandlerFor(
|
|
||||||
registry,
|
|
||||||
promhttp.HandlerOpts{
|
|
||||||
EnableOpenMetrics: true,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
go func() {
|
|
||||||
log.Error(context.Background(), "%v", http.ListenAndServe(":8888", nil))
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue