Skip to main content

Flux

Flux is a custom metrics and events platform that lets you track anything and see everything in your Rails application.

Features

Custom Events

Track any discrete occurrence in your application

Metrics

Gauges, counters, distributions, and sets

Dashboards

Build custom dashboards with widgets

Anomaly Detection

AI-powered detection of spikes, drops, and trends

Quick Start

Add the gem and configure:
Gemfile
gem 'brainzlab'
config/initializers/brainzlab.rb
BrainzLab.configure do |config|
  config.secret_key = ENV['BRAINZLAB_SECRET_KEY']
  config.flux_enabled = true
end
Track your first event:
BrainzLab::Flux.track("user.signup", {
  user_id: user.id,
  plan: "pro",
  value: 29.99
})

Event Tracking

Events are discrete occurrences with a name, timestamp, and optional properties:
# Track a simple event
BrainzLab::Flux.track("button.clicked")

# Track with properties
BrainzLab::Flux.track("order.placed", {
  user_id: user.id,
  properties: { product: "widget", quantity: 3 },
  tags: { environment: "production" },
  value: 149.99
})
Events support:
  • Properties - Arbitrary key/value data
  • Tags - Indexed metadata for filtering
  • Value - Numeric value for aggregations
  • User ID - Link events to users

Metrics

Track four types of metrics:
TypeUse CaseExample
GaugeCurrent valueusers.online, queue.depth
CounterIncrementingapi.requests, emails.sent
DistributionStats (avg, p95)response_time, order_value
SetUnique countsdaily_active_users
# Gauge - current value
BrainzLab::Flux.gauge("users.online", 234)

# Counter - increment
BrainzLab::Flux.increment("api.requests")
BrainzLab::Flux.increment("api.requests", 5)

# Distribution - statistical aggregation
BrainzLab::Flux.distribution("response_time", 145.2)

# Set - unique count
BrainzLab::Flux.set("daily_active_users", user.id)

Timing Operations

Measure code execution time automatically:
BrainzLab::Flux.measure("pdf.generate", tags: { pages: 10 }) do
  generate_pdf(document)
end
This creates a distribution metric with the execution time in milliseconds.

Dashboards

Create custom dashboards with widgets:
  • Number - Single metric value
  • Graph - Time series charts
  • Bar - Categorical comparisons
  • Pie - Distribution breakdown
  • Table - Tabular data
  • Heatmap - Time-based patterns

Dashboard Guide

Learn how to build dashboards

Anomaly Detection

Flux automatically detects unusual patterns:
  • Spikes - Values more than 3x baseline
  • Drops - Values below 30% of baseline
  • Trends - Sustained directional changes
Severity levels:
  • Info - 0-50% deviation
  • Warning - 50-100% deviation
  • Critical - Over 100% deviation

Anomaly Detection

Configure anomaly detection

Configuration

BrainzLab.configure do |config|
  # Enable/disable Flux
  config.flux_enabled = true

  # Batch settings (for performance)
  config.flux_batch_size = 100
  config.flux_flush_interval = 10 # seconds

  # Tags added to all events/metrics
  config.flux_default_tags = {
    environment: Rails.env,
    version: MyApp::VERSION
  }
end

What’s Next?