Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request weaveworks#250 from ssncferreira/server_tcp_metric…
Browse files Browse the repository at this point in the history
…s_fix

Bugfix server tcp metrics to use the configured registry or the default Prometheus registry
  • Loading branch information
bboreham authored Aug 10, 2022
2 parents 72ba250 + e389dd3 commit c65105d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,36 @@ type Server struct {

// New makes a new Server
func New(cfg Config) (*Server, error) {
// If user doesn't supply a logging implementation, by default instantiate
// logrus.
log := cfg.Log
if log == nil {
log = logging.NewLogrus(cfg.LogLevel)
}

// If user doesn't supply a registerer/gatherer, use Prometheus' by default.
reg := cfg.Registerer
if reg == nil {
reg = prometheus.DefaultRegisterer
}
gatherer := cfg.Gatherer
if gatherer == nil {
gatherer = prometheus.DefaultGatherer
}

tcpConnections := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: cfg.MetricsNamespace,
Name: "tcp_connections",
Help: "Current number of accepted TCP connections.",
}, []string{"protocol"})
prometheus.MustRegister(tcpConnections)
reg.MustRegister(tcpConnections)

tcpConnectionsLimit := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: cfg.MetricsNamespace,
Name: "tcp_connections_limit",
Help: "The max number of TCP connections that can be accepted (0 means no limit).",
}, []string{"protocol"})
prometheus.MustRegister(tcpConnectionsLimit)
reg.MustRegister(tcpConnectionsLimit)

network := cfg.HTTPListenNetwork
if network == "" {
Expand Down Expand Up @@ -226,23 +243,6 @@ func New(cfg Config) (*Server, error) {
grpcListener = netutil.LimitListener(grpcListener, cfg.GRPCConnLimit)
}

// If user doesn't supply a logging implementation, by default instantiate
// logrus.
log := cfg.Log
if log == nil {
log = logging.NewLogrus(cfg.LogLevel)
}

// If user doesn't supply a registerer/gatherer, use Prometheus' by default.
reg := cfg.Registerer
if reg == nil {
reg = prometheus.DefaultRegisterer
}
gatherer := cfg.Gatherer
if gatherer == nil {
gatherer = prometheus.DefaultGatherer
}

// Setup TLS
var httpTLSConfig *tls.Config
if len(cfg.HTTPTLSConfig.TLSCertPath) > 0 && len(cfg.HTTPTLSConfig.TLSKeyPath) > 0 {
Expand Down

0 comments on commit c65105d

Please sign in to comment.