dashboard

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dashboard serves a local, self-hosted web view of a Litescope fleet.

It is intentionally dependency-free: the frontend is a single embedded HTML file (no build step, no node_modules) and the server is the Go standard library. It runs on the operator's own machine or server — no cloud, no outbound telemetry. The hosted, multi-user, org-scoped dashboard is a separate Enterprise offering; this one is free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutopilotAction

type AutopilotAction struct {
	Kind   string `json:"kind"` // analyze | optimize | vacuum | create-index | drop-index
	Risk   string `json:"risk"` // safe | risky
	Table  string `json:"table,omitempty"`
	SQL    string `json:"sql,omitempty"` // the statement autopilot would run (empty = guidance only)
	Reason string `json:"reason"`        // plain-language explanation
}

AutopilotAction is one optimization step autopilot would take (mirrors autopilot.Action). Risk is "safe" (auto-applied) or "risky" (needs review).

type AutopilotFn

type AutopilotFn func(dbName string) (*AutopilotPlan, error)

AutopilotFn builds the autopilot plan for the named database. The CLI supplies it so this package stays decoupled from DSN resolution; when nil, the panel hides.

type AutopilotPlan

type AutopilotPlan struct {
	Source  string            `json:"source"`
	Actions []AutopilotAction `json:"actions"`
	Safe    int               `json:"safe"`    // count of safe (auto-applied) actions
	Risky   int               `json:"risky"`   // count of risky (review-first) actions
	Queries int               `json:"queries"` // observed queries fed to the advisor
}

AutopilotPlan is the DBA self-driving moat's verdict for one database: the set of maintenance and indexing actions it would take, surfaced read-only so the operator can see the plan before applying it from the CLI. Queries records how many observed SQL console queries fed the EXPLAIN-based index advice.

type BackupReport

type BackupReport struct {
	Source    string         `json:"source"`
	Snapshots []SnapshotInfo `json:"snapshots"`
}

BackupReport is the snapshot history for one database — the file-superpower moat (point-in-time backups) surfaced in the dashboard.

type BrowseFn

type BrowseFn func(dbName, table, orderBy, dir string, limit, offset int) (*BrowseResult, error)

BrowseFn returns one paginated, optionally sorted page of a table. The CLI supplies it; it validates the table and sort column to prevent injection.

type BrowseResult

type BrowseResult struct {
	Columns []string `json:"columns"`
	Rows    [][]any  `json:"rows"`
	Total   int64    `json:"total"`
	Offset  int      `json:"offset"`
	Limit   int      `json:"limit"`
	OrderBy string   `json:"order_by,omitempty"`
	Dir     string   `json:"dir,omitempty"`
}

BrowseResult is one page of a table, with server-side sorting and the total row count so the dashboard can paginate.

type CreateSnapshotFn

type CreateSnapshotFn func(dbName, label string) (*SnapshotInfo, error)

CreateSnapshotFn takes a new snapshot of the named database with an optional label and returns the created snapshot.

type DiffColumnChange

type DiffColumnChange struct {
	Name    string `json:"name"`
	OldType string `json:"old_type,omitempty"`
	NewType string `json:"new_type,omitempty"`
}

DiffColumnChange records a column whose definition changed between two databases.

type DiffData

type DiffData struct {
	Table   string `json:"table"`
	Added   int64  `json:"added"`
	Removed int64  `json:"removed"`
	Changed int64  `json:"changed"`
}

DiffData is the row-count delta for one table between the two databases.

type DiffFn

type DiffFn func(oldDB, newDB string) (*DiffResult, error)

DiffFn compares two databases by fleet name (old → new) and returns the curated diff. The CLI supplies it so this package stays decoupled from DSN resolution and the diff engine; when nil, the diff panel is disabled.

type DiffResult

type DiffResult struct {
	Old         string      `json:"old"`
	New         string      `json:"new"`
	Schema      []DiffTable `json:"schema"`
	Data        []DiffData  `json:"data"`
	Identical   bool        `json:"identical"`
	DataSkipped bool        `json:"data_skipped"` // true for remote sources (schema-only)
}

