Lambda function to send your Github traffic statistics to New Relic Insights.
For repositories that you have push access to within Github, the Github traffic API provides access to the information provided in the graphs section of the repositories UI.
This information includes referral sources, referral paths, views and clones. The API returns data over the past 14 day period. As the API only returns data over the past 14 day period, this solution aims to give users access to historical Traffic data for their Github repositories within Insights. This Lambda function calls each endpoint every 15 days and creates custom events that you can then query and create visualations within New Relic Insights.
See the New Relic One Dashboard below:
The function uses Github's token based API authentication to gain access to the user's repository data. For each of the users repostories, the script makes a call to each Traffic API endpoint and records a custom event using the Event API if there has been any Traffic data reported.
Clone the repository: git clone https://github.com/AnthonyBloomer/github-traffic-insights.git
Update the following environment variables in the template.yml
file:
GITHUB_TOKEN
- Create a personal access token using your Personal access tokens settings page.GITHUB_USERNAME
- Your GitHub username.NEW_RELIC_ACCOUNT_ID
- Your New Relic Account IDNEW_RELIC_INSERT_KEY
- Your New Relic Insert Key
Deploy using the AWS CLI:
aws cloudformation deploy --template template.yml --stack-name github
The project also includes the sample dashboard JSON shown above which you can import into your New Relic account using the Dashboards API.