48 lines
1009 B
Go
48 lines
1009 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/bergabruh/stats-gateway/internal/probes"
|
|
"github.com/bergabruh/stats-gateway/internal/storage"
|
|
)
|
|
|
|
func main() {
|
|
dbPath := flag.String("db", "/var/lib/stats-gateway/stats.db", "sqlite path")
|
|
flag.Parse()
|
|
|
|
st, err := storage.Open(*dbPath)
|
|
if err != nil {
|
|
log.Fatalf("open db: %v", err)
|
|
}
|
|
defer st.Close()
|
|
|
|
targets := []struct {
|
|
Node string
|
|
URL string
|
|
}{
|
|
{"fl", "https://fl.speedtest.projectshitpost.fun/"},
|
|
{"pl1", "https://speedtest.projectshitpost.fun/"},
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
for _, t := range targets {
|
|
r, err := probes.ProbeHTTP(ctx, t.URL)
|
|
if err != nil {
|
|
log.Printf("probe %s: %v", t.Node, err)
|
|
continue
|
|
}
|
|
if err := st.InsertSample(ctx, t.Node, r); err != nil {
|
|
log.Printf("store %s: %v", t.Node, err)
|
|
continue
|
|
}
|
|
log.Printf("probe %s ok: http=%.1fms tls=%.1fms",
|
|
t.Node, r.HTTPLatencyMs, r.TLSHandshakeMs)
|
|
}
|
|
}
|