DiffResult is the full comparison rendered in the dashboard's diff panel — "see what changes before you apply it".

type DiffTable

type DiffTable struct {
	Name           string             `json:"name"`
	Status         string             `json:"status"`
	AddedColumns   []string           `json:"added_columns,omitempty"`
	RemovedColumns []string           `json:"removed_columns,omitempty"`
	ChangedColumns []DiffColumnChange `json:"changed_columns,omitempty"`
	AddedIndexes   []string           `json:"added_indexes,omitempty"`
	RemovedIndexes []string           `json:"removed_indexes,omitempty"`
}

DiffTable is one table's worth of schema change between the old and new database. Status is "added", "removed", or "changed".

type History

type History struct {
	// contains filtered or unexported fields
}

History persists fleet-health snapshots to a local SQLite file. The store is itself a SQLite database — the monitoring history of a SQLite tool lives in a SQLite file, no external time-series infrastructure required. It is safe for concurrent use.

func OpenHistory

func OpenHistory(path string) (*History, error)

OpenHistory opens (creating if needed) the SQLite history store at path.

func (*History) Close

func (h *History) Close() error

Close releases the underlying database.

func (*History) Record

func (h *History) Record(ov *Overview) error

Record stores a snapshot derived from the overview. It is best-effort and rate-limited by minSampleGap; callers may ignore the returned error.

func (*History) Series

func (h *History) Series(sinceMs int64) ([]Sample, error)

Series returns samples with ts >= sinceMs (0 for all), oldest first.

type ImportFn

type ImportFn func(filename string, data io.Reader) (summary string, err error)

ImportFn ingests an uploaded data file (CSV/TSV/JSON) and returns a short human summary (e.g. the new table name). The CLI supplies it so this package stays decoupled from the importer; when nil, drag-drop import is disabled.

type LockFinding

type LockFinding struct {
	Severity string `json:"severity"` // "ok" | "warning" | "critical"
	Rule     string `json:"rule"`
	Summary  string `json:"summary"`
	Detail   string `json:"detail"`
	Fix      string `json:"fix"`
}

LockFinding is one static lock-configuration issue (mirrors locks.Finding).

type LockHolder

type LockHolder struct {
	PID     int    `json:"pid"`
	Command string `json:"command"`
	Access  string `json:"access"`
}

LockHolder is a process holding the database file open (mirrors locks.Holder).

type LockReport

type LockReport struct {
	Source     string            `json:"source"`
	Provider   string            `json:"provider"` // "local" | "d1" | "turso"
	Verdict    string            `json:"verdict"`  // "ok" | "attention" | "critical"
	Pragmas    map[string]string `json:"pragmas,omitempty"`
	WALBytes   int64             `json:"wal_bytes"`
	Findings   []LockFinding     `json:"findings"`
	LiveState  string            `json:"live_state,omitempty"` // "free" | "locked" | "readable" | "error"
	LiveDetail string            `json:"live_detail,omitempty"`
	WaitMS     int64             `json:"wait_ms,omitempty"`
	Holders    []LockHolder      `json:"holders,omitempty"`
	Hint       string            `json:"hint,omitempty"`
}

LockReport is the lock doctor's verdict for one database — static PRAGMA diagnosis plus, for local files, a live probe of who holds the lock right now.

type LocksFn

type LocksFn func(dbName string) (*LockReport, error)

LocksFn diagnoses lock health for the named database. The CLI supplies it so this package stays decoupled from DSN resolution; when nil, the panel hides.

type Overview

type Overview struct {
	FleetName   string                   `json:"fleet_name"`
	Total       int                      `json:"total"`
	Preview     bool                     `json:"preview"`     // true when a Free preview cap is in effect
	PreviewCap  int                      `json:"preview_cap"` // databases shown under the cap
	FullTotal   int                      `json:"full_total"`  // databases the fleet actually contains
	Health      *fleet.HealthReport      `json:"health"`
	Fingerprint *fleet.FingerprintReport `json:"fingerprint"`
	GeneratedAt time.Time                `json:"generated_at"`
}

