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 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..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) @@ -50,11 +54,21 @@ 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 + } + 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 {