ansible-taler-exchange

Ansible playbook to deploy a production Taler Exchange
Log | Files | Refs | README | LICENSE

exchange-latency.lua.j2 (1546B)


      1 -- Managed by Ansible. Classify the compact nginx 'taler' format locally.
      2 -- Route patterns are shared with nginx GET selection; identifiers never become labels.
      3 local routes = {
      4 {% for route in monitoring_nginx_latency_routes %}
      5     { {{ route.method | to_json }}, {{ ('^' ~ route.pattern ~ '$') | replace('-', '%-') | to_json }}, {{ route.operation | to_json }} },
      6 {% endfor %}
      7 }
      8 
      9 function exchange_latency(tag, timestamp, record)
     10     local line = record["log"]
     11     if type(line) ~= "string" then
     12         return 2, timestamp, { valid = "false" }
     13     end
     14     local method, uri, status, duration = line:match(
     15         "^m=(%u+) uri=(%S+) s=(%d%d%d) uct=.- urt=.- rt=(%d+%.?%d*) rl=%d+ bs=%d+$")
     16     local seconds = tonumber(duration)
     17     if not seconds or seconds == math.huge or
     18        (method ~= "GET" and method ~= "POST" and method ~= "PATCH" and method ~= "DELETE") or
     19        (status ~= "000" and (tonumber(status) < 100 or tonumber(status) > 599)) then
     20         return 2, timestamp, { valid = "false" }
     21     end
     22     local operation = "other"
     23     for _, route in ipairs(routes) do
     24         if method == route[1] and uri:match(route[2]) then
     25             operation = route[3]
     26             break
     27         end
     28     end
     29     -- GET selection is performed by nginx; reject unknown GETs defensively.
     30     if method == "GET" and operation == "other" then
     31         return 2, timestamp, { valid = "false" }
     32     end
     33     return 2, timestamp, {
     34         valid = "true", duration = seconds,
     35         method = method, status = status, operation = operation
     36     }
     37 end