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