Skip to content

Commit

Permalink
main: allow passing '--port' via command line
Browse files Browse the repository at this point in the history
Allow user to control the Prometheus metrics port number. If non is
given, use default port-number.

Signed-off-by: Shachar Sharon <[email protected]>
  • Loading branch information
synarete committed Jul 7, 2024
1 parent 2c9b0ad commit e8996ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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],
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8996ce

Please sign in to comment.