mirror of
https://github.com/status-im/eth-rpc-proxy.git
synced 2026-08-27 17:51:11 +00:00
* feat(go-proxy-cache): handle when cache is not accessible * feat(go-proxy-cache): serve metrics over http * feat(go-proxy-cache): metrics * feat(go-proxy-cache): fix pr comments fixes #67 * feat(go-proxy-cache): update github actions * feat(go-proxy-cache): fix linter
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package httpserver
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// MetricsServer represents a separate HTTP server for metrics
|
|
type MetricsServer struct {
|
|
logger *zap.Logger
|
|
server *http.Server
|
|
}
|
|
|
|
// NewMetricsServer creates a new metrics HTTP server
|
|
func NewMetricsServer(logger *zap.Logger) *MetricsServer {
|
|
return &MetricsServer{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
// Start starts the metrics HTTP server on the specified port
|
|
func (ms *MetricsServer) Start(port string) error {
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/metrics", promhttp.Handler())
|
|
|
|
ms.server = &http.Server{
|
|
Addr: ":" + port,
|
|
Handler: mux,
|
|
ReadTimeout: 30 * time.Second,
|
|
WriteTimeout: 30 * time.Second,
|
|
IdleTimeout: 60 * time.Second,
|
|
}
|
|
|
|
ms.logger.Info("Starting metrics HTTP server", zap.String("port", port))
|
|
return ms.server.ListenAndServe()
|
|
}
|
|
|
|
// Stop stops the metrics HTTP server
|
|
func (ms *MetricsServer) Stop(ctx context.Context) error {
|
|
if ms.server == nil {
|
|
return nil
|
|
}
|
|
|
|
ms.logger.Info("Stopping metrics HTTP server")
|
|
return ms.server.Shutdown(ctx)
|
|
}
|