Skip to content

Commit c8c19e4

Browse files
roffemurali-reddy
authored andcommitted
Added cli config for changing prometheus port & path (#288)
* added prometheus metrics port option * fix propper config * added option to change path * added path config to prometheus * updated readme * fixed string that should be int
1 parent 42f7177 commit c8c19e4

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Documentation/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Usage of ./kube-router:
116116
--kubeconfig string Path to kubeconfig file with authorization information (the master location is set by the master flag).
117117
--masquerade-all SNAT all traffic to cluster IP/node port.
118118
--master string The address of the Kubernetes API server (overrides any value in kubeconfig).
119+
--metrics-port int Prometheus metrics port to use, ( default 8080 )
120+
--metrics-path string Path to serve Prometheus metrics on, ( default /metrics )
119121
--nodeport-bindon-all-ip For service of NodePort type create IPVS service that listens on all IP's of the node.
120122
--nodes-full-mesh Each node in the cluster will setup BGP peering with rest of the nodes. (default true)
121123
--peer-router-asns uintSlice ASN numbers of the BGP peer to which cluster nodes will advertise cluster ip and node's pod cidr. (default [])

app/controllers/network_services_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ type NetworkServicesController struct {
8383
globalHairpin bool
8484
client *kubernetes.Clientset
8585
nodeportBindOnAllIp bool
86+
MetricsPort int
87+
MetricsPath string
8688
}
8789

8890
// internal representation of kubernetes service
@@ -133,8 +135,8 @@ func (nsc *NetworkServicesController) Run(stopCh <-chan struct{}, wg *sync.WaitG
133135
prometheus.MustRegister(serviceActiveConn)
134136
prometheus.MustRegister(servicePpsIn)
135137
prometheus.MustRegister(servicePpsOut)
136-
http.Handle("/metrics", promhttp.Handler())
137-
go http.ListenAndServe(":8080", nil)
138+
http.Handle(nsc.MetricsPath, promhttp.Handler())
139+
go http.ListenAndServe(":"+strconv.Itoa(nsc.MetricsPort), nil)
138140

139141
// enable ipvs connection tracking
140142
err = ensureIpvsConntrack()
@@ -1565,6 +1567,8 @@ func NewNetworkServicesController(clientset *kubernetes.Clientset, config *optio
15651567
nsc := NetworkServicesController{}
15661568
nsc.syncPeriod = config.IpvsSyncPeriod
15671569
nsc.globalHairpin = config.GlobalHairpinMode
1570+
nsc.MetricsPort = config.MetricsPort
1571+
nsc.MetricsPath = config.MetricsPath
15681572

15691573
nsc.serviceMap = make(serviceInfoMap)
15701574
nsc.endpointsMap = make(endpointsInfoMap)

app/options/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type KubeRouterConfig struct {
3737
EnableOverlay bool
3838
PeerPasswords []string
3939
EnablePprof bool
40+
MetricsPort int
41+
MetricsPath string
4042
// FullMeshPassword string
4143
}
4244

@@ -109,6 +111,9 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
109111
"Password for authenticating against the BGP peer defined with \"--peer-router-ips\".")
110112
fs.BoolVar(&s.EnablePprof, "enable-pprof", false,
111113
"Enables pprof for debugging performance and memory leak issues.")
114+
fs.IntVar(&s.MetricsPort, "metrics-port", 8080, "Prometheus metrics port")
115+
fs.StringVar(&s.MetricsPath, "metrics-path", "/metrics", "Prometheus metrics path")
116+
112117
// fs.StringVar(&s.FullMeshPassword, "nodes-full-mesh-password", s.FullMeshPassword,
113118
// "Password that cluster-node BGP servers will use to authenticate one another when \"--nodes-full-mesh\" is set.")
114119
}

0 commit comments

Comments
 (0)