Learn how to increment values.
Track values
Tracking values runs inc
on the driver. Every time you track a value, it will increment the metrics.
track(key=String, at=DateTime, values=Map, config=Trifle.Stats.Configuration)
key
- string identifier for the metricsat
- timestamp of the sample (in most cases current timestamp)values
- map of values. Can contain only nested maps and numbers (Integer, Float). Any other type will cause an error.config
- optional configuration variable ofTrifle.Stats.Configuration
. It defaults to global configuration, otherwise uses passed in configuration.
Track your first values
Trifle.Stats.track('event::logs', DateTime.utc_now(), %{count: 1, duration: 2, lines: 241})
=> ...
Then do it few more times
Trifle.Stats.track('event::logs', DateTime.utc_now(), %{count: 1, duration: 1, lines: 56})
=> ...
Trifle.Stats.track('event::logs', DateTime.utc_now(), %{count: 1, duration: 5, lines: 361})
=> ...
You can also store nested counters like
Trifle.Stats.track('event::logs', DateTime.utc_now(), %{
count: 1,
duration: %{
parsing: 21,
compression: 8,
upload: 1
},
lines: 25432754
})
Get values
Retrieve your values for specific range
. Adding increments above will return sum of all the values you've tracked.
Trifle.Stats.values('event::logs', DateTime.utc_now, DateTime.utc_now, :day)
=> ...