Skip to content

Commit

Permalink
Merge pull request #184 from promhippie/admin-stats
Browse files Browse the repository at this point in the history
Integrate admin stats, fix runner metrics, use getter functions
  • Loading branch information
tboerger authored Mar 23, 2023
2 parents a9933be + 415b559 commit 8004a3c
Show file tree
Hide file tree
Showing 16 changed files with 1,020 additions and 238 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ The following sections list the changes for unreleased.

## Summary

* Fix #184: Set right name/owner labels for runner metrics
* Enh #123: Add metrics for GitHub runners
* Enh #123: Add metrics for GitHub workflows
* Enh #174: Merge all billing related metrics
* Enh #174: Update all releated dependencies
* Enh #183: Integrate admin stats for GitHub enterprise
* Enh #184: Use getter functions to get values

## Details

* Bugfix #184: Set right name/owner labels for runner metrics

We introduced metrics for GitHub self-hosted runners but we missed some important labels as
remaining todos. With this change this gets corrected to properly show the
repo/org/enterprise where the runner have been attached to.

https://github.com/promhippie/github_exporter/pull/184

* Enhancement #123: Add metrics for GitHub runners

We've added new metrics for selfhosted runners used per repo, org or enterprise to give the
Expand Down Expand Up @@ -39,6 +50,23 @@ The following sections list the changes for unreleased.

https://github.com/promhippie/github_exporter/pull/174

* Enhancement #183: Integrate admin stats for GitHub enterprise

We've integrated another collector within this exporter to provide admin stats as metrics to
get a general overview about the amount of repos, issues, pull requests and so on. Special
thanks for the great initial work by @mafrosis, your effort is highly appreciated.

https://github.com/promhippie/github_exporter/issues/183
https://github.com/promhippie/github_exporter/pull/23

* Enhancement #184: Use getter functions to get values

To reduce the used boilerplate code and to better use the GitHub library we have updated most of
the available collectors to simply use the provided getter functions instead of checking for
nil values everywhere on our own.

https://github.com/promhippie/github_exporter/pull/184


# Changelog for 1.2.0

Expand Down
9 changes: 9 additions & 0 deletions changelog/unreleased/admin-stats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Enhancement: Integrate admin stats for GitHub enterprise

We've integrated another collector within this exporter to provide admin stats
as metrics to get a general overview about the amount of repos, issues, pull
requests and so on. Special thanks for the great initial work by @mafrosis, your
effort is highly appreciated.

https://github.com/promhippie/github_exporter/issues/183
https://github.com/promhippie/github_exporter/pull/23
7 changes: 7 additions & 0 deletions changelog/unreleased/runner-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Set right name/owner labels for runner metrics

We introduced metrics for GitHub self-hosted runners but we missed some
important labels as remaining todos. With this change this gets corrected to
properly show the repo/org/enterprise where the runner have been attached to.

https://github.com/promhippie/github_exporter/pull/184
File renamed without changes.
7 changes: 7 additions & 0 deletions changelog/unreleased/use-getters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Use getter functions to get values

To reduce the used boilerplate code and to better use the GitHub library we have
updated most of the available collectors to simply use the provided getter
functions instead of checking for nil values everywhere on our own.

https://github.com/promhippie/github_exporter/pull/184
3 changes: 3 additions & 0 deletions docs/partials/envvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ GITHUB_EXPORTER_ORG, GITHUB_EXPORTER_ORGS
GITHUB_EXPORTER_REPO, GITHUB_EXPORTER_REPOS
: Repositories to scrape metrics from, comma-separated list

GITHUB_EXPORTER_COLLECTOR_ADMIN
: Enable collector for admin stats, defaults to `false`

GITHUB_EXPORTER_COLLECTOR_ORGS
: Enable collector for orgs, defaults to `true`

Expand Down
102 changes: 102 additions & 0 deletions docs/partials/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,108 @@ github_action_billing_minutes_used_breakdown{type, name, os}
github_action_billing_paid_minutes{type, name}
: Total paid minutes used for this type

