Skip to content

Commit

Permalink
Add API Requests By User (#156)
Browse files Browse the repository at this point in the history
This adds a report to collect the top 20 API users each day.
Reports this info in a simple table, this is handy for identifying
users who are approaching or over the API rate limit.
  • Loading branch information
dfarr authored and Lars Schneider committed Apr 24, 2018
1 parent 9d99460 commit b734a91
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/demo-data/api-requests-by-user.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
user requests
Alpha 1500
Bravo 500
Charlie 20
14 changes: 14 additions & 0 deletions docs/housekeeping-api-requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ <h3>API Requests</h3>
</div>

<div class="chart-placeholder">
<h3>API Requests per User</h3>
<canvas
data-url="{{ site.dataURL }}/api-requests-by-user.tsv"
data-type="list"
></canvas>
<div class="info-box">
<p>
The top 20 users who made the highest number of API requests yesterday.
</p>
</div>
</div>

<div class="chart-placeholder">
<h3>API Requests per Repository per IP</h3>
<table data-url="{{ site.dataURL }}/api-requests-detailed.tsv" data-type="table"></table>
<div class="info-box">
<p>
Expand Down
14 changes: 14 additions & 0 deletions updater/reports/ReportAPIRequestsByUser.py
Original file line number Diff line number Diff line change
@@ -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")))
18 changes: 18 additions & 0 deletions updater/scripts/api-requests-by-user.sh
Original file line number Diff line number Diff line change
@@ -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) }'
2 changes: 2 additions & 0 deletions updater/update-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b734a91

Please sign in to comment.