console

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package console exposes the optional Runa console panel system.

Console intentionally centers on Panel objects collected by Registry rather than a single business Registry-only API because it is an aggregate UI layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MonitorStoreProvider

func MonitorStoreProvider(store MonitorStore) runaprovider.Provider

MonitorStoreProvider registers a custom monitor store.

func Mount

func Mount(target route.Target, app AppContext, configs ...Config)

Mount mounts console routes.

func MountPanels

func MountPanels(target route.Target, panels ...Panel)

MountPanels mounts extension panels under target.

func Provider

func Provider(options ...Option) runaprovider.Provider

Provider registers and optionally mounts console.

func Register

func Register(app AppContext, panels ...Panel)

Register adds panels to the app-scoped console registry.

func RegisterBuiltinSummaries

func RegisterBuiltinSummaries(app AppContext)

RegisterBuiltinSummaries adds built-in summary resolvers to the app-scoped registry once.

func RegisterSummary

func RegisterSummary(app AppContext, resolvers ...SummaryResolver)

RegisterSummary adds summary resolvers to the app-scoped console registry.

func Runtime

func Runtime(app AppContext) core.Map

Runtime returns current app runtime snapshots.

func State

func State(app AppContext) core.Map

State returns current app runtime snapshots.

Types

type AccessLog

type AccessLog struct {
	Time      time.Time     `json:"time"`
	RequestID string        `json:"request_id"`
	Method    string        `json:"method"`
	Path      string        `json:"path"`
	Route     string        `json:"route"`
	Status    int           `json:"status"`
	IP        string        `json:"ip"`
	Latency   time.Duration `json:"latency"`
	Slow      bool          `json:"slow"`
	Error     string        `json:"error,omitempty"`
	Source    string        `json:"source,omitempty"`
}

AccessLog describes one HTTP request captured by the console monitor.

type AppContext

type AppContext = runaprovider.Context

AppContext is the narrow application context used by console resolvers.

type Component

type Component struct {
	Name    string            `json:"name,omitempty"`
	Label   string            `json:"label,omitempty"`
	Type    ComponentType     `json:"type,omitempty"`
	Resolve ComponentResolver `json:"-"`
}

Component renders one data block in a console panel.

type ComponentInfo

type ComponentInfo struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Kind  string `json:"kind"`
	Data  any    `json:"data,omitempty"`
	Error string `json:"error,omitempty"`
}

ComponentInfo is the serializable component payload.

type ComponentPanel

type ComponentPanel struct {
	Name       string
	Title      string
	Icon       string
	Order      int
	Components []Component
}

ComponentPanel is an auto-rendered console panel configured by Go structs.

func (ComponentPanel) PanelConfig

func (panel ComponentPanel) PanelConfig() PanelConfig

PanelConfig returns panel metadata.

func (ComponentPanel) Routes

func (panel ComponentPanel) Routes(group *route.Group)

type ComponentResolver

type ComponentResolver func(context.Context, AppContext) (any, error)

ComponentResolver resolves component data for a console panel.

type ComponentType

type ComponentType string

ComponentType declares how a console component is rendered.

const (
	// ComponentMetric renders a compact stat value.
	ComponentMetric ComponentType = "metric"
	// ComponentStatus renders a status badge/card.
	ComponentStatus ComponentType = "status"
	// ComponentTable renders list-like data as a table.
	ComponentTable ComponentType = "table"
	// ComponentLine renders series data as a line chart.
	ComponentLine ComponentType = "line"
	// ComponentBar renders series data as a bar chart.
	ComponentBar ComponentType = "bar"
	// ComponentJSON renders data as formatted JSON.
	ComponentJSON ComponentType = "json"
)

type Config

type Config struct {
	Title          string        `toml:"title"`
	Mount          string        `toml:"mount"`
	Auth           []string      `toml:"auth"`
	Interval       time.Duration `toml:"interval"`
	SlowThreshold  time.Duration `toml:"slow_threshold"`
	CollectHTTP    bool          `toml:"collect_http"`
	SampleInterval time.Duration `toml:"sample_interval"`
	Panels         []Panel       `toml:"-"`
	Store          MonitorStore  `toml:"-"`
}

Config configures console.

type ErrorLog

type ErrorLog struct {
	Time      time.Time     `json:"time"`
	RequestID string        `json:"request_id"`
	Method    string        `json:"method"`
	Path      string        `json:"path"`
	Route     string        `json:"route"`
	Status    int           `json:"status"`
	Latency   time.Duration `json:"latency"`
	Error     string        `json:"error"`
	Source    string        `json:"source,omitempty"`
}

