This exporter exposes Prometheus metrics for a list of pre-configured GitHub repositories. The focus is on providing more insights about issues, pull requests and milestones.
It uses GitHub's API v4 and tries its best to not exceed the request quotas, but for large repositories (5k+ PRs) it's recommended to tweak the settings a bit.
The goal of this particular exporter is to provide metrics for all pull requests, issues and milestones (collectively called "items" from here on) within a given set of repositories. At the same time, open items should be refreshed much more often and quickly than older data.
To achieve this, the exporter upon startup scans all repositories for all items. After this is complete, it will
- fetch the most recently updated 100 items (to detect new elements and elements whose status has changed),
- re-fetch all open items frequently (every 5 minutes by default) and
- re-fetch all items every 12 hours by default.
While the scheduling for the re-fetches happens concurrently in multiple go routines, the fetching itself is done sequentially to avoid triggering GitHub's anti-abuse system.
Fetching open items has higher priority, so that even large amounts of old items cannot interfere with the freshness of open items.
It is possible to limit the initial scan (using -pr-depth, -issue-depth and -milestone-depth),
so that for very large repositories not all items are fetched. But this only limits the
initial scan, over time the exporter will learn about new items and not forget the old ones
(and since it always keeps all items up-to-date, the number of items fetched will slooooowly
over time grow).
Jobs are always removed from the queue, even if they failed. The exporter relies on the goroutines to re-schedule them later anyway, and this prevents flooding GitHub when the API has issues or misconfiguration occurs. Job queues can only contain one job per kind, so even if the API is down for an hour, the queue will not fill up with the re-fetch job.
You need Go 1.14 installed on your machine.
go get go.xrstf.de/github_exporter
A Docker image is available as xrstf/github_exporter.
You need an OAuth2 token to authenticate against the API. Make it available
as the GITHUB_TOKEN environment variable.
By default, the exporter listens on 0.0.0.0:9612.
All configuration happens via commandline arguments. At the bare minimum, you need to specify a single repository to scrape:
./github_exporter -repo myself/my-repository
You can configure multiple -repo (which is also recommended over running the exporter
multiple times in parallel, so a single exporter can serialize all API requests) and
tweak the exporter further using the available flags:
Usage of ./github_exporter:
-debug
enable more verbose logging
-issue-depth int
max number of issues to fetch per repository upon startup (-1 disables the limit, 0 disables issue fetching entirely) (default -1)
-issue-refresh-interval duration
time in between issue refreshes (default 5m0s)
-issue-resync-interval duration
time in between full issue re-syncs (default 12h0m0s)
-listen string
address and port to listen on (default ":9612")
-milestone-depth int
max number of milestones to fetch per repository upon startup (-1 disables the limit, 0 disables milestone fetching entirely) (default -1)
-milestone-refresh-interval duration
time in between milestone refreshes (default 5m0s)
-milestone-resync-interval duration
time in between full milestone re-syncs (default 12h0m0s)
-pr-depth int
max number of pull requests to fetch per repository upon startup (-1 disables the limit, 0 disables PR fetching entirely) (default -1)
-pr-refresh-interval duration
time in between PR refreshes (default 5m0s)
-pr-resync-interval duration
time in between full PR re-syncs (default 12h0m0s)
-realnames
use usernames instead of internal IDs for author labels (this will make metrics contain personally identifiable information)
-repo value
repository (owner/name format) to include, can be given multiple times
-owner string
github login (username or organization) of the owner of the repositories that will be included. Excludes forked and locked repo, includes 100 first private & public repos
All metrics are labelled with repo=(full repo name), for example
repo="xrstf/github_exporter".
For each repository, the following metrics are available:
github_exporter_repo_disk_usage_bytesgithub_exporter_repo_forksgithub_exporter_repo_stargazersgithub_exporter_repo_watchersgithub_exporter_repo_is_privategithub_exporter_repo_is_archivedgithub_exporter_repo_is_disabledgithub_exporter_repo_is_forkgithub_exporter_repo_is_lockedgithub_exporter_repo_is_mirrorgithub_exporter_repo_is_templategithub_exporter_repo_language_size_bytesis additionally labelled withlanguage.
For pull requests, these metrics are available:
-
github_exporter_pr_infocontains lots of metadata labels and always has a constant value of1. Labels are:numberis the PR's number.stateis one ofopen,closedormerged.authoris the author ID (or username if-realnamesis configured).
In addition, the exporter recognizes a few common label conventions, namely:
size/*is reflected as asizelabel (e.g. thesize/xslabel on GitHub becomes asize="xs"label on the Prometheus metric).team/*is reflected as ateamlabel.kind/*is reflected as akindlabel.priority/*is reflected as aprioritylabel.approvedis reflected as a booleanapprovedlabel.lgtmis reflected as a booleanlgtmlabel.do-no-merge/*is reflected as a booleanpendinglabel.
-
github_exporter_pr_label_countis the number of PRs that have a given label and state. This counts all labels individually, not just those recognized for the_infometric. -
github_exporter_pr_created_atis the UNIX timestamp of when the PR was created on GitHub. This metric only hasrepoandnumberlabels. -
github_exporter_pr_updated_atis the UNIX timestamp of when the PR was last updated on GitHub. This metric only hasrepoandnumberlabels. -
github_exporter_pr_fetched_atis the UNIX timestamp of when the PR was last fetched from the GitHub API. This metric only hasrepoandnumberlabels.
The PR metrics are mirrored for issues:
github_exporter_issue_infogithub_exporter_issue_label_countgithub_exporter_issue_created_atgithub_exporter_issue_updated_atgithub_exporter_issue_fetched_at
The metrics for milestones are similar:
github_exporter_milestone_infohasrepo,number,titleandstatelabels.github_exporter_milestone_issuescounts the number of open/closed issues/PRs for a given milestone, so it hasrepo,number,kind(issue or pullrequest) andstatelabels.github_exporter_milestone_created_atgithub_exporter_milestone_updated_atgithub_exporter_milestone_fetched_atgithub_exporter_milestone_closed_atis optional and 0 if the milestone is open.github_exporter_milestone_due_onis optional and 0 if no due date is set.
And a few more metrics for monitoring the exporter itself are available as well:
github_exporter_pr_queue_sizeis the number of PRs currently queued for being fetched from the API. This is split via thequeuelabel intopriority(open PRs) andregular(older PRs).github_exporter_issue_queue_sizeis the same as for the PR queue.github_exporter_milestone_queue_sizeis the same as for the PR queue.github_exporter_api_requests_totalcounts the number of API requests per repository.github_exporter_api_costs_totalis the sum of costs (in API points) that have been used, grouped byrepo.github_exporter_api_points_remainingis a gauge representing the remaining API points. 5k points can be consumed per hour, with resets after 1 hour.
If you plan on performing long-term analysis over repositories, make sure to put proper recording rules into place so that queries can be performed quickly. The exporter intentionally does not pre-aggregate most things, as to not spam Prometheus or restrict the available information.
A few example rules can be found in contrib/prometheus/rules.yaml.
MIT
