Plugin Monitoring

Pulse — Production Monitoring

Pulse is a lightweight production-grade monitoring plugin for Nimbus. It captures request performance with percentile stats, cache hit rates, queue throughput, exception tracking, and slow query detection — all without external dependencies.

§ Overview

Unlike Telescope (which stores individual entries as a debug tool), Pulse aggregates metrics designed for production use:

Request Stats
P50 / P95 / P99
Slow Queries
Configurable threshold
Cache Stats
Hit / Miss rates
Queue Stats
Processed / Failed
Exceptions
Grouping + Count
Periods
1h / 6h / 24h / 7d

§ Installation

$ nimbus plugin:install pulse

Or add manually:

import "github.com/CodeSyncr/nimbus/plugins/pulse"

app.Use(pulse.NewPlugin())

Access the dashboard at http://localhost:3000/pulse.

§ Configuration

package config

import "github.com/CodeSyncr/nimbus/plugins/pulse"

var Pulse = pulse.Config{
    // Dashboard path (default: "/pulse")
    Path:  "/pulse",

    // Enable/disable (default: true)
    Enabled: true,

    // Slow query threshold (queries slower than this are flagged)
    SlowQueryThreshold: 100 * time.Millisecond, // default: 100ms

    // Maximum recent exceptions to keep
    MaxExceptions: 50,

    // Maximum slow queries to keep
    MaxSlowQueries: 50,

    // Request stats retention periods
    // Stats are auto-bucketed into 1h, 6h, 24h, and 7d windows
}

§ Request Performance

Pulse's request middleware automatically captures every HTTP request and computes rolling percentile statistics:

Metric Description
total_requestsTotal HTTP requests in this period
avg_duration_msAverage response time
p50_ms50th percentile (median response time)
p95_ms95th percentile (tail latency)
p99_ms99th percentile (worst-case latency)
max_duration_msSlowest request in this period

Stats are bucketed into four retention periods:

  • 1 hour — Granular real-time view
  • 6 hours — Short-term trends
  • 24 hours — Daily performance overview
  • 7 days — Weekly trends

§ Cache Statistics

Track how effectively your application uses the cache layer:

// Automatically tracked by the cache subsystem:
// - Hits  (cache key found)
// - Misses (cache key not found)
// - Writes (cache key set/put)

// The dashboard shows hit rate as a percentage:
// Hit Rate = Hits / (Hits + Misses) × 100

§ Queue Statistics

Monitor job throughput and failure rates:

// Tracked metrics:
pulse.RecordJob(true)   // processed successfully
pulse.RecordJob(false)  // job failed

// Dashboard displays:
// - Jobs Processed (total)
// - Jobs Failed (total)
// - Success Rate percentage

§ Exception Tracking

Pulse captures and groups exceptions with occurrence counts:

// Record an exception
pulse.RecordException(err)

// Each exception record includes:
// - Error type (reflect.TypeOf)
// - Error message
// - Occurrence count (auto-incremented for duplicates)
// - First seen / Last seen timestamps

Duplicate exceptions are grouped by error type + message, keeping the recent list compact and actionable.

§ Slow Query Detection

Database queries exceeding the configured threshold are captured with full SQL:

// Queries slower than SlowQueryThreshold (default: 100ms) are flagged
pulse.RecordSlowQuery("SELECT * FROM users WHERE...", 
    250*time.Millisecond)

// Each slow query record:
// - SQL statement
// - Duration (ms)
// - Timestamp

§ Dashboard API

Route Description
GET /pulseDashboard HTML page
GET /pulse/api/statsJSON — full stats object
GET /pulse/api/stats?period=1hFiltered by period (1h, 6h, 24h, 7d)
GET /pulse/api/exceptionsRecent exceptions with grouping
GET /pulse/api/slow-queriesSlow queries above threshold

§ Pulse vs Telescope

Feature Pulse Telescope
PurposeProduction monitoringDevelopment debugging
Data storageAggregated statsIndividual entries
PerformanceMinimal overheadHigher overhead
PercentilesP50 / P95 / P99Not available
Watchers5 (focused)18 (comprehensive)

Tip: Use both! Telescope in development for deep debugging, and Pulse in production for high-level health monitoring.