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 timeout to be configurable #6

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Host picking strategy:
Measurement options:

- `-p int`: Interval in milliseconds at which to perform the ping measurement. A value of -1 disables this test. Results recorded to the `ping_rtt_ms` and `ping_failures_total` metrics with the `target_host` label. (default 10000)
- `-o int`: Interval in milliseconds for which a ping attempt will timeout. (default 30000)

Other options:

Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
// PING_COUNT is the number of ping packets sent to determine the average round trip time.
const PING_COUNT int = 1

// PING_TIMEOUT_MS is the number of milliseconds before a ping attempt will timeout. 30 seconds.
const PING_TIMEOUT_MS int = 30000

// log is the application logger.
var log golog.Logger = golog.NewLogger("net-test")

Expand Down Expand Up @@ -101,6 +98,12 @@ func main() {
10000,
fmt.Sprintf("Interval in milliseconds at which to perform the ping measurement. Will perform %d ping(s). A value of -1 disables this test. Results recorded to the \"ping_rtt_ms\" and \"ping_failures_total\" metrics with the \"target_host\" label.", PING_COUNT))

var timeoutMs int
flag.IntVar(&timeoutMs,
"o",
30000,
"Change timeout of the ping")

flag.Parse()

if len(targetHosts.Get()) == 0 {
Expand Down Expand Up @@ -169,7 +172,7 @@ func main() {
}
pinger.Count = PING_COUNT
pinger.SetPrivileged(true)
pinger.Timeout = time.Duration(PING_TIMEOUT_MS) * time.Millisecond
pinger.Timeout = time.Duration(timeoutMs) * time.Millisecond

pingers = append(pingers, pinger)
}
Expand Down