Initial commit: stats-gateway gRPC service + dashboard + CLI
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user