Skip to content

Commit

Permalink
Merge pull request #285 from bookingcom/grzkv/prom_local
Browse files Browse the repository at this point in the history
Added an option to expose Prometheus metrics locally.
  • Loading branch information
grzkv authored Jan 6, 2025
2 parents 0d946d0 + 2f4fc5e commit c0d5904
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/nanotube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func main() {
}

go func() {
l, err := reuseport.Listen("tcp", fmt.Sprintf(":%d", cfg.PromPort))
addrHostPrefix := ""
if cfg.PromLocal {
addrHostPrefix = "127.0.0.1"
}
l, err := reuseport.Listen("tcp", fmt.Sprintf("%s:%d", addrHostPrefix, cfg.PromPort))
if err != nil {
lg.Error("opening TCP port for Prometheus failed", zap.Error(err))
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type Main struct {
// -1 turns off pprof server
PprofPort int
PromPort int
// Expose the Prometheus metrics locally.
PromLocal bool
// Switch to expose only small subset of essential metrics.
// (Useful to reduce Prometheus load when running as a sidecar on many nodes in a large setup.)
LessMetrics bool
Expand Down

0 comments on commit c0d5904

Please sign in to comment.