Overview is the payload the dashboard renders. It is recomputed on each request so the browser always reflects the current state of the fleet.

type Provider

type Provider func() (*Overview, error)

Provider computes a fresh Overview. The CLI supplies this so the dashboard package stays decoupled from license gating and config loading.

type QueryFn

type QueryFn func(dbName, sql string) (*QueryResult, error)

QueryFn runs a read-only SQL query against the named database. Read-only safety is enforced by the CLI at the engine level (mode=ro + query_only).

type QueryResult

type QueryResult struct {
	Columns    []string `json:"columns"`
	Rows       [][]any  `json:"rows"`
	Truncated  bool     `json:"truncated"`
	DurationMs int64    `json:"duration_ms"`
}

QueryResult is the outcome of a read-only SQL query against one database.

type RestoreSnapshotFn

type RestoreSnapshotFn func(dbName, snapshotPath string) error

RestoreSnapshotFn overwrites the named database with one of its snapshots (identified by path). A safety snapshot of the current state is taken first.

type RewindFn

type RewindFn func(dbName, to string) (*RewindResult, error)

RewindFn restores the named database to the given point in time (RFC 3339 or a human form like "2h ago"). Destructive — the CLI supplies it only for D1 sources, which is why it lives alongside TimeTravelFn rather than the local backup panel's RestoreSnapshotFn.

type RewindResult

type RewindResult struct {
	Bookmark  string `json:"bookmark"`
	Timestamp string `json:"timestamp"`
}

RewindResult is the outcome of a Time Travel restore (mirrors connector.D1TimeTravelResult, kept local so this package stays decoupled from the D1 connector).

type Sample

type Sample struct {
	TS        int64 `json:"ts"` // unix milliseconds
	Total     int   `json:"total"`
	OK        int   `json:"ok"`
	Warning   int   `json:"warning"`
	Critical  int   `json:"critical"`
	SizeBytes int64 `json:"size_bytes"`
}

Sample is one point on the fleet's health timeline.

type SchemaColumn

type SchemaColumn struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	PK    bool   `json:"pk"`
	FK    bool   `json:"fk"`
	Drift string `json:"drift,omitempty"`
}

SchemaColumn is one column in an ERD table node. Drift, when set, marks how the column deviates from the fleet's canonical schema: "added" (present here, absent in canonical), "changed" (type/not-null differs), or "missing" (present in canonical, absent here).

type SchemaEdge

type SchemaEdge struct {
	From   string `json:"from"`   // table holding the foreign key
	To     string `json:"to"`     // referenced table
	Column string `json:"column"` // column in From that references To
}

SchemaEdge is a foreign-key relationship between two tables.

type SchemaFingerprint

type SchemaFingerprint struct {
	ClusterID    string `json:"cluster_id"`
	IsCanonical  bool   `json:"is_canonical"`
	CanonicalID  string `json:"canonical_id"`
	ClusterCount int    `json:"cluster_count"` // databases sharing this exact schema
	FleetTotal   int    `json:"fleet_total"`   // databases fingerprinted
	DriftTables  int    `json:"drift_tables"`  // tables differing from canonical
	DriftColumns int    `json:"drift_columns"` // columns differing from canonical
}

SchemaFingerprint places one database's ERD in the context of the whole fleet: which schema cluster it belongs to and how far it has drifted from canonical.

type SchemaFn

type SchemaFn func(dbName string) (*SchemaGraph, error)

SchemaFn returns the ERD graph of the named database. The CLI supplies it so this package stays decoupled from schema loading; when nil, the ERD is disabled.

type SchemaGraph

type SchemaGraph struct {
	Tables      []SchemaTable      `json:"tables"`
	Edges       []SchemaEdge       `json:"edges"`
	Fingerprint *SchemaFingerprint `json:"fingerprint,omitempty"` // fleet drift overlay
}

SchemaGraph is the entity-relationship graph of one database, rendered as an interactive ERD in the dashboard.

