Trifle.Stats

Hex VersionElixir CI

Time-series metrics for Elixir. Track anything (signups, revenue, job durations) using the database you already have. No InfluxDB. No TimescaleDB. Just one call and your existing PostgreSQL, MongoDB, Redis, MySQL, or SQLite.

Part of the Trifle ecosystem. Also available in Ruby and Go.

Why Trifle.Stats?

Quick Start

1. Install

def deps do
  [
    {:trifle_stats, "~> 1.0"}
  ]
end

2. Configure

# config/config.exs
config :trifle_stats,
  driver: Trifle.Stats.Driver.Postgres,
  granularities: [:hour, :day, :week, :month]

3. Track

Trifle.Stats.track("orders", DateTime.utc_now(), %{
  count: 1,
  revenue: 4990,
  revenue_by_country: %{us: 4990},
  revenue_by_channel: %{organic: 4990}
})

4. Query

Trifle.Stats.values("orders", ~U[2026-02-10 00:00:00Z], DateTime.utc_now(), :day)
#=> %{
#     at: [~U[2026-02-10 00:00:00Z], ~U[2026-02-11 00:00:00Z], ...],
#     values: [%{"count" => 12, "revenue" => 59880, ...}, ...]
#   }

5. Process with Series

Trifle.Stats.values("orders", from, to, :day)
|> Trifle.Stats.series()
|> Trifle.Stats.Series.transform_average("revenue", "count", "avg_order")
|> Trifle.Stats.Series.aggregate_sum("count")

Drivers

Driver Backend Best for
Postgres JSONB upsert Most production apps
MongoDB Document upsert Document-oriented stacks
Redis Hash increment High-throughput counters
MySQL JSON column MySQL shops
SQLite JSON1 extension Single-node apps, dev/test
Process In-memory (ETS) Testing

Features

Documentation

Full guides, API reference, and examples at docs.trifle.io/trifle-stats-ex

Trifle Ecosystem

Trifle.Stats is the tracking layer. The ecosystem grows with you:

Component What it does
Trifle App Dashboards, alerts, scheduled reports, AI-powered chat. Cloud or self-hosted.
Trifle CLI Query and push metrics from the terminal. MCP server mode for AI agents.
Trifle::Stats (Ruby) Ruby implementation with the same API and storage format.
Trifle Stats (Go) Go implementation with the same API and storage format.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/trifle-io/trifle_stats.

License

The package is available as open source under the terms of the MIT License.