/
metrics.go
118 lines (98 loc) · 4.56 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package server
import "github.com/prometheus/client_golang/prometheus"
var (
workflowJobHistogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "workflow_job_duration_seconds",
Help: "Time that a workflow job took to reach a given state.",
Buckets: prometheus.ExponentialBuckets(1, 1.4, 30),
},
[]string{"org", "repo", "state", "runner_group", "workflow_name", "job_name"},
)
workflowJobDurationCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "workflow_job_duration_seconds_total",
Help: "The total duration of jobs.",
},
[]string{"org", "repo", "status", "conclusion", "runner_group", "workflow_name", "job_name"},
)
workflowJobStatusCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "workflow_job_status_count",
Help: "Count of workflow job events.",
},
[]string{"org", "repo", "status", "conclusion", "runner_group", "workflow_name", "job_name"},
)
workflowRunHistogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "workflow_execution_time_seconds",
Help: "Time that a workflow took to run.",
Buckets: prometheus.ExponentialBuckets(1, 1.4, 30),
},
[]string{"org", "repo", "workflow_name", "conclusion"},
)
workflowRunStatusCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "workflow_status_count",
Help: "Count of the occurrences of different workflow states.",
},
[]string{"org", "repo", "status", "conclusion", "workflow_name"},
)
totalMinutesUsedActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_minutes_used_minutes",
Help: "Total minutes used for the GitHub Actions.",
},
[]string{"org", "user"},
)
includedMinutesUsedActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_included_minutes",
Help: "Included Minutes for the GitHub Actions.",
},
[]string{"org", "user"},
)
totalPaidMinutesActions = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "actions_total_paid_minutes",
Help: "Paid Minutes for the GitHub Actions.",
},
[]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() {
// Register metrics with prometheus
prometheus.MustRegister(workflowJobHistogramVec)
prometheus.MustRegister(workflowJobStatusCounter)
prometheus.MustRegister(workflowJobDurationCounter)
prometheus.MustRegister(workflowRunHistogramVec)
prometheus.MustRegister(workflowRunStatusCounter)
prometheus.MustRegister(totalMinutesUsedActions)
prometheus.MustRegister(includedMinutesUsedActions)
prometheus.MustRegister(totalPaidMinutesActions)
prometheus.MustRegister(totalMinutesUsedByHostTypeActions)
}
type WorkflowObserver interface {
ObserveWorkflowJobDuration(org, repo, state, runnerGroup, workflowName, jobName string, seconds float64)
CountWorkflowJobStatus(org, repo, status, conclusion, runnerGroup, workflowName, jobName string)
CountWorkflowJobDuration(org, repo, status, conclusion, runnerGroup, workflowName, jobName string, seconds float64)
ObserveWorkflowRunDuration(org, repo, workflow, conclusion string, seconds float64)
CountWorkflowRunStatus(org, repo, status, conclusion, workflow string)
}
var _ WorkflowObserver = (*PrometheusObserver)(nil)
type PrometheusObserver struct{}
func (o *PrometheusObserver) ObserveWorkflowJobDuration(org, repo, state, runnerGroup, workflowName, jobName string, seconds float64) {
workflowJobHistogramVec.WithLabelValues(org, repo, state, runnerGroup, workflowName, jobName).
Observe(seconds)
}
func (o *PrometheusObserver) CountWorkflowJobStatus(org, repo, status, conclusion, runnerGroup, workflowName, jobName string) {
workflowJobStatusCounter.WithLabelValues(org, repo, status, conclusion, runnerGroup, workflowName, jobName).Inc()
}
func (o *PrometheusObserver) CountWorkflowJobDuration(org, repo, status, conclusion, runnerGroup, workflowName, jobName string, seconds float64) {
workflowJobDurationCounter.WithLabelValues(org, repo, status, conclusion, runnerGroup, workflowName, jobName).Add(seconds)
}
func (o *PrometheusObserver) ObserveWorkflowRunDuration(org, repo, workflowName, conclusion string, seconds float64) {
workflowRunHistogramVec.WithLabelValues(org, repo, workflowName, conclusion).
Observe(seconds)
}
func (o *PrometheusObserver) CountWorkflowRunStatus(org, repo, status, conclusion, workflowName string) {
workflowRunStatusCounter.WithLabelValues(org, repo, status, conclusion, workflowName).Inc()
}