diff --git a/docs/demo-data/api-requests-by-user.tsv b/docs/demo-data/api-requests-by-user.tsv new file mode 100644 index 00000000..583c0754 --- /dev/null +++ b/docs/demo-data/api-requests-by-user.tsv @@ -0,0 +1,4 @@ +user requests +Alpha 1500 +Bravo 500 +Charlie 20 diff --git a/docs/housekeeping-api-requests.html b/docs/housekeeping-api-requests.html index 120e2b58..dc2bd8be 100644 --- a/docs/housekeeping-api-requests.html +++ b/docs/housekeeping-api-requests.html @@ -51,6 +51,20 @@
+ The top 20 users who made the highest number of API requests yesterday. +
+diff --git a/updater/reports/ReportAPIRequestsByUser.py b/updater/reports/ReportAPIRequestsByUser.py new file mode 100644 index 00000000..5ece46b2 --- /dev/null +++ b/updater/reports/ReportAPIRequestsByUser.py @@ -0,0 +1,14 @@ +from .Report import * + +# Calculate the top 20 users generating the most API calls +class ReportAPIRequestsByUser(Report): + + def name(self): + return "api-requests-by-user" + + def readData(self): + pass + + def updateData(self): + self.header, self.data = self.parseData( + self.executeScript(self.scriptPath("api-requests-by-user.sh"))) diff --git a/updater/scripts/api-requests-by-user.sh b/updater/scripts/api-requests-by-user.sh new file mode 100644 index 00000000..55acd138 --- /dev/null +++ b/updater/scripts/api-requests-by-user.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# +# Count number of API calls per user +# + +echo -e "user\trequests" + +zcat -f /var/log/github/unicorn.log.1* | + grep -F 'request_category=api' | + grep -Fv 'remote_address=127.0.0.1' | + grep -oP 'current_user=\K\S+' | + grep -Fvx 'nil' | + sort | + uniq -c | + sort -rn | + head -20 | + awk '{ printf("%s\t%s\n", $2, $1) }' diff --git a/updater/update-stats.py b/updater/update-stats.py index 9cacd6de..5264a322 100755 --- a/updater/update-stats.py +++ b/updater/update-stats.py @@ -9,6 +9,7 @@ from schema import * from reports.ReportAPIRequests import * +from reports.ReportAPIRequestsByUser import * from reports.ReportContributorsByOrg import * from reports.ReportContributorsByRepo import * from reports.ReportForksToOrgs import * @@ -74,6 +75,7 @@ def main(): # Update reports ReportAPIRequests(configuration, dataDirectory, metaStats).update() + ReportAPIRequestsByUser(configuration, dataDirectory, metaStats).update() ReportContributorsByOrg(configuration, dataDirectory, metaStats).update() ReportContributorsByRepo(configuration, dataDirectory, metaStats).update() ReportForksToOrgs(configuration, dataDirectory, metaStats).update()