This docker container collects google analytics data and ships it to graphite (carbon)
1.3K
Fetch Google Analytics metrics, and send them to a given Graphite host.
Make sure to enable the Analytics API via the GCloud interface. Download your GCloud service account .p12 file and generate a .pem file:
openssl pkcs12 -in google-service-account.p12 -nocerts -passin pass:YOUR_PASSWORD -nodes -out google-service-account.pem
In Google Analytics, add a new user with read permission using the service account email address.
# Retreive data from yesterday
docker run -t -i \
-e "[email protected]" \
-e "GA_MAX_RESULTS=1000" \
-e "GA_METRICS=ga:pageviews,ga:sessions,ga:avgTimeOnSite" \
-e "GA_MINUTES=false" \
-e "GA_PEM_PATH=/home/root/google-service-account.pem" \
-e "GA_VIEW_ID=123456" \
-e "GRAPHITE_HOST=localhost" \
-e "GRAPHITE_NAMESPACE=google-analytics" \
-e "GRAPHITE_PORT=2003" \
-v "$(pwd)/google-service-account.pem":/home/root/google-service-account.pem \
analytics
# Retreive data from specific date
docker run -t -i \
-e "[email protected]" \
-e "GA_MAX_RESULTS=1000" \
-e "GA_METRICS=ga:pageviews,ga:sessions,ga:avgTimeOnSite" \
-e "GA_MINUTES=false" \
-e "GA_PEM_PATH=/home/root/google-service-account.pem" \
-e "GA_VIEW_ID=123456" \
-e "GRAPHITE_HOST=localhost" \
-e "GRAPHITE_NAMESPACE=google-analytics" \
-e "GRAPHITE_PORT=2003" \
-v "$(pwd)/google-service-account.pem":/home/root/google-service-account.pem \
analytics \
gatographite 2015-12-25
docker pull travix/analytics-to-graphite:latest