Skip to content

Commit f1490ed

Browse files
committed
add metrics reports
1 parent 165b28e commit f1490ed

14 files changed

+312
-4
lines changed

sql/README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,28 @@ The `audit` folder has queries that are all around auditing credentials, webhook
1818
- `user-emails.sql` - A report of all emails that don't match a list of approved domains you define in the `WHERE` clause. This query should be deprecated by [this issue](https://github.com/github/roadmap/issues/204).
1919
- `user-ssh-keys.sql` - A report of all user SSH keys, when it was last used, when it was set up, and how long the key is.
2020

21+
## Metrics queries
22+
23+
The `metrics` folder has queries that are all around usage of various features in GitHub Enterprise Server.
24+
25+
- `actions-summary.sql` - A monthly summary of runtime hours, seconds waiting in queue before dispatch, and job count for GitHub Actions usage.
26+
- `commit-count.sql` - This pulls a "high score" report of all users, all commits, from all time.
27+
- `count-tabs.sql` - A report of the custom tabs users put in their repositories.
28+
- `issue-report.sql` - A report of active issues within the past X days.
29+
- `linguist-report.sql` - This returns the "size" of each language in each repository and when the repo was last updated. This can be a very large report.
30+
- `linguist-stats.sql` - This returns the count of repositories containing each language and a sum "size" of code in that language for all repos pushed to in the past year. The time limit is adjustable.
31+
- `most-recent-active-repos.sql` - A list of repositories, when they were last updated, who owns them, and the disk space associated with each.
32+
- `pr-report.sql` - This pulls a report of pull requests including the repo name, user name, files included, times it was created/updated/merged, and comments. It can filter by organization or return all PRs in GHES.
33+
- `prereceive-hooks.sql` - A list of pre-receive hooks that are enabled by each repository and who owns the repo.
34+
- `public-repo-owners.sql` - A list of all users or orgs who own repositories marked as "public", a count of public repos, and the user or org email address.
35+
- `reaction-stats.sql` - A count of the reactions used in GHES for trivia.
36+
- `staff-notes.sql` - Returns a list of organizations or users with `staff_notes`.
37+
- `user-report.sql` - Returns username, id, created/suspended date, issues created for all time and in the past 30 days, number of repos owned, and how many pull requests they've opened.
38+
2139
## Security queries
2240

2341
The `security` folder has queries that are all around dependency alerts and any other security features.
2442

2543
- `active-repo-report.sql` - A list of all detected HIGH and CRITICAL vulnerabilities from repos pushed to in the past 90 days. It also returns who owns it and further details on the exact vulnerability. The threshold of time and severity to return is adjustable.
2644
- `vuln-critical-count.sql` - A count of repositories affected by each CRITICAL vulnerability.
2745
- `vuln-report.sql` - A report of all detected vulnerabilities in every single repo in GHES, who owns it, when it was last pushed to, the platform of the vulnerability, and the GHSA/MITRE/WhiteSource info on it. This can be a very large report.
28-
29-
## Usage queries
30-
31-
The `usage` folder has queries that are all around usage of various features in GitHub Enterprise Server.

sql/metrics/actions-summary.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This query generates a monthly summary of runtime hours, seconds waiting
3+
* in queue before dispatch, and job count for GitHub Actions usage.
4+
*/
5+
SELECT
6+
month(j.completed_at) as month,
7+
year(j.completed_at) as year,
8+
round(
9+
sum(
10+
unix_timestamp(j.completed_at) - unix_timestamp(
11+
coalesce(j.started_at, j.queued_at, j.created_at)
12+
)
13+
) / 3600
14+
) as compute_hours,
15+
round(
16+
avg(
17+
unix_timestamp(j.started_at) - unix_timestamp(j.queued_at)
18+
)
19+
) as seconds_queued,
20+
count(j.completed_at) as job_count
21+
FROM
22+
github_enterprise.workflow_builds j
23+
GROUP BY
24+
month,
25+
year
26+
ORDER BY
27+
year,
28+
month

sql/metrics/commit-count.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* This pulls a "high score" report of all users, all commits, from all time.
3+
*/
4+
SELECT
5+
u.login,
6+
SUM(commit_count)
7+
FROM
8+
github_enterprise.commit_contributions c
9+
JOIN github_enterprise.users u ON
10+
u.id = c.user_id
11+
GROUP BY
12+
user_id
13+
ORDER BY
14+
COUNT(c.user_id) DESC;

sql/metrics/count-tabs.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* These are custom tabs set by a repository owner that show up to their users.
3+
*/
4+
SELECT
5+
t.anchor as name,
6+
t.url,
7+
t.created_at,
8+
t.updated_at,
9+
r.name as repo_name,
10+
u.login as owner_name,
11+
u.type as owner_type
12+
FROM
13+
github_enterprise.tabs t
14+
JOIN github_enterprise.repositories r ON
15+
t.repository_id = r.id
16+
JOIN github_enterprise.users u ON
17+
r.owner_id = u.id;

