Custom metrics and events platform for Rails apps.
# Install SDK
gem 'brainzlab'
# Configure and track
BrainzLab::Flux.track("user.signup", user_id: user.id, plan: "pro")
BrainzLab::Flux.gauge("users.online", 234)docker pull brainzllc/flux:latest
docker run -d \
-p 3000:3000 \
-e DATABASE_URL=postgres://user:pass@host:5432/flux \
-e REDIS_URL=redis://host:6379/4 \
-e RAILS_MASTER_KEY=your-master-key \
brainzllc/flux:latest# Gemfile
gem 'brainzlab'# config/initializers/brainzlab.rb
BrainzLab.configure do |config|
config.flux_key = ENV['FLUX_API_KEY']
endbin/setup
bin/rails server| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection | Yes |
REDIS_URL |
Redis connection | Yes |
RAILS_MASTER_KEY |
Rails credentials | Yes |
BRAINZLAB_PLATFORM_URL |
Platform URL for auth | Yes |
- Ruby 3.4.7 / Rails 8.1
- PostgreSQL 16 with TimescaleDB (time-series)
- Redis 7
- Hotwire (Turbo + Stimulus) / Tailwind CSS
- Solid Queue / Solid Cache / Solid Cable
# Track custom events
BrainzLab::Flux.track("user.signup", {
user_id: user.id,
plan: "pro",
value: 29.99
})# Gauges - current value (overwrites)
BrainzLab::Flux.gauge("users.online", 234)
BrainzLab::Flux.gauge("queue.depth", 42)
# Counters - incrementing values
BrainzLab::Flux.increment("api.requests")
BrainzLab::Flux.increment("emails.sent", tags: { type: "welcome" })
# Distributions - statistical aggregation
BrainzLab::Flux.distribution("response_time", 145.2)
BrainzLab::Flux.distribution("order_value", 99.99)
# Sets - unique counts (cardinality)
BrainzLab::Flux.set("daily_active_users", user.id)
# Measure timing
BrainzLab::Flux.measure("pdf.generate", tags: { pages: 10 }) do
generate_pdf(document)
end{
"name": "user.signup",
"timestamp": "2024-12-21T10:00:00Z",
"properties": {
"plan": "pro",
"source": "google_ads"
},
"tags": {
"environment": "production"
},
"user_id": "user_123",
"value": 29.99
}| Type | Description | Example |
|---|---|---|
| Gauge | Current value (overwrites) | users.online, queue.depth |
| Counter | Incrementing values | api.requests, emails.sent |
| Distribution | Statistical aggregation | response_time, order_value |
| Set | Unique counts (cardinality) | daily_active_users |
Build custom dashboards with widgets:
- Number - Single metric value
- Graph - Time series chart
- Bar - Bar chart comparison
- Pie - Distribution breakdown
- Table - Data table
- Heatmap - Activity visualization
AI-powered anomaly detection:
- Compares current data with historical baselines
- Detects spikes (>3x baseline) and drops (<30% baseline)
- Severity levels: info, warning, critical
POST /api/v1/events- Track single eventPOST /api/v1/events/batch- Batch eventsGET /api/v1/events- List eventsGET /api/v1/events/count- Count eventsGET /api/v1/events/stats- Event statistics
POST /api/v1/metrics- Track metricPOST /api/v1/metrics/batch- Batch metricsGET /api/v1/metrics- List metric definitionsGET /api/v1/metrics/:name- Get metric detailsGET /api/v1/metrics/:name/query- Query time series
GET /api/v1/dashboards- List dashboardsPOST /api/v1/dashboards- Create dashboardGET /api/v1/dashboards/:id- Get dashboard with widgets
| Tool | Description |
|---|---|
flux_track |
Track a custom event |
flux_query |
Query events with filters |
flux_metric |
Get metric values and time series |
flux_dashboard |
Get dashboard data with widget values |
flux_anomalies |
List detected anomalies |
Full documentation: docs.brainzlab.ai/products/flux
services:
flux:
image: brainzllc/flux:latest
ports:
- "3000:3000"
environment:
DATABASE_URL: postgres://user:pass@db:5432/flux
REDIS_URL: redis://redis:6379/4
RAILS_MASTER_KEY: ${RAILS_MASTER_KEY}
BRAINZLAB_PLATFORM_URL: http://platform:3000
depends_on:
- db
- redisbin/rails test
bin/rubocopSee CONTRIBUTING.md for development setup and contribution guidelines.
This project is licensed under the OSAaSy License.