monitor

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Background colors
	BaseBackground   = lipgloss.AdaptiveColor{Light: "#f8f8f2", Dark: "#1e1e2e"} // Main background
	PanelBackground  = lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#313244"} // Panel backgrounds
	AltRowBackground = lipgloss.AdaptiveColor{Light: "#eff0eb", Dark: "#45475a"} // Alternate row

	// Text colors
	PrimaryText   = lipgloss.AdaptiveColor{Light: "#282a36", Dark: "#cdd6f4"} // Main text
	SecondaryText = lipgloss.AdaptiveColor{Light: "#6272a4", Dark: "#a6adc8"} // Secondary/muted
	HeaderText    = lipgloss.AdaptiveColor{Light: "#bd93f9", Dark: "#cba6f7"} // Headers

	// Accent colors
	SelectionAccent = lipgloss.AdaptiveColor{Light: "#8be9fd", Dark: "#89b4fa"} // Selected items
	BorderColor     = lipgloss.AdaptiveColor{Light: "#44475a", Dark: "#585b70"} // Borders

	// Status colors
	SuccessColor = lipgloss.AdaptiveColor{Light: "#2e7d32", Dark: "#a6e3a1"} // Running/success
	ErrorColor   = lipgloss.AdaptiveColor{Light: "#c62828", Dark: "#f38ba8"} // Errors
	WarningColor = lipgloss.AdaptiveColor{Light: "#e65100", Dark: "#fab387"} // Warnings
	InfoColor    = lipgloss.AdaptiveColor{Light: "#1565c0", Dark: "#89b4fa"} // Info
	DebugColor   = lipgloss.AdaptiveColor{Light: "#546e7a", Dark: "#6c7086"} // Debug
	TraceColor   = lipgloss.AdaptiveColor{Light: "#7b1fa2", Dark: "#f5c2e7"} // Trace
	VerboseColor = lipgloss.AdaptiveColor{Light: "#00796b", Dark: "#94e2d5"} // Verbose

	// Semantic color aliases (for clarity in usage)
	PrimaryAccent       = SelectionAccent // Cyan for selections
	SecondaryAccent     = HeaderText      // Purple for headers
	MutedColor          = SecondaryText   // Medium gray for muted text
	BackgroundColor     = BaseBackground  // Main background
	StatusBarBackground = BaseBackground  // Same as main (no dark bar)
	SelectedBackground  = SelectionAccent // Cyan selection

	// Helper styles for rendering colored text
	MutedStyle   = lipgloss.NewStyle().Foreground(MutedColor)
	ErrorStyle   = lipgloss.NewStyle().Foreground(ErrorColor)
	SuccessStyle = lipgloss.NewStyle().Foreground(SuccessColor)
	AccentStyle  = lipgloss.NewStyle().Foreground(PrimaryAccent)

	// Flash animation styles
	FlashHighlightBg    = lipgloss.AdaptiveColor{Light: "#8be9fd", Dark: "#45475a"} // bright cyan / dark overlay
	FlashFadeBg         = lipgloss.AdaptiveColor{Light: "#e0f4fd", Dark: "#313244"} // light cyan / panel bg
	FlashHighlightStyle = lipgloss.NewStyle().Background(FlashHighlightBg).Bold(true).Foreground(PrimaryText)
	FlashFadeStyle      = lipgloss.NewStyle().Background(FlashFadeBg).Foreground(PrimaryText)

	// UI Component Styles
	BorderStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(BorderColor)

	ActiveTabStyle = lipgloss.NewStyle().
					Bold(true).
					Foreground(PrimaryText).
					Background(SelectionAccent).
					Padding(0, 1)

	InactiveTabStyle = lipgloss.NewStyle().
						Foreground(SecondaryText).
						Background(BackgroundColor).
						Padding(0, 1)

	TableHeaderStyle = lipgloss.NewStyle().
						Bold(true).
						Foreground(HeaderText).
						BorderStyle(lipgloss.NormalBorder()).
						BorderBottom(true).
						BorderForeground(BorderColor)

	TableRowStyle = lipgloss.NewStyle().
					Foreground(PrimaryText)

	TableRowAltStyle = lipgloss.NewStyle().
						Foreground(PrimaryText).
						Background(AltRowBackground)

	SelectedInstanceStyle = lipgloss.NewStyle().
							Bold(true).
							Foreground(PrimaryText).
							Background(SelectionAccent).
							Padding(0, 1)

	UnselectedInstanceStyle = lipgloss.NewStyle().
							Foreground(PrimaryText).
							Padding(0, 1)

	RunningIndicator  = lipgloss.NewStyle().Foreground(SuccessColor).SetString("●")
	StoppedIndicator  = lipgloss.NewStyle().Foreground(MutedColor).SetString("○")
	StatusBarStyle    = lipgloss.NewStyle().Foreground(SecondaryText).Background(StatusBarBackground).Padding(0, 1)
	ConsoleTitleStyle = lipgloss.NewStyle().Bold(true).Foreground(PrimaryAccent)

	LogLevelStyles = map[LogLevel]lipgloss.Style{
		LogLevelVerbs: lipgloss.NewStyle().Foreground(VerboseColor),
		LogLevelTrace: lipgloss.NewStyle().Foreground(TraceColor),
		LogLevelDebug: lipgloss.NewStyle().Foreground(DebugColor),
		LogLevelInfo:  lipgloss.NewStyle().Foreground(InfoColor),
		LogLevelWarn:  lipgloss.NewStyle().Foreground(WarningColor),
		LogLevelError: lipgloss.NewStyle().Foreground(ErrorColor),
		LogLevelFatal: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#880e4f", Dark: "#f38ba8"}).Bold(true),
	}
)

