Class: RedisStat::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/redis-stat/server.rb

Constant Summary collapse

HISTORY_LENGTH =
50
STAT_TABLE_ROWS =
10

Class Method Summary collapse

Class Method Details

.alert(error) ⇒ Object



106
107
108
109
110
111
# File 'lib/redis-stat/server.rb', line 106

def alert error
  settings.mutex.synchronize do
    settings.last_error = error
  end
  publish({ :error => error })
end

.push(hosts, info, data, error) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/redis-stat/server.rb', line 88

def push hosts, info, data, error
  static = Hash[settings.redis_stat.tab_measures.map { |stat|
    [stat, hosts.map { |h| info[h][stat] }]
  }]
  data = {:at      => (Time.now.to_f * 1000).to_i,
          :static  => static,
          :dynamic => data,
          :error   => error}

  settings.mutex.synchronize do
    settings.last_error = nil
    hist = settings.history
    hist << data
    hist.shift if hist.length > HISTORY_LENGTH
  end
  publish data
end

.wait_until_runningObject



82
83
84
85
86
# File 'lib/redis-stat/server.rb', line 82

def wait_until_running
  while !RedisStat::Server.running?
    sleep 0.5
  end
end