diff --git a/cmd/main.go b/cmd/main.go index 3bb0983..8239e11 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ import ( "os" goruntime "runtime" + "github.com/spf13/pflag" "sigs.k8s.io/controller-runtime/pkg/log/zap" "github.com/samba-in-kubernetes/smbmetrics/internal/metrics" @@ -23,6 +24,11 @@ func init() { } func main() { + var port int + pflag.IntVar(&port, "port", metrics.DefaultMetricsPort, + "Prometheus metrics-exporter port number") + pflag.Parse() + log := zap.New(zap.UseDevMode(true)) log.Info("Initializing smbmetrics", "ProgramName", os.Args[0], @@ -48,7 +54,7 @@ func main() { } log.Info("Located smbstatus", "path", loc, "version", ver) - err = metrics.RunSmbMetricsExporter(log, metrics.DefaultMetricsPort) + err = metrics.RunSmbMetricsExporter(log, port) if err != nil { os.Exit(1) } diff --git a/go.mod b/go.mod index 09bb49a..4648dd6 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.16 require ( github.com/go-logr/logr v0.4.0 github.com/prometheus/client_golang v1.11.1 + github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.7.0 k8s.io/api v0.22.2 k8s.io/apimachinery v0.22.2