From 17d40d19849c5a36aebd8dae9486884b3bd55b7b Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Wed, 28 Sep 2022 14:28:50 +0200 Subject: [PATCH 1/4] Add docker pull command to readme Update readme & example env Fix readme --- .env.example | 6 ++++-- README.md | 26 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 0f1e566..43676ef 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,10 @@ -GIN_MODE=release - # interval in seconds INTERVAL=60 # ping check destinations separated by comma PING_HOSTS=1.1.1.1,google.com +PING_TIMEOUT=5 PING_PRIVILEGED=false + +# webserver mode +GIN_MODE=release diff --git a/README.md b/README.md index 7cb47ad..42ca3bb 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,29 @@ ## Features -- Monitor network uptime -- Pings & Speed test +- Continuously monitors network availability with Pings to configurated servers +- Web UI with interactive charts Built with [Go](https://go.dev/) and [SQLite](https://sqlite.org/). -## Docker +## Usage (Docker) + +``` +docker pull ghcr.io/romanzipp/sprinter:latest +``` + +See [repository](https://github.com/romanzipp/Sprinter/pkgs/container/sprinter) for more information. + +### Environment variables + +- `INTERVAL` Ping interval in seconds (default: `60`) +- `PING_HOSTS` Destination servers, separated by comma (default: `1.1.1.1,google.com`) +- `PING_TIMEOUT` Ping timeout in seconds (default: `5`) +- `PING_PRIVILEGED` Privileged UDP ping mode (see [Troubleshooting](#troubleshooting)) + +--- + +### Local #### Build @@ -62,6 +79,9 @@ yarn install ```shell yarn watch ``` +## Roadmap + +- [ ] Make ping timeout configurable ## Troubleshooting From bca9794246f03f1ea9627b23c9e5edf964bc6399 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Wed, 28 Sep 2022 14:39:24 +0200 Subject: [PATCH 2/4] Make ping timeout configurable --- config/config.go | 1 + main.go | 6 ++++++ models/check.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 8160377..2dc4f9a 100644 --- a/config/config.go +++ b/config/config.go @@ -3,5 +3,6 @@ package config type Config struct { Interval int64 PingHosts []string + PingTimeout int64 PingPrivileged bool } diff --git a/main.go b/main.go index a94da3b..705296a 100644 --- a/main.go +++ b/main.go @@ -50,11 +50,17 @@ func main() { func makeConfig() config.Config { interval, _ := strconv.ParseInt(os.Getenv("INTERVAL"), 10, 64) + timeout, _ := strconv.ParseInt(os.Getenv("PING_TIMEOUT"), 10, 64) + if timeout == 0 { + timeout = 5 + } + pingHosts := strings.Split(os.Getenv("PING_HOSTS"), ",") return config.Config{ Interval: interval, PingHosts: pingHosts, + PingTimeout: timeout, PingPrivileged: os.Getenv("PING_PRIVILEGED") == "true", } } diff --git a/models/check.go b/models/check.go index b340ddc..7f1e3c4 100644 --- a/models/check.go +++ b/models/check.go @@ -30,7 +30,7 @@ func ExecPingCheck(host string, id string, conf config.Config, db *gorm.DB) { } pinger.Count = 1 - pinger.Timeout = 5 * time.Second + pinger.Timeout = time.Duration(conf.PingTimeout) * time.Second pinger.Debug = true err = pinger.Run() if err != nil { From 27b5386b256effddeb131f13a082049a88ff7231 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Wed, 28 Sep 2022 14:39:36 +0200 Subject: [PATCH 3/4] Add default value for interval env var --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 705296a..36a9f15 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,10 @@ func main() { func makeConfig() config.Config { interval, _ := strconv.ParseInt(os.Getenv("INTERVAL"), 10, 64) + if interval == 0 { + interval = 60 + } + timeout, _ := strconv.ParseInt(os.Getenv("PING_TIMEOUT"), 10, 64) if timeout == 0 { timeout = 5 From daace6d7faff4d757a6eef1f57c07a2d2ba7af98 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Wed, 28 Sep 2022 14:39:47 +0200 Subject: [PATCH 4/4] Abort execution if no ping hosts configured --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 36a9f15..4ec455e 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,10 @@ func main() { ) conf := makeConfig() + if len(conf.PingHosts) == 0 { + panic("no ping hosts configured") + } + db := makeDb() router := makeRouter(db)