-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NETOBSERV-765 Restore metrics (#315)
* NETOBSERV-765 Restore metrics * Use dedicated port for metrics
- Loading branch information
Showing
9 changed files
with
1,582 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package server | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var mlog = logrus.WithField("module", "metrics-server") | ||
|
||
type MetricsConfig struct { | ||
Port int | ||
CertFile string | ||
PrivateKeyFile string | ||
} | ||
|
||
func StartMetrics(cfg *MetricsConfig) { | ||
promServer := &http.Server{ | ||
Addr: fmt.Sprintf(":%d", cfg.Port), | ||
// TLS clients must use TLS 1.2 or higher | ||
TLSConfig: &tls.Config{ | ||
MinVersion: tls.VersionTLS12, | ||
}, | ||
} | ||
|
||
// The Handler function provides a default handler to expose metrics | ||
// via an HTTP server. "/metrics" is the usual endpoint for that. | ||
http.Handle("/metrics", promhttp.Handler()) | ||
|
||
if cfg.CertFile != "" && cfg.PrivateKeyFile != "" { | ||
mlog.Infof("listening on https://:%d", cfg.Port) | ||
panic(promServer.ListenAndServeTLS(cfg.CertFile, cfg.PrivateKeyFile)) | ||
} else { | ||
mlog.Infof("listening on http://:%d", cfg.Port) | ||
panic(promServer.ListenAndServe()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.