Compare commits

...

10 Commits

Author SHA1 Message Date
bel 439c481c60 log err
cicd / ci (push) Successful in 3m25s
2026-07-07 17:16:08 -06:00
bel 0a58f85ca3 2d cause only reaps sad
cicd / ci (push) Successful in 2m56s
2026-06-28 09:42:07 -06:00
bel 141c0e5100 forget it 30d
cicd / ci (push) Successful in 3m12s
2026-06-28 09:35:43 -06:00
bel 9f3de791f9 fix killnig and 55h 2026-06-28 09:35:22 -06:00
bel 8d3db70e01 botched
cicd / ci (push) Has been cancelled
2026-06-28 09:33:04 -06:00
bel 831fed82f7 go delete success from more than 12h ago
cicd / ci (push) Successful in 3m39s
2026-06-28 09:23:11 -06:00
bel 43887bb447 list ms too
cicd / ci (push) Successful in 2m3s
2026-06-28 00:56:29 -06:00
bel 0b9b790986 okay,slow,err
cicd / ci (push) Successful in 2m51s
2026-06-28 00:51:16 -06:00
bel ae54bee23b dockerfile
cicd / ci (push) Successful in 3m14s
2026-06-28 00:28:19 -06:00
bel 84a8897bf0 it is techincally a ui 2026-06-28 00:27:14 -06:00
3 changed files with 96 additions and 4 deletions
+15
View File
@@ -0,0 +1,15 @@
FROM golang:1.26-trixie AS builder
WORKDIR /go/src/
COPY ./go.* ./
COPY ./cmd ./cmd/
COPY ./.vendor ./.vendor/
ENV CGO_ENABLED=0
RUN go build \
-o /go/bin/binary \
-mod=readonly \
-ldflags="-extldflags '-static'" \
./cmd/*/
FROM debian:trixie-slim AS runtime
COPY --from=builder /go/bin/binary /bin/binary
CMD []
ENTRYPOINT ["/bin/binary"]
+48
View File
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<header>
<script>
function onload() {
const results = [
{{ range $v := query
`
SELECT
start AS start
, CASE
WHEN ms < 50 AND ok THEN
'okay'
WHEN ms < 750 AND ok THEN
'slow'
ELSE
'bad'
END AS ok
, ms AS ms
FROM
"pinger_pings"
ORDER BY start DESC
LIMIT 1000
`
-}}
[
{{.ok}}==="okay"
? "🟢"
: {{.ok}}==="slow"
? "🟠"
: "🔴",
`${Math.round((new Date() - 1000*{{.start}})/1000.0)}s ago`,
new Date(1000*{{.start}}),
"{{.ms}}ms",
],
{{ end }}
]
document.getElementById("draw").innerHTML = results.map((r) => `<br>${JSON.stringify(r)}`).join("\n");
}
</script>
</header>
<body onload="onload()">
<div id="draw">
</div>
</body>
<footer>
</footer>
</html>
+33 -4
View File
@@ -42,6 +42,7 @@ func run(ctx context.Context) error {
defer wg.Wait() defer wg.Wait()
for _, foo := range []func(context.Context) error{ for _, foo := range []func(context.Context) error{
s.pingAndRecord, s.pingAndRecord,
s.collectGarbage,
s.listen, s.listen,
} { } {
foo := foo foo := foo
@@ -62,10 +63,10 @@ func (s S) init(ctx context.Context) error {
, addr TEXT NOT NULL UNIQUE , addr TEXT NOT NULL UNIQUE
)`, )`,
`CREATE TABLE IF NOT EXISTS "pinger_pings" ( `CREATE TABLE IF NOT EXISTS "pinger_pings" (
start TIMESTAMP NOT NULL start TIMESTAMP NOT NULL
, ms NUMBER NOT NULL , ms NUMBER NOT NULL
, ok BOOLEAN NOT NULL DEFAULT false , ok BOOLEAN NOT NULL DEFAULT false
, to_id NUMBER , to_id NUMBER
, FOREIGN KEY (to_id) REFERENCES "pinger_to"(id) , FOREIGN KEY (to_id) REFERENCES "pinger_to"(id)
)`, )`,
//`ALTER TABLE "pinger_pings" SET UNLOGGED`, //`ALTER TABLE "pinger_pings" SET UNLOGGED`,
@@ -141,6 +142,32 @@ func (s S) listen(ctx context.Context) error {
return nil return nil
} }
func (s S) collectGarbage(ctx context.Context) error {
c := time.NewTicker(time.Hour)
defer c.Stop()
for {
select {
case <-c.C:
case <-ctx.Done():
return nil
}
if _, err := s.ExecContext(ctx, `
DELETE FROM "pinger_pings"
WHERE
start < $1
AND (
ms < 100
OR ok
)
`, time.Now().Add(-1*2*24*time.Hour).Unix()); err != nil {
log.Println("!", err)
}
}
return nil
}
func (s S) pingAndRecord(ctx context.Context) error { func (s S) pingAndRecord(ctx context.Context) error {
ctx, can := context.WithCancel(ctx) ctx, can := context.WithCancel(ctx)
defer can() defer can()
@@ -183,11 +210,11 @@ func (s S) pingAndRecord(ctx context.Context) error {
go func() { go func() {
for record := range records { for record := range records {
if _, err := s.ExecContext(ctx, ` if _, err := s.ExecContext(ctx, `
INSERT INTO "pinger_pings" INSERT INTO "pinger_pings"
(start, ms, ok, to_id) (start, ms, ok, to_id)
VALUES VALUES
($1, $2, $3, $4) ($1, $2, $3, $4)
`, record.start, record.ms.Milliseconds(), record.ok, toId); err != nil { `, record.start.Unix(), record.ms.Milliseconds(), record.ok, toId); err != nil {
log.Println("!", err) log.Println("!", err)
} }
} }
@@ -224,6 +251,8 @@ func (s S) pingAndRecord(ctx context.Context) error {
} }
if err == nil { if err == nil {
conn.Close() conn.Close()
} else {
log.Println("!", err)
} }
}() }()
} }