Add metrics support

This change introduces prometheus metric exporter support for
multus-daemon, thick plugin.
This commit is contained in:
Tomofumi Hayashi
2022-06-02 18:20:38 +09:00
parent df903a757e
commit 9f3e6b0da0
159 changed files with 34579 additions and 17 deletions

View File

@@ -19,6 +19,7 @@ import (
"flag"
"fmt"
"io"
"net/http"
"os"
"os/user"
"path/filepath"
@@ -30,6 +31,8 @@ import (
srv "gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server"
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/server/config"
"gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/types"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
@@ -231,6 +234,14 @@ func startMultusDaemon(configFilePath string) error {
return fmt.Errorf("failed to create the server: %v", err)
}
if daemonConfig.MetricsPort != nil {
go utilwait.Forever(func() {
http.Handle("/metrics", promhttp.Handler())
logging.Debugf("metrics port: %d", *daemonConfig.MetricsPort)
logging.Debugf("metrics: %s", http.ListenAndServe(fmt.Sprintf(":%d", *daemonConfig.MetricsPort), nil))
}, 0)
}
l, err := srv.GetListener(srv.SocketPath(daemonConfig.MultusSocketDir))
if err != nil {
return fmt.Errorf("failed to start the CNI server using socket %s. Reason: %+v", srv.SocketPath(daemonConfig.MultusSocketDir), err)