type SchemaTable

type SchemaTable struct {
	Name    string         `json:"name"`
	Columns []SchemaColumn `json:"columns"`
	Drift   string         `json:"drift,omitempty"`
	Ghost   bool           `json:"ghost,omitempty"`
}

SchemaTable is one entity (table) in the ERD. Drift "added" marks a table present here but absent from canonical; Ghost marks a table present in canonical but missing here (rendered as a placeholder).

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves the embedded dashboard and its JSON API.

func New

func New(provider Provider) *Server

New builds a dashboard server backed by the given provider.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler (useful for tests and custom hosting).

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the dashboard on addr (e.g. "127.0.0.1:7575").

func (*Server) SetAutopilot

func (s *Server) SetAutopilot(fn AutopilotFn)

SetAutopilot enables the DBA autopilot panel (read-only plan preview).

func (*Server) SetBackup

func (s *Server) SetBackup(list SnapshotsFn, create CreateSnapshotFn, restore RestoreSnapshotFn)

SetBackup enables the snapshot/restore (backup) panel. list is required; create and restore enable the respective actions when non-nil.

func (*Server) SetDataBrowser

func (s *Server) SetDataBrowser(tables TablesFn, query QueryFn)

SetDataBrowser enables the read-only data browser and SQL console.

func (*Server) SetDiffProvider

func (s *Server) SetDiffProvider(fn DiffFn)

SetDiffProvider enables the visual schema/data diff panel.

func (*Server) SetHistory

func (s *Server) SetHistory(h *History)

SetHistory enables the fleet-health timeline, persisting a snapshot on each overview request to the given store.

func (*Server) SetImportHandler

func (s *Server) SetImportHandler(fn ImportFn)

SetImportHandler enables drag-drop import in the dashboard.

func (*Server) SetLockDoctor

func (s *Server) SetLockDoctor(fn LocksFn)

SetLockDoctor enables the lock doctor panel.

func (*Server) SetSchemaProvider

func (s *Server) SetSchemaProvider(fn SchemaFn)

SetSchemaProvider enables the interactive ERD.

func (*Server) SetTableBrowser

func (s *Server) SetTableBrowser(fn BrowseFn)

SetTableBrowser enables paginated, sortable table browsing.

func (*Server) SetTimeTravel

func (s *Server) SetTimeTravel(info TimeTravelFn, rewind RewindFn)

SetTimeTravel enables the D1 Time Travel panel (window info + restore). info is required; rewind enables the restore action when non-nil.

type SnapshotInfo

type SnapshotInfo struct {
	Path      string    `json:"path"`
	Label     string    `json:"label,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	SizeBytes int64     `json:"size_bytes"`
}

SnapshotInfo is one stored point-in-time backup (mirrors snapshot.Snapshot).

type SnapshotsFn

type SnapshotsFn func(dbName string) (*BackupReport, error)

SnapshotsFn lists the snapshots of the named database. The CLI supplies it so this package stays decoupled from DSN resolution; when nil, the panel hides.

type TableInfo

type TableInfo struct {
	Name string `json:"name"`
	Rows int64  `json:"rows"`
}

TableInfo describes one table available for browsing in a database.

type TablesFn

type TablesFn func(dbName string) ([]TableInfo, error)

TablesFn lists the browsable tables of the named database. The CLI supplies it so this package stays decoupled from DSN resolution; when nil, the data browser is disabled.

type TimeTravelFn

type TimeTravelFn func(dbName string) (*TimeTravelInfo, error)

TimeTravelFn reports the Time Travel window for the named database. The CLI supplies it and rejects non-D1 sources; when nil, the panel hides.

type TimeTravelInfo

type TimeTravelInfo struct {
	Source string    `json:"source"`
	Oldest time.Time `json:"oldest"`
	Now    time.Time `json:"now"`
}

TimeTravelInfo describes the Cloudflare D1 Time Travel window for one database — the file-superpower moat's D1-native counterpart to local snapshots (D1 keeps 30 days of continuous history, no local backup needed).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL