mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
cron / timer updates
This commit is contained in:
19
hub/main.go
19
hub/main.go
@@ -67,12 +67,11 @@ func main() {
|
||||
return err
|
||||
}
|
||||
usersAuthOptions := usersCollection.AuthOptions()
|
||||
usersAuthOptions.AllowUsernameAuth = false
|
||||
if os.Getenv("DISABLE_PASSWORD_AUTH") == "true" {
|
||||
usersAuthOptions.AllowEmailAuth = false
|
||||
usersAuthOptions.AllowUsernameAuth = false
|
||||
} else {
|
||||
usersAuthOptions.AllowEmailAuth = true
|
||||
usersAuthOptions.AllowUsernameAuth = true
|
||||
}
|
||||
usersCollection.SetOptions(usersAuthOptions)
|
||||
if err := app.Dao().SaveCollection(usersCollection); err != nil {
|
||||
@@ -99,11 +98,13 @@ func main() {
|
||||
return nil
|
||||
})
|
||||
|
||||
// set up cron jobs
|
||||
// set up cron jobs / ticker for system updates
|
||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
// 15 second ticker for system updates
|
||||
go startSystemUpdateTicker()
|
||||
// cron job to delete old records
|
||||
scheduler := cron.New()
|
||||
// delete records that are older than the display period
|
||||
scheduler.MustAdd("delete old records", "8 */2 * * *", func() {
|
||||
scheduler.MustAdd("delete old records", "8 * * * *", func() {
|
||||
deleteOldRecords("system_stats", "1m", time.Hour)
|
||||
deleteOldRecords("container_stats", "1m", time.Hour)
|
||||
deleteOldRecords("system_stats", "10m", 12*time.Hour)
|
||||
@@ -151,12 +152,6 @@ func main() {
|
||||
return nil
|
||||
})
|
||||
|
||||
// start ticker for server updates
|
||||
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
|
||||
go serverUpdateTicker()
|
||||
return nil
|
||||
})
|
||||
|
||||
// immediately create connection for new servers
|
||||
app.OnModelAfterCreate("systems").Add(func(e *core.ModelEvent) error {
|
||||
go updateSystem(e.Model.(*models.Record))
|
||||
@@ -206,7 +201,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func serverUpdateTicker() {
|
||||
func startSystemUpdateTicker() {
|
||||
ticker := time.NewTicker(15 * time.Second)
|
||||
for range ticker.C {
|
||||
updateSystems()
|
||||
|
@@ -140,11 +140,10 @@ func twoDecimals(value float64) float64 {
|
||||
|
||||
/* Delete records of specified collection and type that are older than timeLimit */
|
||||
func deleteOldRecords(collection string, recordType string, timeLimit time.Duration) {
|
||||
// log.Println("Deleting old", recordType, "records...")
|
||||
timeLimitStamp := time.Now().UTC().Add(timeLimit).Format("2006-01-02 15:04:05")
|
||||
timeLimitStamp := time.Now().UTC().Add(-timeLimit).Format("2006-01-02 15:04:05")
|
||||
records, _ := app.Dao().FindRecordsByExpr(collection,
|
||||
dbx.NewExp("type = {:type}", dbx.Params{"type": recordType}),
|
||||
dbx.NewExp("created > {:created}", dbx.Params{"created": timeLimitStamp}),
|
||||
dbx.NewExp("created < {:created}", dbx.Params{"created": timeLimitStamp}),
|
||||
)
|
||||
for _, record := range records {
|
||||
if err := app.Dao().DeleteRecord(record); err != nil {
|
||||
|
@@ -30,7 +30,7 @@ Beszel has two components: the hub and the agent.
|
||||
|
||||
The hub is a web application, built on top of [PocketBase](https://pocketbase.io/), that provides a dashboard to view and manage your connected systems.
|
||||
|
||||
The agent runs on each system you want to monitor. It provides a minimal SSH server through which it communicates system information to the hub.
|
||||
The agent runs on each system you want to monitor. It creates a minimal SSH server through which it communicates system metrics to the hub.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -133,7 +133,7 @@ The agent's SSH server is configured to accept connections only using this key.
|
||||
|
||||
### Agent is not connecting
|
||||
|
||||
Assuming the agent is running, the connection is probably being blocked by a firewall. You should add an inbound rule to allow TCP connections to the port. Check any active firewalls on the agent system, like iptables or ufw, and in your cloud provider account if applicable.
|
||||
Assuming the agent is running, the connection is probably being blocked by a firewall. You need to add an inbound rule on the agent system to allow TCP connections to the port. Check any active firewalls, like iptables or ufw, and in your cloud provider account if applicable.
|
||||
|
||||
Connectivity can be tested by running `telnet <agent-ip> <port>` or `nc -zv <agent-ip> <port>` from a remote machine.
|
||||
|
||||
|
Reference in New Issue
Block a user