Sha256: cc691370e3f926cdaa50e06faef73e817384cf71b67717fe82c20377d9200fc9
Contents?: true
Size: 1.13 KB
Versions: 8
Compression:
Stored size: 1.13 KB
Contents
require 'thread' require 'logger' module Anschel class Stats def initialize interval, logger @logger = logger @interval = interval || 30 @stats = Hash.new @lock = Mutex.new @logger.info event: 'stats-loaded' @thread = Thread.new do loop do sleep @interval @logger.info \ event: 'stats-report', version: Anschel::VERSION, stats: read end end end def read ; stats end def create name, init=0 with_lock do stats[name] = init stats end end def delete name with_lock do stats.delete name end end def inc name, by=1 with_lock do stats[name] += by end end def dec name, by=1 with_lock do stats[name] -= by end end def set name, to with_lock do stats[name] = to end end def get name with_lock do stats[name] end end private attr_reader :stats def with_lock &block @lock.synchronize do yield end end end end
Version data entries
8 entries across 8 versions & 1 rubygems