这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
ARG GOLANG_VERSION=1.22.7
FROM golang:${GOLANG_VERSION} AS build
ARG GOLANG_VERSION=1.25.3
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} AS build
LABEL maintainer="githubexporter"

ENV GO111MODULE=on
ARG TARGETOS
ARG TARGETARCH

COPY ./ /go/src/github.com/githubexporter/github-exporter
WORKDIR /go/src/github.com/githubexporter/github-exporter

RUN go mod download \
&& go test ./... \
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/main
&& CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /bin/main

FROM gcr.io/distroless/static AS runtime

ADD VERSION .
COPY --from=build /bin/main /bin/main
ENV LISTEN_PORT=9171
EXPOSE 9171
EXPOSE $LISTEN_PORT
ENTRYPOINT [ "/bin/main" ]
37 changes: 24 additions & 13 deletions METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,51 @@ Below are an example of the metrics as exposed by this exporter.
```
# HELP github_rate_limit Number of API queries allowed in a 60 minute window
# TYPE github_rate_limit gauge
github_rate_limit 5000
github_rate_limit{resource="code_search"} 60
github_rate_limit{resource="core"} 60
github_rate_limit{resource="graphql"} 0
github_rate_limit{resource="integration_manifest"} 5000
github_rate_limit{resource="search"} 10
# HELP github_rate_remaining Number of API queries remaining in the current window
# TYPE github_rate_remaining gauge
github_rate_remaining 2801
github_rate_remaining{resource="code_search"} 56
github_rate_remaining{resource="core"} 56
github_rate_remaining{resource="graphql"} 0
github_rate_remaining{resource="integration_manifest"} 5000
github_rate_remaining{resource="search"} 10
# HELP github_rate_reset The time at which the current rate limit window resets in UTC epoch seconds
# TYPE github_rate_reset gauge
github_rate_reset 1.527709029e+09
github_rate_reset{resource="code_search"} 1.760954346e+09
github_rate_reset{resource="core"} 1.760954346e+09
github_rate_reset{resource="graphql"} 1.760954347e+09
github_rate_reset{resource="integration_manifest"} 1.760954347e+09
github_rate_reset{resource="search"} 1.760950807e+09
# HELP github_repo_forks Total number of forks for given repository
# TYPE github_repo_forks gauge
github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 19
github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 129
# HELP github_repo_open_issues Total number of open issues for given repository
# TYPE github_repo_open_issues gauge
github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 7
github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 28
# HELP github_repo_pull_request_count Total number of pull requests for given repository
# TYPE github_repo_pull_request_count gauge
github_repo_pull_request_count{repo="github-exporter",user="githubexporter"} 7
# HELP github_repo_size_kb Size in KB for given repository
# TYPE github_repo_size_kb gauge
github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 41
github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 2185
# HELP github_repo_stars Total number of Stars for given repository
# TYPE github_repo_stars gauge
github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 64
github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 441
# HELP github_repo_watchers Total number of watchers/subscribers for given repository
# TYPE github_repo_watchers gauge
github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 10
# TYPE github_repo_release_downloads gauge
github_repo_release_downloads{name="release1.0.0",repo="github-exporter",user="infinityworks"} 3500
github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 10```
```

<!--

The above output was generated by running:

```
REPOS=infinityworks/github-exporter go run main.go
```

And copying the output of http://localhost:9171/metrics

-->
-->
47 changes: 29 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@ Exposes basic metrics for your repositories from the GitHub API, to a Prometheus

## Configuration

This exporter is setup to take input from environment variables. All variables are optional:

* `ORGS` If supplied, the exporter will enumerate all repositories for that organization. Expected in the format "org1, org2".
* `REPOS` If supplied, The repos you wish to monitor, expected in the format "user/repo1, user/repo2". Can be across different Github users/orgs.
* `USERS` If supplied, the exporter will enumerate all repositories for that users. Expected in
the format "user1, user2".
* `GITHUB_TOKEN` If supplied, enables the user to supply a github authentication token that allows the API to be queried more often. Optional, but recommended.
* `GITHUB_TOKEN_FILE` If supplied _instead of_ `GITHUB_TOKEN`, enables the user to supply a path to a file containing a github authentication token that allows the API to be queried more often. Optional, but recommended.
* `GITHUB_APP` If true , authenticates ass GitHub app to the API.
* `GITHUB_APP_ID` The APP ID of the GitHub App.
* `GITHUB_APP_INSTALLATION_ID` The INSTALLATION ID of the GitHub App.
* `GITHUB_APP_KEY_PATH` The path to the github private key.
* `GITHUB_RATE_LIMIT` The RATE LIMIT that suppose to be for github app (default is 15,000). If the exporter sees the value is below this variable it generating new token for the app.
* `API_URL` Github API URL, shouldn't need to change this. Defaults to `https://api.github.com`
* `LISTEN_PORT` The port you wish to run the container on, the Dockerfile defaults this to `9171`
* `METRICS_PATH` the metrics URL path you wish to use, defaults to `/metrics`
* `LOG_LEVEL` The level of logging the exporter will run with, defaults to `debug`

This exporter is configured via environment variables. All variables are optional unless otherwise stated. Below is a list of supported configuration values:

| Variable | Description | Default |
|------------------------------|------------------------------------------------------------------------------------|--------------------------|
| `ORGS` | Comma-separated list of GitHub organizations to monitor (e.g. `org1,org2`). | |
| `REPOS` | Comma-separated list of repositories to monitor (e.g. `user/repo1,user/repo2`). | |
| `USERS` | Comma-separated list of GitHub users to monitor (e.g. `user1,user2`). | |
| `GITHUB_TOKEN` | GitHub personal access token for API authentication. | |
| `GITHUB_TOKEN_FILE` | Path to a file containing a GitHub personal access token. | |
| `GITHUB_APP` | Set to `true` to authenticate as a GitHub App. | `false` |
| `GITHUB_APP_ID` | The App ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_INSTALLATION_ID` | The Installation ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_KEY_PATH` | Path to the GitHub App private key file. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_RATE_LIMIT_ENABLED` | Whether to fetch GitHub API rate limit metrics (`true` or `false`). | `true` |
| `GITHUB_RESULTS_PER_PAGE` | Number of results to request per page from the GitHub API (max 100). | `100` |
| `API_URL` | GitHub API URL. You should not need to change this unless using GitHub Enterprise. | `https://api.github.com` |
| `LISTEN_PORT` | The port the exporter will listen on. | `9171` |
| `METRICS_PATH` | The HTTP path to expose Prometheus metrics. | `/metrics` |
| `LOG_LEVEL` | Logging level (`debug`, `info`, `warn`, `error`). | `info` |

### Credential Precedence

When authenticating with the GitHub API, the exporter uses credentials in the following order of precedence:

1. **GitHub App credentials** (`GITHUB_APP=true` with `GITHUB_APP_ID`, `GITHUB_APP_INSTALLATION_ID`, and `GITHUB_APP_KEY_PATH`): If enabled, the exporter authenticates as a GitHub App and ignores any personal access token or token file.
2. **Token file** (`GITHUB_TOKEN_FILE`): If a token file is provided (and GitHub App is not enabled), the exporter reads the token from the specified file.
3. **Direct token** (`GITHUB_TOKEN`): If neither GitHub App nor token file is provided, the exporter uses the token supplied directly via the environment variable.

If none of these credentials are provided, the exporter will make unauthenticated requests, which are subject to very strict rate limits.

## Install and deploy

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
2.0.0
Loading
Loading