aboutsummaryrefslogtreecommitdiff
path: root/internal/monitor/database.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-20 17:16:22 -0800
committerFuwn <[email protected]>2026-01-20 17:16:22 -0800
commit2371b28128213fbcc8d1c062dccc3074e6b0fa98 (patch)
tree84452dbf5f2b1821d1fc5cf8ecdb0a5ad2b74f56 /internal/monitor/database.go
parentfix: Use wildcard path for badge endpoint to support .svg extension (diff)
downloadkaze-2371b28128213fbcc8d1c062dccc3074e6b0fa98.tar.xz
kaze-2371b28128213fbcc8d1c062dccc3074e6b0fa98.zip
feat: Use composite group/name key for monitor identification
Previously monitors were identified by just their name, causing monitors with the same name in different groups to share data in the database. Changes: - Add ID() method to MonitorConfig returning 'group/name' format - Add Group field to MonitorConfig (set at runtime) - Update Monitor interface with ID() and Group() methods - Update all monitor implementations (http, tcp, dns, icmp, gemini, graphql, database) to use composite ID - Update Scheduler to use monitor ID instead of name - Update server handlers to use composite ID for stats lookups - Change API routes to use {group}/{name} pattern: - /api/monitor/{group}/{name} - /api/history/{group}/{name} - /api/uptime/{group}/{name} - /api/badge/{group}/{name}.svg - URL-encode group and name components to handle special characters (e.g., slashes in names become %2F) - Update config.UpdateResetFlag to accept group and name separately BREAKING: API endpoints now require group in the path. Existing database data using just monitor names won't be associated with the new composite keys.
Diffstat (limited to 'internal/monitor/database.go')
-rw-r--r--internal/monitor/database.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/monitor/database.go b/internal/monitor/database.go
index 0b4d2a9..3301632 100644
--- a/internal/monitor/database.go
+++ b/internal/monitor/database.go
@@ -14,7 +14,9 @@ import (
// DatabaseMonitor monitors database connections
type DatabaseMonitor struct {
+ id string
name string
+ group string
target string // Connection string or host:port
dbType string // postgres, mysql, redis, mongodb, sqlite
interval time.Duration
@@ -48,7 +50,9 @@ func NewDatabaseMonitor(cfg config.MonitorConfig) (*DatabaseMonitor, error) {
}
return &DatabaseMonitor{
+ id: cfg.ID(),
name: cfg.Name,
+ group: cfg.Group,
target: cfg.Target,
dbType: dbType,
interval: cfg.Interval.Duration,
@@ -59,11 +63,21 @@ func NewDatabaseMonitor(cfg config.MonitorConfig) (*DatabaseMonitor, error) {
}, nil
}
+// ID returns the unique identifier for this monitor
+func (m *DatabaseMonitor) ID() string {
+ return m.id
+}
+
// Name returns the monitor's name
func (m *DatabaseMonitor) Name() string {
return m.name
}
+// Group returns the group this monitor belongs to
+func (m *DatabaseMonitor) Group() string {
+ return m.group
+}
+
// Type returns the monitor type
func (m *DatabaseMonitor) Type() string {
return "database"
@@ -102,7 +116,7 @@ func (m *DatabaseMonitor) RoundUptime() bool {
// Check performs the database connection check
func (m *DatabaseMonitor) Check(ctx context.Context) *Result {
result := &Result{
- MonitorName: m.name,
+ MonitorName: m.id,
Timestamp: time.Now(),
}