ErrorLog describes one failed request captured by the console monitor.

type JobLog

type JobLog struct {
	Time    time.Time     `json:"time"`
	Queue   string        `json:"queue"`
	Job     string        `json:"job"`
	Attempt int           `json:"attempt"`
	Latency time.Duration `json:"latency"`
	Bytes   int           `json:"bytes"`
	Error   string        `json:"error,omitempty"`
}

JobLog describes one queue job execution.

type JobStat

type JobStat struct {
	Queue    string        `json:"queue"`
	Job      string        `json:"job"`
	Count    int64         `json:"count"`
	Errors   int64         `json:"errors"`
	Avg      time.Duration `json:"avg"`
	Max      time.Duration `json:"max"`
	LastSeen time.Time     `json:"last_seen"`
}

JobStat aggregates queue job execution metrics.

type MemoryMonitorStore

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

MemoryMonitorStore stores recent monitor data in memory.

func NewMemoryMonitorStore

func NewMemoryMonitorStore(limit ...int) *MemoryMonitorStore

NewMemoryMonitorStore creates an in-memory monitor store.

func (*MemoryMonitorStore) AccessLogs

func (store *MemoryMonitorStore) AccessLogs(limit int) []AccessLog

func (*MemoryMonitorStore) ErrorLogs

func (store *MemoryMonitorStore) ErrorLogs(limit int) []ErrorLog

func (*MemoryMonitorStore) ErrorSeries

func (store *MemoryMonitorStore) ErrorSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) JobFailureSeries

func (store *MemoryMonitorStore) JobFailureSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) JobLatencySeries

func (store *MemoryMonitorStore) JobLatencySeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) JobLogs

func (store *MemoryMonitorStore) JobLogs(limit int) []JobLog

func (*MemoryMonitorStore) JobStats

func (store *MemoryMonitorStore) JobStats(limit int) []JobStat

func (*MemoryMonitorStore) LatencySeries

func (store *MemoryMonitorStore) LatencySeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) MessageConsumeSeries

func (store *MemoryMonitorStore) MessageConsumeSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) MessageErrorSeries

func (store *MemoryMonitorStore) MessageErrorSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) MessageLogs

func (store *MemoryMonitorStore) MessageLogs(limit int) []MessageLog

func (*MemoryMonitorStore) MessagePublishSeries

func (store *MemoryMonitorStore) MessagePublishSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) MessageStats

func (store *MemoryMonitorStore) MessageStats(limit int) []MessageStat

func (*MemoryMonitorStore) QueuePressureSeries

func (store *MemoryMonitorStore) QueuePressureSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) RPCErrorSeries

func (store *MemoryMonitorStore) RPCErrorSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) RPCLatencySeries

func (store *MemoryMonitorStore) RPCLatencySeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) RPCLogs

func (store *MemoryMonitorStore) RPCLogs(limit int) []RPCLog

func (*MemoryMonitorStore) RPCSeries

func (store *MemoryMonitorStore) RPCSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) RPCStats

func (store *MemoryMonitorStore) RPCStats(limit int) []RPCStat

func (*MemoryMonitorStore) RecordAccess

func (store *MemoryMonitorStore) RecordAccess(item AccessLog)

func (*MemoryMonitorStore) RecordJob

func (store *MemoryMonitorStore) RecordJob(item JobLog)

func (*MemoryMonitorStore) RecordMessage

func (store *MemoryMonitorStore) RecordMessage(item MessageLog)

func (*MemoryMonitorStore) RecordQueue

func (store *MemoryMonitorStore) RecordQueue(item QueueSample)

func (*MemoryMonitorStore) RecordRPC

func (store *MemoryMonitorStore) RecordRPC(item RPCLog)

func (*MemoryMonitorStore) RecordSQL

func (store *MemoryMonitorStore) RecordSQL(item database.SQLLog)

func (*MemoryMonitorStore) RecordWS

func (store *MemoryMonitorStore) RecordWS(item WSSample)

func (*MemoryMonitorStore) RouteStats

func (store *MemoryMonitorStore) RouteStats(limit int) []RouteStat

func (*MemoryMonitorStore) SQLErrorSeries

func (store *MemoryMonitorStore) SQLErrorSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) SQLLatencySeries

func (store *MemoryMonitorStore) SQLLatencySeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) SQLLogs

func (store *MemoryMonitorStore) SQLLogs(limit int) []database.SQLLog

func (*MemoryMonitorStore) SQLSeries