Base palette colors

View Source
var (

	// Box styles with dynamic width
	DynamicBoxStyle = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(BorderColor)

	// Table cell styles (using light theme palette)
	TableCellStyle = lipgloss.NewStyle().
					Foreground(PrimaryText) // #282a36 - dark text

	TableCellAltStyle = lipgloss.NewStyle().
						Foreground(PrimaryText).
						Background(AltRowBackground) // #eff0eb - light gray

	TableHeaderCellStyle = lipgloss.NewStyle().
							Bold(true).
							Foreground(HeaderText) // #bd93f9 - purple
)

Adaptive layout styles - Catppuccin Mocha Theme

Functions

This section is empty.

Types

type DateRange

type DateRange int

DateRange represents the selected time period

const (
	DateRangeToday DateRange = iota
	DateRangeWeek
	DateRangeMonth
	DateRangeYTD
	DateRangeTTM
)

func (DateRange) String

func (d DateRange) String() string

type ErrorMsg

type ErrorMsg struct {
	Error error
}

ErrorMsg is sent when an error occurs

type FlashTickMsg

type FlashTickMsg time.Time

FlashTickMsg is sent during flash animation frames

type InstanceInfo

type InstanceInfo struct {
	ID        string
	IsRunning bool
	StartTime time.Time
	LogPath   string
}

InstanceInfo represents an instance for the selector

type LogBuffer

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

LogBuffer is a thread-safe ring buffer for console logs

func NewLogBuffer

func NewLogBuffer(capacity int) *LogBuffer

NewLogBuffer creates a new log buffer with the given capacity

func (*LogBuffer) Append

func (lb *LogBuffer) Append(line LogLine)

Append adds a new log line to the buffer

func (*LogBuffer) Capacity

func (lb *LogBuffer) Capacity() int

Capacity returns the maximum capacity

func (*LogBuffer) Clear

func (lb *LogBuffer) Clear()

Clear resets the buffer

func (*LogBuffer) GetFilteredLines

func (lb *LogBuffer) GetFilteredLines(filters LogLevelSet) []LogLine

GetFilteredLines returns log lines that match the given filters

func (*LogBuffer) GetLines

func (lb *LogBuffer) GetLines() []LogLine

GetLines returns all log lines in order

func (*LogBuffer) GetLinesUnsafe

func (lb *LogBuffer) GetLinesUnsafe() []LogLine

GetLinesUnsafe returns lines without locking (caller must hold lock)

func (*LogBuffer) Size

