A badly written (probably) and ridiculously simple Go HTTP script to take an incoming request and persist it in Redis for deriving useful information from later.
git clone git@github.com:joshmcarthur/go-analytics.git
cd go-analytics
go get menteslibres.net/gosexy/redis
- (Ensure Redis is installed and running)
go build analytics.go
./analytics
open http://localhost:8080/analytics.js
- Run
redis-cli
, and thenLLEN analytics
to see that request data is being pushed onto the list
I'm still working that out myself at the moment - all this does is serializes the request and stores it as JSON. What you might do though, is run a worker that does something along the following lines:
- Use an
RPOP
Redis command to get the oldest item added to the list (FIFO style) - De-serialize the JSON
- Geolocate the remote IP to find out where the visitor came from - maybe try and work out their ISP
- Take a look at the
User-Agent
and map that to previous requests - Have a look at the URL they requested, along with any params
- Inspect any custom headers you might have added to the request - maybe you're interested in rendering time, the current user, or how many times they've visited before.
- Same instructions as above up to 4]
go test -v
- All tests should be passing, but require that a Redis server is runnning at
localhost:6379
.
See LICENSE.txt