Skip to content

Commit

Permalink
Allow changing Prometheus metrics path (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
koesie10 authored Jan 18, 2022
1 parent e77bb3a commit 695fa4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ There is not a lot to configure, but these environment variables exist
| `HTTP_CLIENT_TIMEOUT` | Timeout used for HTTP requests. Supports units like ms, s, m. | 5s |
| `HTTP_MAX_AGE_DURATION` | Cache duration for all dynamically generated HTTP responses. Supports units like ms, s, m. | 720h _(30 days)_ |
| `HTTP_USER_AGENT` | User-Agent used for HTTP requests | _iPhone user agent string_ |
| `METRICS_PATH` | Path at which the Prometheus metrics are served. Set to `disable` to disable Prometheus metrics | `/metrics` |
| `POPULAR_SITES` | Comma-separated list of domains used on /popular page | some random web sites |
| `PORT` | HTTP server port | 8080 |
| `SERVER_MODE` | Set to `download` to proxy downloads through besticon or `redirect` to let browser to download instead. (example at [#40](https://github.com/mat/besticon/pull/40#issuecomment-528325450)) | `redirect` |
Expand Down
10 changes: 9 additions & 1 deletion besticon/iconserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,15 @@ func startServer(port string, address string) {
serveAsset("/favicon.ico", "favicon.ico", oneYear)
serveAsset("/apple-touch-icon.png", "apple-touch-icon.png", oneYear)

http.Handle("/metrics", promhttp.Handler())
metricsPath := getenvOrFallback("METRICS_PATH", "/metrics")

if metricsPath != "disable" {
if !strings.HasPrefix(metricsPath, "/") {
logger.Fatalf("METRICS_PATH must start with a slash")
}

http.Handle(metricsPath, promhttp.Handler())
}

addr := address + ":" + port
logger.Print("Starting server on ", addr, "...")
Expand Down

0 comments on commit 695fa4c

Please sign in to comment.