Skip to content

Additional fields for runners and workflows #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you want to monitor a public repository, you must put the public_repo option
| Exporter port | port, p | PORT | 9999 | Exporter port |
| Github Api URL | github_api_url, url | GITHUB_API_URL | api.github.com | Github API URL (primarily for Github Enterprise usage) |
| Github Enterprise Name | enterprise_name | ENTERPRISE_NAME | "" | Enterprise name. Needed for enterprise endpoints (/enterprises/{ENTERPRISE_NAME}/*). Currently used to get Enterprise level tunners status |
| Fields to export | export_fields | EXPORT_FIELDS | repo,id,node_id,head_branch,head_sha,run_number,workflow_id,workflow,event,status | A comma separated list of fields for workflow metrics that should be exported |
| Fields to export | export_fields | EXPORT_FIELDS | repo,id,node_id,head_branch,head_sha,run_number,workflow_id,workflow,event,status,created_at,updated_at,conclusion | A comma separated list of fields for workflow metrics that should be exported |

## Exported stats

Expand Down Expand Up @@ -49,6 +49,9 @@ Gauge type
| workflow_id | Workflow ID |
| workflow | Workflow Name |
| status | Workflow status (completed/in_progress) |
| created_at | Workflow run creation timestamp |
| updated_at | Workflow run update timestamp |
| conclusion | Result of workflow run |

### github_workflow_run_duration_ms
Gauge type
Expand All @@ -72,6 +75,10 @@ Gauge type
| workflow_id | Workflow ID |
| workflow | Workflow Name |
| status | Workflow status (completed/in_progress) |
| created_at | Workflow run creation timestamp |
| updated_at | Workflow run update timestamp |
| conclusion | Result of workflow run |


### github_job
> :warning: **This is a duplicate of the `github_workflow_run_status` metric that will soon be deprecated, do not use anymore.**
Expand Down Expand Up @@ -136,6 +143,7 @@ Gauge type
| id | Runner id (incremental id) |
| name | Runner name |
| os | Operating system (linux/macos/windows) |
| status | Runner status (busy/idle) |

### github_workflow_usage_seconds
Gauge type
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github-actions-exporter
go 1.16

require (
github.com/fasthttp/router v1.3.9 // indirect
github.com/google/go-github/v33 v33.0.1-0.20210311004518-0540c33dca8b // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/fasthttp/router v1.3.9
github.com/google/go-github/v33 v33.0.1-0.20210311004518-0540c33dca8b
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/client_golang v1.9.0 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/valyala/fasthttp v1.22.0 // indirect
golang.org/x/oauth2 v0.0.0-20210311163135-5366d9dc1934 // indirect
github.com/prometheus/client_golang v1.9.0
github.com/urfave/cli/v2 v2.3.0
github.com/valyala/fasthttp v1.22.0
golang.org/x/oauth2 v0.0.0-20210311163135-5366d9dc1934
)
10 changes: 7 additions & 3 deletions pkg/metrics/get_runners_enterprise_from_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"github-actions-exporter/pkg/config"
"log"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -16,12 +15,13 @@ var (
Name: "github_runner_enterprise_status",
Help: "runner status",
},
[]string{"os", "name", "id"},
[]string{"os", "name", "status"},
)
)

func getRunnersEnterpriseFromGithub() {
for {
runnersEnterpriseGauge.Reset()
runners, _, err := client.Enterprise.ListRunners(context.Background(), config.EnterpriseName, nil)
if err != nil {
log.Printf("Enterprise.ListRunners error: %s", err.Error())
Expand All @@ -31,7 +31,11 @@ func getRunnersEnterpriseFromGithub() {
if integerStatus = 0; runner.GetStatus() == "online" {
integerStatus = 1
}
runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10)).Set(integerStatus)
var status string
if status = "idle"; *runner.Busy == true {
status = "busy"
}
runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, status).Set(integerStatus)
}
}
time.Sleep(time.Duration(config.Github.Refresh) * time.Second)
Expand Down
6 changes: 6 additions & 0 deletions pkg/metrics/get_workflow_runs_from_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func getFieldValue(repo string, run github.WorkflowRun, field string) string {
return *run.Event
case "status":
return *run.Status
case "conclusion":
return run.GetConclusion()
case "created_at":
return run.CreatedAt.Format(time.RFC3339)
case "updated_at":
return run.UpdatedAt.Format(time.RFC3339)
}
return ""
}
Expand Down