Documentation
¶
Overview ¶
Package pulse provides lightweight application monitoring for Nimbus applications. It collects metrics on requests, slow queries, exceptions, queue throughput, and cache hit rates with minimal overhead.
Unlike Telescope which records every request, Pulse uses aggregated metrics and ring buffers suitable for production use.
p := pulse.New(pulse.Config{MaxEntries: 10000})
app.Use(p.Middleware())
app.GET("/pulse", p.DashboardHandler())
Index ¶
- type CacheStats
- type Config
- type Entry
- type EntryType
- type MySQLTimestampCol
- type PathStat
- type Pulse
- func (p *Pulse) AuditY2038()
- func (p *Pulse) DashboardHandler() router.HandlerFunc
- func (p *Pulse) GetCacheStats() CacheStats
- func (p *Pulse) GetQueueStats() QueueStats
- func (p *Pulse) GetRequestStats() RequestStats
- func (p *Pulse) Middleware() router.Middleware
- func (p *Pulse) RecentExceptions(n int) []Entry
- func (p *Pulse) RecentRequests(n int) []Entry
- func (p *Pulse) RecentSlowQueries(n int) []Entry
- func (p *Pulse) RecordCacheDelete(key string)
- func (p *Pulse) RecordCacheHit(key string)
- func (p *Pulse) RecordCacheMiss(key string)
- func (p *Pulse) RecordCacheWrite(key string)
- func (p *Pulse) RecordException(err error, context map[string]any)
- func (p *Pulse) RecordJob(name string, duration time.Duration, err error)
- func (p *Pulse) RecordMail(to, subject string, success bool)
- func (p *Pulse) RecordRequest(method, path string, status int, duration time.Duration, err error)
- func (p *Pulse) RecordSlowQuery(query string, duration time.Duration, args ...any)
- type PulsePlugin
- type QueueStats
- type RequestStats
- type Y2038Audit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheStats ¶
type CacheStats struct {
Hits int64 `json:"hits"`
Misses int64 `json:"misses"`
Writes int64 `json:"writes"`
Deletes int64 `json:"deletes"`
HitRate float64 `json:"hit_rate"`
}
CacheStats holds cache hit/miss statistics.
type Config ¶
type Config struct {
// MaxEntries is the maximum number of entries to keep in each ring buffer.
MaxEntries int
// SlowQueryThreshold marks queries slower than this as "slow" (default: 100ms).
SlowQueryThreshold time.Duration
// SlowRequestThreshold marks requests slower than this as "slow" (default: 500ms).
SlowRequestThreshold time.Duration
}
Config holds Pulse configuration options.
type Entry ¶
type Entry struct {
Type EntryType `json:"type"`
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration_ms"`
Data map[string]any `json:"data"`
}
Entry is a single monitoring record.
type MySQLTimestampCol ¶
type PathStat ¶
type PathStat struct {
Path string `json:"path"`
Count int64 `json:"count"`
AvgDuration float64 `json:"avg_duration_ms"`
ErrorCount int64 `json:"error_count"`
}
PathStat holds per-path request stats.
type Pulse ¶
type Pulse struct {
// contains filtered or unexported fields
}
Pulse is the main monitoring instance.
func (*Pulse) AuditY2038 ¶
func (p *Pulse) AuditY2038()
AuditY2038 inspects the connected MySQL schema and records any TIMESTAMP columns. Best-effort; it never panics.
func (*Pulse) DashboardHandler ¶
func (p *Pulse) DashboardHandler() router.HandlerFunc
DashboardHandler returns a handler that serves the Pulse monitoring dashboard as JSON (default) or a small HTML page when Accept prefers text/html.
func (*Pulse) GetCacheStats ¶
func (p *Pulse) GetCacheStats() CacheStats
GetCacheStats returns cache hit/miss statistics.
func (*Pulse) GetQueueStats ¶
func (p *Pulse) GetQueueStats() QueueStats
GetQueueStats returns queue job statistics.
func (*Pulse) GetRequestStats ¶
func (p *Pulse) GetRequestStats() RequestStats
GetRequestStats returns aggregated request statistics.
func (*Pulse) Middleware ¶
func (p *Pulse) Middleware() router.Middleware
Middleware returns a router middleware that automatically records request metrics.
func (*Pulse) RecentExceptions ¶
RecentExceptions returns the most recent exceptions.
func (*Pulse) RecentRequests ¶
RecentRequests returns the most recent requests.
func (*Pulse) RecentSlowQueries ¶
RecentSlowQueries returns the most recent slow queries.
func (*Pulse) RecordCacheDelete ¶
RecordCacheDelete records a cache deletion.
func (*Pulse) RecordCacheHit ¶
RecordCacheHit records a cache hit.
func (*Pulse) RecordCacheMiss ¶
RecordCacheMiss records a cache miss.
func (*Pulse) RecordCacheWrite ¶
RecordCacheWrite records a cache write.
func (*Pulse) RecordException ¶
RecordException records an application error.
func (*Pulse) RecordMail ¶
RecordMail records a sent email.
func (*Pulse) RecordRequest ¶
RecordRequest records an HTTP request.
type PulsePlugin ¶
type PulsePlugin struct {
nimbus.BasePlugin
Pulse *Pulse
}
PulsePlugin wraps Pulse as a Nimbus plugin, making it installable via `nimbus plugin install pulse` and selectable during `nimbus new`.
func NewPlugin ¶
func NewPlugin(cfg ...Config) *PulsePlugin
NewPlugin creates a new Pulse plugin with default config.
func (*PulsePlugin) Boot ¶
func (p *PulsePlugin) Boot(app *nimbus.App) error
Boot is a no-op for Pulse.
func (*PulsePlugin) DefaultConfig ¶
func (p *PulsePlugin) DefaultConfig() map[string]any
DefaultConfig returns default Pulse configuration.
func (*PulsePlugin) Middleware ¶
func (p *PulsePlugin) Middleware() map[string]router.Middleware
Middleware returns named middleware for Pulse request recording.
func (*PulsePlugin) Register ¶
func (p *PulsePlugin) Register(app *nimbus.App) error
Register binds the Pulse instance into the container.
func (*PulsePlugin) RegisterRoutes ¶
func (p *PulsePlugin) RegisterRoutes(r *router.Router)
RegisterRoutes mounts the Pulse dashboard at /pulse.
type QueueStats ¶
type QueueStats struct {
Processed int64 `json:"processed"`
Failed int64 `json:"failed"`
Pending int64 `json:"pending"`
AvgTime float64 `json:"avg_time_ms"`
}
QueueStats holds queue job statistics.
type RequestStats ¶
type RequestStats struct {
TotalRequests int64 `json:"total_requests"`
TotalErrors int64 `json:"total_errors"`
AvgDuration float64 `json:"avg_duration_ms"`
P50Duration float64 `json:"p50_duration_ms"`
P95Duration float64 `json:"p95_duration_ms"`
P99Duration float64 `json:"p99_duration_ms"`
RequestsPerMin float64 `json:"requests_per_min"`
StatusCounts map[int]int64 `json:"status_counts"`
SlowRequests int64 `json:"slow_requests"`
TopPaths []PathStat `json:"top_paths"`
}
RequestStats holds aggregated request statistics.
type Y2038Audit ¶
type Y2038Audit struct {
Driver string `json:"driver"`
TimestampColumns []MySQLTimestampCol `json:"timestamp_columns"`
OK bool `json:"ok"`
// Error is set when the audit query failed (e.g. permissions) or DB was unavailable.
Error string `json:"error,omitempty"`
// Skipped explains non-MySQL drivers or missing DB (informational).
Skipped string `json:"skipped,omitempty"`
}
Y2038Audit summarizes schema timestamp risk for MySQL.