globeviz.vcl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. table globeviz_config {
  2. "service_name": "${service}",
  3. "sample_rate": "50" // send (1 / sample_rate) requests, target is 20-50
  4. }
  5. // https://deviceatlas.com/device-data/explorer/#defined_property_values/7/2705619
  6. table globeviz_known_browsers {
  7. "Chrome": "C",
  8. "Chrome Mobile": "C",
  9. "Firefox": "F",
  10. "Firefox for Mobile": "F",
  11. "Edge": "E",
  12. "Kindle Browser": "K",
  13. "Safari": "S",
  14. "Samsung Browser": "A"
  15. }
  16. // Record the following data (space separated)
  17. // PIO Name of source service (3 char)
  18. // LCY Name of Fastly POP (3 char)
  19. // 51.43,-0.23 Client location (var length)
  20. // 17234 Duration (var length)
  21. // EN Normalized Accept-Language (2 char)
  22. // M Cache state (1 char: H, M, P)
  23. // 2 HTTP version (numeric, variable length)
  24. // 1.2 TLS version (numeric, variable length)
  25. // C Browser (1 char: C, F, E, K, S, A)
  26. //
  27. sub vcl_log {
  28. // Record only non-shielding, non-VPN requests at the specified sample frequency
  29. if (fastly.ff.visits_this_service == 0 && client.geo.proxy_type == "?" && client.geo.latitude != 0 && randombool(1,std.atoi(table.lookup(globeviz_config, "sample_rate", "100000")))) {
  30. log "syslog " req.service_id " fastly-globeviz :: "
  31. table.lookup(globeviz_config, "service_name", "-") " "
  32. server.datacenter " "
  33. client.geo.latitude "," client.geo.longitude " "
  34. time.elapsed.usec " "
  35. std.toupper(
  36. accept.language_lookup(
  37. "en:de:fr:nl:jp:es:ar:zh:gu:he:hi:id:it:ko:ms:pl:pt:ru:th:uk",
  38. "en",
  39. req.http.Accept-Language
  40. )
  41. ) " "
  42. substr(fastly_info.state, 0, 1) " "
  43. regsuball(req.proto, "[^\d.]", "") " "
  44. regsuball(tls.client.protocol, "[^\d.]", "") " "
  45. table.lookup(globeviz_known_browsers, client.browser.name, "Z")
  46. ;
  47. }
  48. }