mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Reapply "Merge branch 'canary' into kucherenko/canary"
This reverts commit e6cb6454db.
This commit is contained in:
47
apps/monitoring/database/db.go
Normal file
47
apps/monitoring/database/db.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type DB struct {
|
||||
*sql.DB
|
||||
}
|
||||
|
||||
func InitDB() (*DB, error) {
|
||||
db, err := sql.Open("sqlite3", "./monitoring.db")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create metrics table if it doesn't exist
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS server_metrics (
|
||||
timestamp TEXT PRIMARY KEY,
|
||||
cpu REAL,
|
||||
cpu_model TEXT,
|
||||
cpu_cores INTEGER,
|
||||
cpu_physical_cores INTEGER,
|
||||
cpu_speed REAL,
|
||||
os TEXT,
|
||||
distro TEXT,
|
||||
kernel TEXT,
|
||||
arch TEXT,
|
||||
mem_used REAL,
|
||||
mem_used_gb REAL,
|
||||
mem_total REAL,
|
||||
uptime INTEGER,
|
||||
disk_used REAL,
|
||||
total_disk REAL,
|
||||
network_in REAL,
|
||||
network_out REAL
|
||||
)
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DB{db}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user