Trifle.Stats
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?
- No new infrastructure. Uses your existing database. No dedicated time-series DB to deploy, maintain, or pay for.
- One call, many dimensions. Track nested breakdowns (revenue by country by channel) in a single
trackcall. Automatic rollup across dynamic time granularities (1m,6h,1d, etc.). - Library-first. Start with the package. Add Trifle App dashboards, Trifle CLI terminal access, or AI agent integration via MCP when you need them.
Quick Start
1. Install
def deps do
[
{:trifle_stats, "~> 1.0"}
]
end2. 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
- Dynamic time granularities. Use any interval like
1m,10m,1h,6h,1d,1w,1mo,1q,1y. - Nested value hierarchies. Track dimensional breakdowns in a single call.
- Pipe-friendly Series API. Chain aggregators, transponders, and formatters.
- Precision mode. Decimal-based arithmetic for financial data.
- Data compatible. Same storage format as the Ruby and Go implementations.
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.