init work of uptime

This commit is contained in:
Blake Ridgway
2026-03-22 11:30:31 -05:00
parent 854cba4c24
commit f0db70c840
18 changed files with 2252 additions and 0 deletions

46
internal/monitor/tcp.go Normal file
View File

@@ -0,0 +1,46 @@
package monitor
import (
"fmt"
"net"
"time"
"arclineit/arcline-uptime/internal/config"
)
type TCPChecker struct {
cfg config.MonitorConfig
addr string
timeout time.Duration
}
func NewTCPChecker(cfg config.MonitorConfig, timeout time.Duration) *TCPChecker {
return &TCPChecker{
cfg: cfg,
addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
timeout: timeout,
}
}
func (t *TCPChecker) Name() string { return t.cfg.Name }
func (t *TCPChecker) Interval() time.Duration { return time.Duration(t.cfg.Interval) * time.Second }
func (t *TCPChecker) Check() Result {
start := time.Now()
result := Result{
MonitorName: t.cfg.Name,
CheckedAt: start,
}
conn, err := net.DialTimeout("tcp", t.addr, t.timeout)
result.ResponseTime = time.Since(start)
if err != nil {
result.Error = err.Error()
return result
}
conn.Close()
result.Up = true
applyThreshold(&result, t.cfg.MaxResponseMS)
return result
}