func (store *MemoryMonitorStore) SQLSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) SQLStats

func (store *MemoryMonitorStore) SQLStats(limit int) []SQLStat

func (*MemoryMonitorStore) SlowLogs

func (store *MemoryMonitorStore) SlowLogs(limit int) []AccessLog

func (*MemoryMonitorStore) StatusSeries

func (store *MemoryMonitorStore) StatusSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) TrafficSeries

func (store *MemoryMonitorStore) TrafficSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) WSMessageInSeries

func (store *MemoryMonitorStore) WSMessageInSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) WSMessageOutSeries

func (store *MemoryMonitorStore) WSMessageOutSeries(window time.Duration, points int) []MetricPoint

func (*MemoryMonitorStore) WSSamples

func (store *MemoryMonitorStore) WSSamples(limit int) []WSSample

func (*MemoryMonitorStore) WorkerThroughputSeries

func (store *MemoryMonitorStore) WorkerThroughputSeries(window time.Duration, points int) []MetricPoint

type MessageLog

type MessageLog struct {
	Time     time.Time     `json:"time"`
	Broker   string        `json:"broker"`
	Topic    string        `json:"topic"`
	Consumer string        `json:"consumer,omitempty"`
	Action   string        `json:"action"`
	Latency  time.Duration `json:"latency"`
	Bytes    int           `json:"bytes"`
	Error    string        `json:"error,omitempty"`
}

MessageLog describes one message broker operation.

type MessageStat

type MessageStat struct {
	Broker   string        `json:"broker"`
	Topic    string        `json:"topic"`
	Consumer string        `json:"consumer,omitempty"`
	Action   string        `json:"action"`
	Count    int64         `json:"count"`
	Errors   int64         `json:"errors"`
	Avg      time.Duration `json:"avg"`
	Max      time.Duration `json:"max"`
	LastSeen time.Time     `json:"last_seen"`
}

MessageStat aggregates message operations by broker/topic/action.

type MetricPoint

type MetricPoint struct {
	Label string  `json:"label"`
	Value float64 `json:"value"`
}

MetricPoint describes one chart point.

type MonitorStore

type MonitorStore interface {
	RecordAccess(AccessLog)
	RecordQueue(QueueSample)
	RecordJob(JobLog)
	RecordMessage(MessageLog)
	RecordRPC(RPCLog)
	RecordWS(WSSample)
	RecordSQL(database.SQLLog)
	AccessLogs(limit int) []AccessLog
	ErrorLogs(limit int) []ErrorLog
	SlowLogs(limit int) []AccessLog
	RouteStats(limit int) []RouteStat
	TrafficSeries(window time.Duration, points int) []MetricPoint
	ErrorSeries(window time.Duration, points int) []MetricPoint
	LatencySeries(window time.Duration, points int) []MetricPoint
	StatusSeries(window time.Duration, points int) []MetricPoint
	QueuePressureSeries(window time.Duration, points int) []MetricPoint
	WorkerThroughputSeries(window time.Duration, points int) []MetricPoint
	JobFailureSeries(window time.Duration, points int) []MetricPoint
	JobLogs(limit int) []JobLog
	JobStats(limit int) []JobStat
	JobLatencySeries(window time.Duration, points int) []MetricPoint
	MessageLogs(limit int) []MessageLog
	MessageStats(limit int) []MessageStat
	MessagePublishSeries(window time.Duration, points int) []MetricPoint
	MessageConsumeSeries(window time.Duration, points int) []MetricPoint
	MessageErrorSeries(window time.Duration, points int) []MetricPoint
	RPCLogs(limit int) []RPCLog
	RPCStats(limit int) []RPCStat
	RPCSeries(window time.Duration, points int) []MetricPoint
	RPCErrorSeries(window time.Duration, points int) []MetricPoint
	RPCLatencySeries(window time.Duration, points int) []MetricPoint
	WSSamples(limit int) []WSSample
	WSMessageInSeries(window time.Duration, points int) []MetricPoint
	WSMessageOutSeries(window time.Duration, points int) []MetricPoint
	SQLLogs(limit int) []database.SQLLog
	SQLStats(limit int) []SQLStat
	SQLSeries(window time.Duration, points int) []MetricPoint
	SQLErrorSeries(window time.Duration, points int) []MetricPoint
	SQLLatencySeries(window time.Duration, points int) []MetricPoint
}

MonitorStore stores console metrics and logs.

func MonitorStoreOf

func MonitorStoreOf(app AppContext) MonitorStore

MonitorStoreOf returns the app-scoped monitor store.

type Option

