mirror of
https://github.com/fosrl/newt.git
synced 2026-03-08 03:36:40 +00:00
added healthy check in main.go
added healthy check in main.go extended the ping check that creates a /tmp/healthy file if ping successfull and removes that file if ping failes 3 times. With this you can add the following to the newt docker compose to do the health check: healthcheck: test: ["CMD-SHELL", "test -f /tmp/healthy"] interval: 30s timeout: 10s retries: 3
This commit is contained in:
5
main.go
5
main.go
@@ -137,8 +137,9 @@ func startPingCheck(tnet *netstack.Net, serverIP string, stopChan chan struct{})
|
|||||||
if consecutiveFailures >= 3 {
|
if consecutiveFailures >= 3 {
|
||||||
_ = os.Remove("/tmp/healthy")
|
_ = os.Remove("/tmp/healthy")
|
||||||
}
|
}
|
||||||
// increase interval if it keeps failing
|
// Increase interval if we have consistent failures, with a maximum cap
|
||||||
if consecutiveFailures >= 3 && currentInterval < maxInterval {
|
if consecutiveFailures >= 3 && currentInterval < maxInterval {
|
||||||
|
// Increase by 50% each time, up to the maximum
|
||||||
currentInterval = time.Duration(float64(currentInterval) * 1.5)
|
currentInterval = time.Duration(float64(currentInterval) * 1.5)
|
||||||
if currentInterval > maxInterval {
|
if currentInterval > maxInterval {
|
||||||
currentInterval = maxInterval
|
currentInterval = maxInterval
|
||||||
@@ -152,7 +153,7 @@ func startPingCheck(tnet *netstack.Net, serverIP string, stopChan chan struct{})
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warn("Failed to write health file: %v", err)
|
logger.Warn("Failed to write health file: %v", err)
|
||||||
}
|
}
|
||||||
// Reset interval if we increased it
|
// On success, if we've backed off, gradually return to normal interval
|
||||||
if currentInterval > initialInterval {
|
if currentInterval > initialInterval {
|
||||||
currentInterval = time.Duration(float64(currentInterval) * 0.8)
|
currentInterval = time.Duration(float64(currentInterval) * 0.8)
|
||||||
if currentInterval < initialInterval {
|
if currentInterval < initialInterval {
|
||||||
|
|||||||
Reference in New Issue
Block a user