mirror of
https://github.com/henrygd/beszel.git
synced 2026-04-21 04:01:50 +02:00
updates
This commit is contained in:
@@ -8,8 +8,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/henrygd/beszel/internal/entities/probe"
|
||||
"log/slog"
|
||||
|
||||
"github.com/henrygd/beszel/internal/entities/probe"
|
||||
)
|
||||
|
||||
// ProbeManager manages network probe tasks.
|
||||
@@ -33,7 +34,7 @@ type probeSample struct {
|
||||
|
||||
func newProbeManager() *ProbeManager {
|
||||
return &ProbeManager{
|
||||
probes: make(map[string]*probeTask),
|
||||
probes: make(map[string]*probeTask),
|
||||
httpClient: &http.Client{Timeout: 10 * time.Second},
|
||||
}
|
||||
}
|
||||
@@ -145,8 +146,7 @@ func (pm *ProbeManager) runProbe(task *probeTask) {
|
||||
if interval < time.Second {
|
||||
interval = 10 * time.Second
|
||||
}
|
||||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
ticker := time.Tick(interval)
|
||||
|
||||
// Run immediately on start
|
||||
pm.executeProbe(task)
|
||||
@@ -155,7 +155,7 @@ func (pm *ProbeManager) runProbe(task *probeTask) {
|
||||
select {
|
||||
case <-task.cancel:
|
||||
return
|
||||
case <-ticker.C:
|
||||
case <-ticker:
|
||||
pm.executeProbe(task)
|
||||
}
|
||||
}
|
||||
@@ -185,8 +185,8 @@ func (pm *ProbeManager) executeProbe(task *probeTask) {
|
||||
// Trim old samples beyond 120s to bound memory
|
||||
cutoff := time.Now().Add(-120 * time.Second)
|
||||
start := 0
|
||||
for i, s := range task.samples {
|
||||
if s.timestamp.After(cutoff) {
|
||||
for i := range task.samples {
|
||||
if task.samples[i].timestamp.After(cutoff) {
|
||||
start = i
|
||||
break
|
||||
}
|
||||
@@ -195,7 +195,8 @@ func (pm *ProbeManager) executeProbe(task *probeTask) {
|
||||
}
|
||||
}
|
||||
if start > 0 {
|
||||
task.samples = task.samples[start:]
|
||||
size := copy(task.samples, task.samples[start:])
|
||||
task.samples = task.samples[:size]
|
||||
}
|
||||
task.samples = append(task.samples, sample)
|
||||
task.mu.Unlock()
|
||||
|
||||
@@ -24,10 +24,10 @@ var pingTimeRegex = regexp.MustCompile(`time[=<]([\d.]+)\s*ms`)
|
||||
type icmpMethod int
|
||||
|
||||
const (
|
||||
icmpUntried icmpMethod = iota // haven't tried yet
|
||||
icmpRaw // privileged raw socket (ip4:icmp)
|
||||
icmpDatagram // unprivileged datagram socket (udp4)
|
||||
icmpExecFallback // shell out to system ping command
|
||||
icmpUntried icmpMethod = iota // haven't tried yet
|
||||
icmpRaw // privileged raw socket (ip4:icmp)
|
||||
icmpDatagram // unprivileged datagram socket (udp4)
|
||||
icmpExecFallback // shell out to system ping command
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -17,13 +17,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { PlusIcon } from "lucide-react"
|
||||
import { useToast } from "@/components/ui/use-toast"
|
||||
|
||||
export function AddProbeDialog({
|
||||
systemId,
|
||||
onCreated,
|
||||
}: {
|
||||
systemId: string
|
||||
onCreated: () => void
|
||||
}) {
|
||||
export function AddProbeDialog({ systemId, onCreated }: { systemId: string; onCreated: () => void }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [protocol, setProtocol] = useState<string>("icmp")
|
||||
const [target, setTarget] = useState("")
|
||||
@@ -60,8 +54,8 @@ export function AddProbeDialog({
|
||||
resetForm()
|
||||
setOpen(false)
|
||||
onCreated()
|
||||
} catch (err: any) {
|
||||
toast({ variant: "destructive", title: t`Error`, description: err?.message })
|
||||
} catch (err: unknown) {
|
||||
toast({ variant: "destructive", title: t`Error`, description: (err as Error)?.message })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
@@ -85,6 +79,17 @@ export function AddProbeDialog({
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit} className="grid gap-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
<Trans>Target</Trans>
|
||||
</Label>
|
||||
<Input
|
||||
value={target}
|
||||
onChange={(e) => setTarget(e.target.value)}
|
||||
placeholder={protocol === "http" ? "https://example.com" : "1.1.1.1"}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
<Trans>Protocol</Trans>
|
||||
@@ -100,17 +105,6 @@ export function AddProbeDialog({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
<Trans>Target</Trans>
|
||||
</Label>
|
||||
<Input
|
||||
value={target}
|
||||
onChange={(e) => setTarget(e.target.value)}
|
||||
placeholder={protocol === "http" ? "https://example.com" : "1.1.1.1"}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{protocol === "tcp" && (
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
@@ -147,7 +141,7 @@ export function AddProbeDialog({
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder={t`e.g. Cloudflare DNS`}
|
||||
placeholder={target || t`e.g. Cloudflare DNS`}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
|
||||
Reference in New Issue
Block a user