type Option func(*Config)

Option configures console provider.

func Auth

func Auth(names ...string) Option

Auth protects console routes with named Runa authenticators.

func CollectHTTP

func CollectHTTP(value bool) Option

CollectHTTP enables or disables console HTTP monitoring.

func Interval

func Interval(value time.Duration) Option

Interval sets frontend refresh interval.

func MountAt

func MountAt(path string) Option

MountAt sets provider auto mount path.

func Panels

func Panels(items ...Panel) Option

Panels registers console extension panels.

func SampleInterval

func SampleInterval(value time.Duration) Option

SampleInterval sets console background metric sampling interval.

func SlowThreshold

func SlowThreshold(value time.Duration) Option

SlowThreshold sets the request latency threshold used by slow logs.

func Store

func Store(store MonitorStore) Option

Store sets the monitor store used by console metrics and logs.

func Title

func Title(value string) Option

Title sets console title.

type Panel

type Panel interface {
	PanelConfig() PanelConfig
	Routes(group *route.Group)
}

Panel is a console extension panel.

func BuiltinPanels

func BuiltinPanels() []Panel

BuiltinPanels returns the framework-provided console panels.

func ErrorsPanel

func ErrorsPanel() Panel

ErrorsPanel returns HTTP error trends and error logs.

func InfrastructurePanel

func InfrastructurePanel() Panel

InfrastructurePanel returns built-in infrastructure snapshots.

func LogsPanel

func LogsPanel() Panel

LogsPanel returns captured application monitor logs.

func MessagePanel

func MessagePanel() Panel

MessagePanel returns the built-in message broker panel.

func ORMPanel

func ORMPanel() Panel

ORMPanel returns the built-in ORM and SQL execution panel.

func Overview

func Overview() Panel

Overview returns the built-in runtime overview panel.

func QueuePanel

func QueuePanel() Panel

QueuePanel returns the built-in queue and worker panel.

func RPCPanel

func RPCPanel() Panel

RPCPanel returns the built-in JSON-RPC panel.

func RoutesPanel

func RoutesPanel() Panel

RoutesPanel returns the built-in route snapshot panel.

func RuntimePanel

func RuntimePanel() Panel

RuntimePanel returns the built-in Go runtime panel.

func SchedulePanel

func SchedulePanel() Panel

SchedulePanel returns the built-in schedule/task/event panel.

func TrafficPanel

func TrafficPanel() Panel

TrafficPanel returns HTTP traffic metrics and access logs.

func WebSocketPanel

func WebSocketPanel() Panel

WebSocketPanel returns the built-in websocket panel.

type PanelConfig

type PanelConfig struct {
	Name  string
	Title string
	Icon  string
	Order int
}

PanelConfig describes one console panel.

type PanelFunc

type PanelFunc struct {
	Name  string
	Title string
	Icon  string
	Order int
	Mount func(group *route.Group)
}

PanelFunc adapts a function to Panel.

func (PanelFunc) PanelConfig

func (panel PanelFunc) PanelConfig() PanelConfig

PanelConfig returns panel metadata.

func (PanelFunc) Routes

func (panel PanelFunc) Routes(group *route.Group)

Routes mounts panel routes.

type PanelInfo

type PanelInfo struct {
	Name  string `json:"name"`
	Title string `json:"title"`
	Icon  string `json:"icon,omitempty"`
	Path  string `json:"path"`
	Order int    `json:"order,omitempty"`
}

PanelInfo describes a mounted console panel.

type QueueSample

type QueueSample struct {
	Time      time.Time `json:"time"`
	Pending   int64     `json:"pending"`
	Reserved  int64     `json:"reserved"`
	Delayed   int64     `json:"delayed"`
	Failed    int64     `json:"failed"`
	Processed int64     `json:"processed"`
	Succeeded int64     `json:"succeeded"`
	Retried   int64     `json:"retried"`
	Workers   int       `json:"workers"`
	Instances int       `json:"instances"`
}

QueueSample describes one queue/worker aggregate sample.

type RPCLog

type RPCLog struct {
	Time      time.Time     `json:"time"`
	Transport string        `json:"transport"`
	Method    string        `json:"method"`
	Latency   time.Duration `json:"latency"`
	Error     string        `json:"error,omitempty"`
}

RPCLog describes one JSON-RPC method call.

type RPCStat

type RPCStat struct {
	Method   string        `json:"method"`
	Count    int64         `json:"count"`
	Errors   int64         `json:"errors"`
	Avg      time.Duration `json:"avg"`
	Max      time.Duration `json:"max"`
	LastSeen time.Time     `json:"last_seen"`
}

