-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
user requests | ||
Alpha 1500 | ||
Bravo 500 | ||
Charlie 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters