Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of the request timeout #54

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ A [Speedtest](https://www.speedtest.net) exporter for Prometheus.

```bash
$ ./speedtest_exporter --help
Usage of speedtest_exporter
Usage of speedtest_exporter:
-port string
listening port to expose metrics on (default "9090")
-server_fallback
If the serverID given is not available, should we fallback to closest available server
If the server_id given is not available, should we fallback to closest available server
-server_id int
Speedtest.net server ID to run test against, -1 will pick the closest server to your location (default -1)
-timeout int
request timeout for the execution of the speedtest (default 60)

```

Expand Down
5 changes: 4 additions & 1 deletion cmd/speedtest_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
port := flag.String("port", "9090", "listening port to expose metrics on")
serverID := flag.Int("server_id", -1, "Speedtest.net server ID to run test against, -1 will pick the closest server to your location")
serverFallback := flag.Bool("server_fallback", false, "If the server_id given is not available, should we fallback to closest available server")
requestTimeout := flag.Int("timeout", 60, "request timeout for the execution of the speedtest")
flag.Parse()

exporter, err := exporter.New(*serverID, *serverFallback)
Expand Down Expand Up @@ -58,7 +59,9 @@ func main() {

http.Handle(metricsPath, promhttp.HandlerFor(r, promhttp.HandlerOpts{
MaxRequestsInFlight: 1,
Timeout: 60 * time.Second,
Timeout: time.Duration(*requestTimeout) * time.Second,
}))

log.Info("starting listener on port: " + *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}