sql/metrics/issue-report.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* This query returns a report of active issues within the past X days.
3+
*/
4+
SELECT
5+
r.name as repo_name,
6+
u.login as created_by,
7+
v.login as assigned_to,
8+
i.state as issue_state,
9+
i.created_at,
10+
i.updated_at,
11+
i.closed_at,
12+
i.issue_comments_count,
13+
DATEDIFF(i.closed_at, i.created_at) as days_open
14+
FROM
15+
github_enterprise.issues i
16+
LEFT JOIN github_enterprise.users u ON
17+
i.user_id = u.id
18+
LEFT JOIN github_enterprise.users v ON
19+
i.assignee_id = v.id
20+
INNER JOIN github_enterprise.repositories r ON
21+
i.repository_id = r.id
22+
WHERE
23+
DATEDIFF(NOW(), i.created_at) <= 365
24+
ORDER BY
25+
days_open DESC;

sql/metrics/linguist-report.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* This lists the "size" of each language in each repository and when the repo
3+
* was last updated.
4+
*/
5+
SELECT
6+
r.name,
7+
l.updated_at,
8+
l.public,
9+
l.size,
10+
n.name
11+
FROM
12+
github_enterprise.languages l
13+
JOIN github_enterprise.language_names n ON
14+
l.language_name_id = n.id
15+
JOIN github_enterprise.repositories r ON
16+
l.repository_id = r.id;

sql/metrics/linguist-stats.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This pulls the number of repositories containing any individual language
3+
* that have been pushed to in the past year.
4+
*
5+
* If you comment out the WHERE clause, it'll return the stats for your server
6+
* for all time.
7+
*/
8+
SELECT
9+
n.name as language_name,
10+
COUNT(l.language_name_id) as repo_count,
11+
ROUND(SUM(l.size) /(1024 * 1024)) as language_size_mb
12+
FROM
13+
github_enterprise.languages l
14+
JOIN github_enterprise.language_names n ON l.language_name_id = n.id
15+
JOIN github_enterprise.repositories r ON l.repository_id = r.id
16+
WHERE
17+
r.id IN (
18+
SELECT
19+
r.id
20+
FROM
21+
github_enterprise.repositories r
22+
WHERE
23+
DATEDIFF(NOW(), r.updated_at) < 365
24+
)
25+
GROUP BY
26+
language_name_id
27+
ORDER BY
28+
COUNT(l.language_name_id) DESC;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* This pulls a list of repositories, when they were last updated, who owns
3+
* them, and the disk space associated with each.
4+
*/
5+
SELECT
6+
r.name as repo_name,
7+
r.updated_at,
8+
r.disk_usage,
9+
u.login
10+
FROM
11+
github_enterprise.repositories r
12+
JOIN github_enterprise.users u ON
13+
r.owner_id = u.id
14+
ORDER BY
15+
updated_at DESC;

sql/metrics/pr-report.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This pulls a report of pull requests including the repo name, user name,
3+
* files included, times it was created/updated/merged, and comments.
4+
*
5+
* If you know the organization ID you're interested in, uncomment and put it
6+
* in line 27 to filter this to a specific org. Otherwise, this query returns
7+
* all pull requests in GitHub Enterprise Server.
8+
*/
9+
SELECT
10+
r.name,
11+
u.login,
12+
path as filename,
13+
p.id as pr_id,
14+
p.created_at as created_time,
15+
p.updated_at as updated_time,
16+
p.merged_at as merged_time,
17+
CONVERT(body
18+
USING utf8) as comment
19+
FROM
20+
github_enterprise.pull_request_review_comments c
21+
JOIN github_enterprise.users u ON
22+
u.id = c.user_id
23+
JOIN github_enterprise.pull_requests p ON
24+
p.id = c.pull_request_id
25+
JOIN github_enterprise.repositories r ON
26+
r.id = c.repository_id
27+
-- WHERE r.owner_id = (org id here)
28+
;

sql/metrics/prereceive-hooks.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* This returns a list of pre-receive hooks that are enabled by each repository
3+
* and who owns the repo.
4+
*/
5+
SELECT
6+
h.name as hook_name,
7+
r.name as repo_name,
8+
u.login as owner_name
9+
FROM
10+
github_enterprise.pre_receive_hook_targets t
11+
JOIN github_enterprise.pre_receive_hooks h ON
12+
h.id = t.hook_id
13+
JOIN github_enterprise.repositories r ON
14+
r.id = t.hookable_id
15+
JOIN github_enterprise.users u ON
16+
r.owner_id = u.id;

0 commit comments

Comments
 (0)