@@ -33,6 +33,7 @@ type Config struct {
33
33
DataPath string `mapstructure:"data-path"`
34
34
ConfigPath string `mapstructure:"config-path"`
35
35
Port string `mapstructure:"port"`
36
+ PortMetrics int `mapstructure:"port-metrics"`
36
37
Hostname string `mapstructure:"hostname"`
37
38
RandomDelay bool `mapstructure:"random-delay"`
38
39
RandomError bool `mapstructure:"random-error"`
@@ -96,6 +97,7 @@ func (s *Server) registerMiddlewares() {
96
97
}
97
98
98
99
func (s * Server ) ListenAndServe (stopCh <- chan struct {}) {
100
+ go s .startMetricsServer ()
99
101
100
102
s .registerHandlers ()
101
103
s .registerMiddlewares ()
@@ -157,6 +159,24 @@ func (s *Server) ListenAndServe(stopCh <-chan struct{}) {
157
159
}
158
160
}
159
161
162
+ func (s * Server ) startMetricsServer () {
163
+ if s .config .PortMetrics > 0 {
164
+ mux := http .DefaultServeMux
165
+ mux .Handle ("/metrics" , promhttp .Handler ())
166
+ mux .HandleFunc ("/healthz" , func (w http.ResponseWriter , r * http.Request ) {
167
+ w .WriteHeader (http .StatusOK )
168
+ w .Write ([]byte ("OK" ))
169
+ })
170
+
171
+ srv := & http.Server {
172
+ Addr : fmt .Sprintf (":%v" , s .config .PortMetrics ),
173
+ Handler : mux ,
174
+ }
175
+
176
+ srv .ListenAndServe ()
177
+ }
178
+ }
179
+
160
180
func (s * Server ) printRoutes () {
161
181
s .router .Walk (func (route * mux.Route , router * mux.Router , ancestors []* mux.Route ) error {
162
182
pathTemplate , err := route .GetPathTemplate ()
0 commit comments