github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/scripts/local-analytics.sh (about)

     1  #!/bin/bash
     2  #
     3  # Run a dummy local analytics server that prints each metric in a formatted JSON
     4  # blob similar to the format it is stored in Tilt cloud.
     5  #
     6  # Run this script in one shell, then start Tilt like:
     7  #
     8  # TILT_ANALYTICS_URL=http://localhost:9988 tilt up
     9  
    10  port=${1-9988}
    11  running=1
    12  interrupt() { running=; }
    13  trap interrupt INT
    14  
    15  echo Analytics listening on http://localhost:$port
    16  
    17  jqscript='. as {$name, $machine, "git.origin": $gitorigin} | 
    18    delpaths([["name"],["machine"],["git.origin"]]) | 
    19    { $name, $machine, "git.origin": $gitorigin, time: (now | todate), tags: . }'
    20  
    21  while [ "$running" ]; do
    22      echo -e "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n" | \
    23          nc -l $port | tail -1 | jq "$jqscript"
    24  done
    25  
    26  exit 0