github_admin_comments_commit{}
: Number of commit comments

github_admin_comments_gist{}
: Number of gist comments

github_admin_comments_issue{}
: Number of issue comments

github_admin_comments_pull_request{}
: Number of pull request comments

github_admin_gists_private{}
: Number of private gists

github_admin_gists_public{}
: Number of public gists

github_admin_gists_total{}
: Total number of gists

github_admin_hooks_active{}
: Number of active hooks

github_admin_hooks_inactive{}
: Number of inactive hooks

github_admin_hooks_total{}
: Total number of hooks

github_admin_issues_closed{}
: Number of closed issues

github_admin_issues_open{}
: Number of open issues

github_admin_issues_total{}
: Total number of issues

github_admin_milestones_closed{}
: Number of closed milestones

github_admin_milestones_open{}
: Number of open milestones

github_admin_milestones_total{}
: Total number of milestones

github_admin_orgs_disabled{}
: Number of disabled organizations

github_admin_orgs_members{}
: Number of organization team members

github_admin_orgs_teams{}
: Number of organization teams

github_admin_orgs_total{}
: Total number of organizations

github_admin_pages_total{}
: Total number of pages

github_admin_pulls_mergeable{}
: Number of mergeable pull requests

github_admin_pulls_merged{}
: Number of merged pull requests

github_admin_pulls_total{}
: Total number of pull requests

github_admin_pulls_unmergeable{}
: Number of unmergeable pull requests

github_admin_repos_fork{}
: Number of fork repositories

github_admin_repos_org{}
: Number of organization repos

github_admin_repos_pushes_total{}
: Total number of pushes

github_admin_repos_root{}
: Number of root repositories

github_admin_repos_total{}
: Total number of repositories

github_admin_repos_wikis_total{}
: Total number of wikis

github_admin_users_admin{}
: Number of admin users

github_admin_users_suspended{}
: Number of suspended users

github_admin_users_total{}
: Total number of users

github_org_collaborators{name}
: Number of collaborators within org

Expand Down
5 changes: 5 additions & 0 deletions hack/generate-metrics-docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type metric struct {
func main() {
collectors := make([]*prometheus.Desc, 0)

collectors = append(
collectors,
exporter.NewAdminCollector(nil, nil, nil, nil, config.Load().Target).Metrics()...,
)

collectors = append(
collectors,
exporter.NewOrgCollector(nil, nil, nil, nil, config.Load().Target).Metrics()...,
Expand Down
14 changes: 14 additions & 0 deletions pkg/action/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ func handler(cfg *config.Config, logger log.Logger, client *github.Client) *chi.
mux.Use(middleware.Timeout)
mux.Use(middleware.Cache)

if cfg.Collector.Admin {
level.Debug(logger).Log(
"msg", "Admin collector registered",
)

registry.MustRegister(exporter.NewAdminCollector(
logger,
client,
requestFailures,
requestDuration,
cfg.Target,
))
}

if cfg.Collector.Orgs {
level.Debug(logger).Log(
"msg", "Org collector registered",
Expand Down
7 changes: 7 additions & 0 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ func RootFlags(cfg *config.Config) []cli.Flag {
EnvVars: []string{"GITHUB_EXPORTER_REPO", "GITHUB_EXPORTER_REPOS"},
Destination: &cfg.Target.Repos,
},
&cli.BoolFlag{
Name: "collector.admin",
Value: false,
Usage: "Enable collector for admin stats",
EnvVars: []string{"GITHUB_EXPORTER_COLLECTOR_ADMIN"},
Destination: &cfg.Collector.Admin,
},
&cli.BoolFlag{
Name: "collector.orgs",
Value: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Target struct {

// Collector defines the collector specific configuration.
type Collector struct {
Admin bool
Orgs bool
Repos bool
Billing bool
Expand Down
Loading

0 comments on commit 8004a3c

Please sign in to comment.