1 Ohai.plugin(:TileCache) do
5 recent = Time.now - 600
8 # Find performance reports for last few minutes
9 # Add up total time taken to download tile grouped by remote server
10 # Remove 1 second per successful time report (de-prioritise new servers)
11 # Add 10 seconds per failed time report request
12 Dir.glob("/srv/tilecache/data/**/tilecache-*.txt").each do |path|
13 if File.mtime(path) > recent
14 IO.readlines(path).reverse.take(20).each do |sample|
15 if sample =~ %r{^(\d+\.\d+),(\d+),https://([^/]+)/} then
16 time = Regexp.last_match(1).to_f
17 status = Regexp.last_match(2).to_i
18 host = Regexp.last_match(3)
21 times[host] = times.fetch(host, 0) + (time + 1) * (time + 1) - 1
23 times[host] = times.fetch(host, 0) + 10
31 # Strip to best 4 server names
32 times.to_a.sort_by(&:last).take(4).map(&:first)
35 collect_data(:default) do
38 tilecache[:tile_siblings] = tile_siblings