Circling back, I was able to write the Python script to pull Realtime Reporting API data from Google Analytics ... locally.
I found some of the initial challenges were in utilizing the current Google Analytics API's correctly. As a number of the examples I found online referenced deprecated API's etc.
Here are a few of the resources that ultimately provided the most help:
Google API Client Libraries - Python
https://developers.google.com/api-client-library/python/
OAuth2 Service Account (setting up a Service Account)
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
Google Analytics API v3 Explorer
https://developers.google.com/apis-explorer/#p/analytics/v3/analytics.data.realtime.get
Here's the script that I've gotten to work (on a locally installed Python):
# Python script to pull Active User count on website from Google Analytics via Realtime Reporting API
from google.oauth2 import service_account
from googleapiclient.discovery import build
API_NAME = 'analytics'
API_VERSION = 'v3'
ACCOUNT_EMAIL = '<svc-account>@<project>.iam.gserviceaccount.com' #generated from Google Developer
KEYFILE = './client_secrets.json' #downloaded from Google Developer
ANALYTICS_VIEW_ID = 'ga:<#########>' #gathered from GA account
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
RT_ACTIVE_USERS = 'rt:activeUsers'
RT_DIMENSIONS = 'rt:medium'
credentials = service_account.Credentials.from_service_account_file(KEYFILE, scopes=SCOPES)
service = build(API_NAME, API_VERSION, credentials=credentials)
results = service.data().realtime().get(ids=ANALYTICS_VIEW_ID, metrics=RT_ACTIVE_USERS, dimensions=RT_DIMENSIONS).execute()
totals = results.get('totalsForAllResults')
active_users = int(totals.get("rt:activeUsers"))
print str(active_users)
Next challenge/step - edit script to use json and paepy modules and configure Python on PRTG probe to add Google APIs
Python Sensor Example -> C:\Program Files (x86)\PRTG Network Monitor\Custom Sensor\python\sensor_example.py
Add Google Module -> C:\Program Files (x86)\PRTG Network Monitor\Python34\Lib
Viewing the example python script sensor provided in PRTG install shows:
# -*- coding: utf-8 -*-
import sys
import json
# get CustomSensorResult from paepy package
from paepy.ChannelDefinition import CustomSensorResult
if __name__ == "__main__":
# interpret first command line parameter as json object
data = json.loads(sys.argv[1])
# create sensor result
result = CustomSensorResult("This sensor is added to " + data['host'])
# add primary channel
result.add_channel(channel_name="Percentage", unit="Percent", value=87, is_float=False, primary_channel=True,
is_limit_mode=True, limit_min_error=10, limit_max_error=90,
limit_error_msg="Percentage too high")
# add additional channel
result.add_channel(channel_name="Response Time", unit="TimeResponse", value="4711")
# print sensor result to std
print(result.get_json_result())
Add comment