Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions metrics/metrics.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"time"

"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/prometheus/client_golang/prometheus"
Expand DownExpand Up@@ -48,12 +49,23 @@ func NewMetrics(ipPortAddress string, reg prometheus.Registerer, logger logging.
func (m *Metrics) Start(ctx context.Context, reg prometheus.Gatherer) <-chan error {
m.logger.Infof("Starting metrics server at port %v", m.ipPortAddress)
errC := make(chan error, 1)

server := http.Server{
Addr: m.ipPortAddress,
Handler: http.NewServeMux(),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
MaxHeaderBytes: 1 << 20, // This is 1MB
}

server.Handler.(*http.ServeMux).Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{},
))

go func() {
http.Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{},
))
err := http.ListenAndServe(m.ipPortAddress, nil)
err := server.ListenAndServe()
if err != nil {
errC <- errors.New("prometheus server failed")
} else {
Expand Down