redis_stats
redis_stats
5m-30m-1d stats for tracking of code execution duration.
Installation
-
Add the dependency to your
shard.yml
:dependencies: redis_stats: github: sschekotikhin/redis_stats
-
Run
shards install
Usage
require "redis_stats"
Basic example
# configure
RedisStats.configure do |config|
config.redis = Redis::PooledClient.new(
host: "localhost",
port: 6379,
database: 0,
pool_size: 10
)
config.ttl = 10.minutes
config.prefix = "redis_stats"
end
# add method
t0 = Time.local
# ...
# some code
# ...
t1 = Time.local
# `key` - any string key
# `duration` - duration of executed code, milliseconds
RedisStats.add(key: "foo", duration: (t1 - t0).total_milliseconds)
# stats method
# Retrieves statistics from Redis.
RedisStats.stats
# => {
# "foo" => {
# "5m" => "0.3ms", # last 5 minutes
# "30m" => "0.5ms", # last 30 minutes
# "1d" => "0.55ms", # last day
# "max" => "0.7ms", # max stored duration
# "min" => "0.05ms", # min stored duration
# "count" => "100" # count of stored records
# }
# }
# del_expired_stats method
# Removes all stats, which ttl expired.
RedisStats.del_expired_stats
Contributing
- Fork it (https://github.com/sschekotikhin/redis_stats/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- SShekotihin - creator and maintainer
Repository
redis_stats
Owner
Statistic
- 1
- 0
- 0
- 0
- 3
- almost 3 years ago
- January 12, 2022
License
MIT License
Links
Synced at
Thu, 21 Nov 2024 12:13:11 GMT
Languages