Skip to content

Commit

Permalink
add actions_total_minutes_used_by_host_minutes metric (#75)
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Mar 10, 2023
1 parent 9ee4f62 commit 23ac198
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 12 additions & 0 deletions internal/server/billing_metrics_exporter.go
Expand Up @@ -92,6 +92,12 @@ func (c *BillingMetricsExporter) collectOrgBilling(ctx context.Context) {
totalMinutesUsedActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(actionsBilling.TotalMinutesUsed)
includedMinutesUsedActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(actionsBilling.IncludedMinutes)
totalPaidMinutesActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(actionsBilling.TotalPaidMinutesUsed)

for host, minutes := range actionsBilling.MinutesUsedBreakdown {
totalMinutesUsedByHostTypeActions.WithLabelValues(c.Opts.GitHubOrg, "", host).Set(float64(minutes))
}

// TODO: deprecate
totalMinutesUsedUbuntuActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(float64(actionsBilling.MinutesUsedBreakdown["UBUNTU"]))
totalMinutesUsedMacOSActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(float64(actionsBilling.MinutesUsedBreakdown["MACOS"]))
totalMinutesUsedWindowsActions.WithLabelValues(c.Opts.GitHubOrg, "").Set(float64(actionsBilling.MinutesUsedBreakdown["WINDOWS"]))
Expand All @@ -107,6 +113,12 @@ func (c *BillingMetricsExporter) collectUserBilling(ctx context.Context) {
totalMinutesUsedActions.WithLabelValues("", c.Opts.GitHubUser).Set(actionsBilling.TotalMinutesUsed)
includedMinutesUsedActions.WithLabelValues("", c.Opts.GitHubUser).Set(actionsBilling.IncludedMinutes)
totalPaidMinutesActions.WithLabelValues("", c.Opts.GitHubUser).Set(actionsBilling.TotalPaidMinutesUsed)

for host, minutes := range actionsBilling.MinutesUsedBreakdown {
totalMinutesUsedByHostTypeActions.WithLabelValues("", c.Opts.GitHubUser, host).Set(float64(minutes))
}

// TODO: deprecate
totalMinutesUsedUbuntuActions.WithLabelValues("", c.Opts.GitHubUser).Set(float64(actionsBilling.MinutesUsedBreakdown["UBUNTU"]))
totalMinutesUsedMacOSActions.WithLabelValues("", c.Opts.GitHubUser).Set(float64(actionsBilling.MinutesUsedBreakdown["MACOS"]))
totalMinutesUsedWindowsActions.WithLabelValues("", c.Opts.GitHubUser).Set(float64(actionsBilling.MinutesUsedBreakdown["WINDOWS"]))
Expand Down
14 changes: 11 additions & 3 deletions internal/server/metrics.go
Expand Up @@ -63,24 +63,31 @@ var (

totalMinutesUsedUbuntuActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_minutes_used_ubuntu_minutes",
Help: "Total minutes used for Ubuntu type for the GitHub Actions.",
Help: "Total minutes used for Ubuntu type for the GitHub Actions. To be deprecate, use actions_total_minutes_used_by_host_minutes",
},
[]string{"org", "user"},
)

totalMinutesUsedMacOSActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_minutes_used_macos_minutes",
Help: "Total minutes used for MacOS type for the GitHub Actions.",
Help: "Total minutes used for MacOS type for the GitHub Actions. To be deprecate, use actions_total_minutes_used_by_host_minutes",
},
[]string{"org", "user"},
)

totalMinutesUsedWindowsActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_minutes_used_windows_minutes",
Help: "Total minutes used for Windows type for the GitHub Actions.",
Help: "Total minutes used for Windows type for the GitHub Actions. To be deprecate, use actions_total_minutes_used_by_host_minutes",
},
[]string{"org", "user"},
)

totalMinutesUsedByHostTypeActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_minutes_used_by_host_minutes",
Help: "Total minutes used for a specific host type for the GitHub Actions.",
},
[]string{"org", "user", "host_type"},
)
)

func init() {
Expand All @@ -96,6 +103,7 @@ func init() {
prometheus.MustRegister(totalMinutesUsedUbuntuActions)
prometheus.MustRegister(totalMinutesUsedMacOSActions)
prometheus.MustRegister(totalMinutesUsedWindowsActions)
prometheus.MustRegister(totalMinutesUsedByHostTypeActions)
}

type WorkflowObserver interface {
Expand Down

0 comments on commit 23ac198

Please sign in to comment.