Skip to content

Commit

Permalink
updated net-test and grafana dashboard to work under ping failure, ma…
Browse files Browse the repository at this point in the history
…x ping timeout 30s only 1 ping
  • Loading branch information
Noah-Huppert committed Apr 8, 2021
1 parent c3685a2 commit dd01677
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
15 changes: 9 additions & 6 deletions grafana/dashboards/net-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"dashLength": 10,
"dashes": false,
"datasource": null,
"description": "Count of failed ICMP ping measurements.",
"fieldConfig": {
"defaults": {},
"overrides": []
Expand Down Expand Up @@ -135,17 +136,17 @@
"targets": [
{
"exemplar": true,
"expr": "ping_failures_total",
"expr": "rate(ping_failures_total[1m])",
"interval": "",
"legendFormat": "",
"legendFormat": "{{target_host}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Failures",
"title": "Ping Failures",
"tooltip": {
"shared": true,
"sort": 0,
Expand Down Expand Up @@ -211,6 +212,8 @@
"alignAsTable": false,
"avg": false,
"current": false,
"hideEmpty": true,
"hideZero": true,
"max": false,
"min": false,
"rightSide": false,
Expand All @@ -227,7 +230,7 @@
"percentage": false,
"pluginVersion": "7.5.3",
"pointradius": 2,
"points": false,
"points": true,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
Expand Down Expand Up @@ -320,12 +323,12 @@
"list": []
},
"time": {
"from": "now-5m",
"from": "now-15m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Net Test",
"uid": "WM-nr_lMk",
"version": 7
"version": 9
}
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const PING_COUNT int = 3
// 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")

// die will print an error then exit the process with code 1
Expand Down Expand Up @@ -133,8 +138,7 @@ func main() {
Buckets: []float64{
0, 20, 40, 60, 80, 100,
150, 200, 500,
1000, 1500, 2000, 3000, 5000,
10000, 30000, 60000, 120000,
1000, 1500, 2000, 3000,
},
},
[]string{"target_host"},
Expand All @@ -156,10 +160,15 @@ func main() {
pingers := []*ping.Pinger{}
for _, host := range targetHosts.Get() {
pinger, err := ping.NewPinger(host)
check(fmt.Sprintf("failed to create pinger for \"%s\"", host), err)
if err != nil {
log.Warnf("failed to create pinger for \"%s\": %s", host, err.Error())
pingFailures.With(prom.Labels{
"target_host": pinger.Addr(),
}).Inc()
}
pinger.Count = PING_COUNT
pinger.SetPrivileged(true)
pinger.Timeout = time.Duration(120) * time.Second // 2 minute timeout
pinger.Timeout = time.Duration(PING_TIMEOUT_MS) * time.Millisecond

pingers = append(pingers, pinger)
}
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd01677

Please sign in to comment.