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, "~> 2.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_expression(["revenue", "count"], "a / b", "avg_order")
|> Trifle.Stats.Series.aggregate_sum("count")

Drivers

DriverBackendBest for
APITrifle Cloud ProjectsHosted metrics without your own database
PostgresJSONB upsertMost production apps
MongoDBDocument upsertDocument-oriented stacks
RedisHash incrementHigh-throughput counters
MySQLJSON columnMySQL shops
SQLiteJSON1 extensionSingle-node apps, dev/test
ProcessIn-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:

ComponentWhat it does
Trifle AppDashboards, alerts, scheduled reports, AI-powered chat. Cloud or self-hosted.
Trifle CLIQuery 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.