RPCStat aggregates JSON-RPC method calls.

type Registry

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

Registry stores console panels registered by framework and app providers.

func Default

func Default() *Registry

Default returns the default console registry.

func New

func New() *Registry

New creates a console panel registry.

func (*Registry) Panels

func (registry *Registry) Panels() []Panel

Panels returns registered panels ordered by menu order then registration order.

func (*Registry) Register

func (registry *Registry) Register(panels ...Panel)

Register adds or replaces console panels.

func (*Registry) RegisterBuiltinSummaries

func (registry *Registry) RegisterBuiltinSummaries()

RegisterBuiltinSummaries adds built-in summary resolvers once.

func (*Registry) RegisterSummary

func (registry *Registry) RegisterSummary(resolvers ...SummaryResolver)

RegisterSummary adds console summary resolvers.

func (*Registry) Summaries

func (registry *Registry) Summaries(ctx context.Context, app AppContext) []Summary

Summaries resolves all registered summary rows.

type RouteInfo

type RouteInfo struct {
	Method      string   `json:"method"`
	Path        string   `json:"path"`
	Name        string   `json:"name,omitempty"`
	Summary     string   `json:"summary,omitempty"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Security    []string `json:"security,omitempty"`
	Deprecated  bool     `json:"deprecated,omitempty"`
	Status      int      `json:"status,omitempty"`
	Middlewares int      `json:"middlewares"`
	DocNames    []string `json:"docs,omitempty"`
	SkipDoc     bool     `json:"skip_doc,omitempty"`
	Meta        core.Map `json:"meta,omitempty"`
}

RouteInfo is a serializable route snapshot.

func PublicRoutes

func PublicRoutes(app AppContext) []RouteInfo

PublicRoutes returns route snapshots intended for the console routes page.

func Routes

func Routes(app AppContext) []RouteInfo

Routes returns serializable route snapshots.

type RouteStat

type RouteStat struct {
	Method    string        `json:"method"`
	Route     string        `json:"route"`
	Path      string        `json:"path"`
	Count     int64         `json:"count"`
	Errors    int64         `json:"errors"`
	Min       time.Duration `json:"min"`
	Max       time.Duration `json:"max"`
	Avg       time.Duration `json:"avg"`
	LastSeen  time.Time     `json:"last_seen"`
	LastState int           `json:"last_status"`
}

RouteStat aggregates HTTP request metrics by route.

type SQLStat

type SQLStat struct {
	Database string        `json:"database"`
	Dialect  string        `json:"dialect"`
	Table    string        `json:"table"`
	Count    int64         `json:"count"`
	Errors   int64         `json:"errors"`
	Slow     int64         `json:"slow"`
	Avg      time.Duration `json:"avg"`
	Max      time.Duration `json:"max"`
	LastSeen time.Time     `json:"last_seen"`
}

SQLStat aggregates SQL execution metrics.

type Summary

type Summary struct {
	Module  string `json:"module"`
	Summary string `json:"summary"`
	Default string `json:"default"`
}

Summary describes one framework/runtime module row for the console overview.

func CacheSummary

func CacheSummary(_ context.Context, app AppContext) []Summary

func DatabaseSummary

func DatabaseSummary(_ context.Context, app AppContext) []Summary

func HostSummary

func HostSummary(_ context.Context, app AppContext) []Summary

func LockSummary

func LockSummary(_ context.Context, app AppContext) []Summary

func QueueSummary

func QueueSummary(ctx context.Context, app AppContext) []Summary

func RateSummary

func RateSummary(_ context.Context, app AppContext) []Summary

func SessionSummary

func SessionSummary(_ context.Context, app AppContext) []Summary

func StorageSummary

func StorageSummary(_ context.Context, app AppContext) []Summary

type SummaryResolver

type SummaryResolver func(context.Context, AppContext) []Summary

SummaryResolver resolves console summary rows.

func BuiltinSummaries

func BuiltinSummaries() []SummaryResolver

type WSSample

type WSSample struct {
	Time        time.Time `json:"time"`
	Hub         string    `json:"hub"`
	Clients     int       `json:"clients"`
	Channels    int       `json:"channels"`
	MessagesIn  uint64    `json:"messages_in"`
	MessagesOut uint64    `json:"messages_out"`
	BytesIn     uint64    `json:"bytes_in"`
	BytesOut    uint64    `json:"bytes_out"`
}

WSSample describes one websocket hub aggregate sample.

Jump to

Keyboard shortcuts

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