]> git.openstreetmap.org Git - chef.git/commitdiff
tilecache: add script for reporting fastest peers
authorGrant Slater <git@firefishy.com>
Sun, 5 Apr 2020 13:39:53 +0000 (14:39 +0100)
committerGrant Slater <git@firefishy.com>
Sun, 5 Apr 2020 13:39:53 +0000 (14:39 +0100)
cookbooks/tilecache/recipes/default.rb
cookbooks/tilecache/templates/tilecache-fastest-peers.erb [new file with mode: 0644]

index 683a53d09d9165f7d0e808ea9db7227fbc56917a..e6e848ce175884fedfc506fe770cbf5e213a20ce 100644 (file)
@@ -205,3 +205,10 @@ template "/srv/tilecache/tilecache-curl-time" do
   mode 0o755
   variables :caches => tilecaches, :renders => tilerenders
 end
+
+template "/srv/tilecache/tilecache-fastest-peers" do
+  source "tilecache-fastest-peers.erb"
+  owner "root"
+  group "root"
+  mode 0o755
+end
diff --git a/cookbooks/tilecache/templates/tilecache-fastest-peers.erb b/cookbooks/tilecache/templates/tilecache-fastest-peers.erb
new file mode 100644 (file)
index 0000000..c6745de
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# Find performance reports for last few minutes
+# Add up total time taken to download tile grouped by remote server
+# Remove 1 second per successful time report (de-prioritise new servers)
+# Add 30 seconds per failed time report request
+# Sort time reports
+# Strip to best 4 server names
+
+/usr/bin/find /srv/tilecache/data/ -type f -iname 'tilecache-*.txt' -mmin -10 -print0 \
+ | /usr/bin/xargs -0 --no-run-if-empty /usr/bin/tail --quiet -n 20 \
+ | /usr/bin/awk -F ',' '$2 == 200 {time[$3] += $1; time[$3] -= 1} $2 != 200 {time[$3] +=30} END{for (i in time) print time[i], i}' \
+ | /usr/bin/sort -k1n \
+ | /usr/bin/cut -d '/' -f 3 \
+ | /bin/grep -E '(openstreetmap|localhost)' \
+ | /usr/bin/head -n 4