Expose prometheus metrics for globalnet
Since the globalnet collects it's own metrics,
they need to be exposed separately from the engine
Related issue
@@ -16,12 +16,15 @@ limitations under the License.
package main
import (
+ "context"
"flag"
+ "net/http"
"os"
"sync"
"time"
"github.com/kelseyhightower/envconfig"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
submarinerv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/globalnet/controllers/ipam"
@@ -53,6 +56,8 @@ func main() {
// set up signals so we handle the first shutdown signal gracefully
stopCh := signals.SetupSignalHandler()
+ httpServer := startHttpServer()
+
cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig)
if err != nil {
klog.Fatalf("Error building kubeconfig: %s", err.Error())
@@ -105,6 +110,10 @@ func main() {
wg.Wait()
klog.Infof("All controllers stopped or exited. Stopping main loop")
+
+ if err := httpServer.Shutdown(context.TODO()); err != nil {
+ klog.Errorf("Error shutting down metrics HTTP server: %v", err)
+ }
}
func init() {
@@ -112,3 +121,17 @@ func init() {
flag.StringVar(&masterURL, "master", "",
"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
}
+
+func startHttpServer() *http.Server {
+ srv := &http.Server{Addr: ":8081"}
+
+ http.Handle("/metrics", promhttp.Handler())
+
+ go func() {
+ if err := srv.ListenAndServe(); err != http.ErrServerClosed {
+ klog.Errorf("Error starting metrics server: %v", err)
+ }
+ }()
+
+ return srv
+}