func (lb *LogBuffer) Size() int

Size returns the current number of lines in the buffer

type LogLevel

type LogLevel int

LogLevel represents the log severity level

const (
	LogLevelVerbs LogLevel = 1 << iota
	LogLevelTrace
	LogLevelDebug
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal
)

type LogLevelSet

type LogLevelSet int

LogLevelSet is a bitmask of LogLevel values

type LogLine

type LogLine struct {
	Timestamp time.Time
	Level     LogLevel
	Message   string
	Raw       string
}

LogLine represents a parsed log line

type LogMsg

type LogMsg struct {
	Line string
}

LogMsg is sent when a log line is received

type LogTailer

type LogTailer struct {
	LogPath    string
	Filters    LogLevelSet
	BufferSize int
	// contains filtered or unexported fields
}

LogTailer tails a log file and sends lines through a channel

func (*LogTailer) Run

func (lt *LogTailer) Run(ctx context.Context, logChan chan<- string, errChan chan<- error)

Run tails the log file

func (*LogTailer) UpdateFilters

func (lt *LogTailer) UpdateFilters(filters LogLevelSet)

UpdateFilters safely updates log level filters

type MonitorModel

type MonitorModel struct {

	// Configuration
	RefreshInterval time.Duration
	DBPath          string

	// UI State
	SelectedDateRange DateRange
	SelectedInstance  string
	ConsoleLogEnabled bool
	ConsoleLogPaused  bool
	LogLevelFilters   LogLevelSet
	LastError         error

	// Data State
	Stats     *UsageStats
	Instances []InstanceInfo
	LogBuffer *LogBuffer

	// Channels (buffered)
	StatsChan chan *UsageStats
	LogChan   chan string
	ErrChan   chan error

	// Component state
	InstanceCursor int
	WindowSize     tea.WindowSizeMsg

	// Lifecycle
	Ctx    context.Context
	Cancel context.CancelFunc
	WG     sync.WaitGroup

	// Log tailer context (separate)
	LogCtx    context.Context
	LogCancel context.CancelFunc

	// Background workers
	StatsPoller *StatsPoller
	LogTailer   *LogTailer

	// Layout calculations (updated on window resize)
	LeftPanelWidth  int
	RightPanelWidth int
	RouteColWidth   int
	ModelColWidth   int
	// contains filtered or unexported fields
}

MonitorModel is the root Bubble Tea model

func NewMonitorModel

func NewMonitorModel(refreshInterval time.Duration, dbPath string) *MonitorModel

NewMonitorModel creates a new monitor model

func (*MonitorModel) Init

func (m *MonitorModel) Init() tea.Cmd

Init starts the background workers

func (*MonitorModel) Update

func (m *MonitorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages

func (*MonitorModel) View

func (m *MonitorModel) View() string

View renders the complete UI

type RecoveryMsg

type RecoveryMsg struct{}

RecoveryMsg is sent when the poller recovers from an error

type StatsPoller

type StatsPoller struct {
	Interval          time.Duration
	DBPath            string
	DateRange         DateRange
	InstanceID        string
	ConsecutiveErrors int
	// contains filtered or unexported fields
}

StatsPoller polls the database for usage stats

func (*StatsPoller) Run

func (sp *StatsPoller) Run(ctx context.Context, statsChan chan<- *UsageStats, errChan chan<- error)

Run executes the polling loop

func (*StatsPoller) UpdateDateRange

func (sp *StatsPoller) UpdateDateRange(dr DateRange)

UpdateDateRange safely updates the date range

func (*StatsPoller) UpdateInstance

func (sp *StatsPoller) UpdateInstance(instanceID string)

UpdateInstance safely updates the instance filter

type StatsUpdateMsg

type StatsUpdateMsg struct {
	Stats *UsageStats
}

StatsUpdateMsg is sent when stats are updated

type UsageStats

type UsageStats struct {
	Summary   usage.Summary
	ByRoute   map[string]*usage.RouteStats
	ByModel   map[string]*usage.ModelStats
	Timestamp time.Time
}

UsageStats represents aggregated usage data

Jump to

Keyboard shortcuts

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