diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 45ffd3d2c..86d91f6cc 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -74,6 +74,7 @@ func main() { // This mirrors how kubectl extracts information from the environment. var ( listenAddr = fs.StringP("listen", "l", ":3030", "Listen address where /metrics and API will be served") + listenMetricsAddr = fs.String("listen-metrics", "", "Listen address for /metrics endpoint") kubernetesKubectl = fs.String("kubernetes-kubectl", "", "Optional, explicit path to kubectl tool") versionFlag = fs.Bool("version", false, "Get version number") // Git repo & key etc. @@ -445,12 +446,24 @@ func main() { go func() { mux := http.DefaultServeMux - mux.Handle("/metrics", promhttp.Handler()) + // Serve /metrics alongside API + if *listenMetricsAddr == "" { + mux.Handle("/metrics", promhttp.Handler()) + } handler := daemonhttp.NewHandler(daemon, daemonhttp.NewRouter()) mux.Handle("/api/flux/", http.StripPrefix("/api/flux", handler)) logger.Log("addr", *listenAddr) errc <- http.ListenAndServe(*listenAddr, mux) }() + if *listenMetricsAddr != "" { + go func() { + mux := http.NewServeMux() + mux.Handle("/metrics", promhttp.Handler()) + logger.Log("metrics-addr", *listenMetricsAddr) + errc <- http.ListenAndServe(*listenMetricsAddr, mux) + }() + } + // Fall off the end, into the waiting procedure. } diff --git a/deploy/flux-deployment.yaml b/deploy/flux-deployment.yaml index 27decb7a8..4a1f9fb78 100644 --- a/deploy/flux-deployment.yaml +++ b/deploy/flux-deployment.yaml @@ -12,6 +12,8 @@ spec: type: Recreate template: metadata: + annotations: + prometheus.io.port: "3031" # tell prometheus to scrape /metrics endpoint's port. labels: name: flux spec: @@ -34,7 +36,7 @@ spec: # repo rather than using github or the like. You'll also need to # mount it into the container, below. # - name: ssh-config - # configMap: + # configMap: # name: flux-ssh-config containers: @@ -78,3 +80,7 @@ spec: # (e.g., Weave Cloud). The token is particular to the service. # - --connect=wss://cloud.weave.works/api/flux # - --token=abc123abc123abc123abc123 + + # serve /metrics endpoint at different port. + # make sure to set prometheus' annotation to scrape the port value. + - --listen-metrics=:3031 diff --git a/site/daemon.md b/site/daemon.md index 56f1ee850..f595d0889 100644 --- a/site/daemon.md +++ b/site/daemon.md @@ -27,12 +27,12 @@ Version controlling of cluster manifests provides reproducibility and a historic Deployment happens automatically when a new image tag is detected. Deautomated deployment will not proceed until manually released (through the UI or the CLI tool fluxctl). - + 2. Lock vs Unlock Deployment is pinned to a particular image tag. New deployment will not proceed upon triggered release. - + # Flags fluxd requires setup and offers customization though a multitude of flags. @@ -40,6 +40,7 @@ fluxd requires setup and offers customization though a multitude of flags. |flag | default | purpose | |------------------------|-------------------------------|---------| |--listen -l | `:3030` | listen address where /metrics and API will be served| +|--listen-metrics | | listen address for /metrics endpoint | |--kubernetes-kubectl | | optional, explicit path to kubectl tool| |--version | false | output the version number and exit | |**Git repo & key etc.** | ||