@@ -12,28 +12,35 @@ By default, the metrics are served on `0.0.0.0:8383/metrics`. To modify the port
12
12
13
13
``` go
14
14
import (
15
- " github.com/operator-framework/operator-sdk/pkg/metrics"
16
- " sigs.k8s.io/controller-runtime/pkg/manager"
15
+ " github.com/operator-framework/operator-sdk/pkg/metrics"
16
+ " sigs.k8s.io/controller-runtime/pkg/manager"
17
17
)
18
18
19
- // Change the below variables to serve metrics on different host or port.
20
- var metricsHost = " 0.0.0.0"
21
- var metricsPort int32 = 8383
22
-
23
- // Pass metrics address to controller-runtime manager
24
- mgr , err := manager.New (cfg, manager.Options {
25
- Namespace : namespace,
26
- MetricsBindAddress : fmt.Sprintf (" %s :%d " , metricsHost, metricsPort),
27
- })
28
-
29
- ...
30
-
31
- // Create Service object to expose the metrics port.
32
- _, err = metrics.ExposeMetricsPort (ctx, metricsPort)
33
- if err != nil {
34
- // handle error
35
- log.Info (err.Error ())
36
- }
19
+ func main () {
20
+
21
+ ...
22
+
23
+ // Change the below variables to serve metrics on different host or port.
24
+ var metricsHost = " 0.0.0.0"
25
+ var metricsPort int32 = 8383
26
+
27
+ // Pass metrics address to controller-runtime manager
28
+ mgr , err := manager.New (cfg, manager.Options {
29
+ Namespace: namespace,
30
+ MetricsBindAddress: fmt.Sprintf (" %s :%d " , metricsHost, metricsPort),
31
+ })
32
+
33
+ ...
34
+
35
+ // Create Service object to expose the metrics port.
36
+ _, err = metrics.ExposeMetricsPort (ctx, metricsPort)
37
+ if err != nil {
38
+ // handle error
39
+ log.Info (err.Error ())
40
+ }
41
+
42
+ ...
43
+ }
37
44
```
38
45
39
46
Note: The above example is already present in ` cmd/manager/main.go ` in all the operators generated with operator-sdk.
0 commit comments