From 8905263fd7fb0f9c39b2ddb59e6d175c9ad01fb7 Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Mon, 19 Jul 2021 13:27:36 +0300 Subject: [PATCH 1/7] add status field for runners --- pkg/metrics/get_runners_enterprise_from_github.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/metrics/get_runners_enterprise_from_github.go b/pkg/metrics/get_runners_enterprise_from_github.go index ee896b4..2a91238 100644 --- a/pkg/metrics/get_runners_enterprise_from_github.go +++ b/pkg/metrics/get_runners_enterprise_from_github.go @@ -16,7 +16,7 @@ var ( Name: "github_runner_enterprise_status", Help: "runner status", }, - []string{"os", "name", "id"}, + []string{"os", "name", "id", "status"}, ) ) @@ -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, strconv.FormatInt(runner.GetID(), 10), status).Set(integerStatus) } } time.Sleep(time.Duration(config.Github.Refresh) * time.Second) From 2affa40a34702dd54a6b0398b7515da036e0e75a Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Mon, 19 Jul 2021 13:27:47 +0300 Subject: [PATCH 2/7] additional workflow fields --- pkg/metrics/get_workflow_runs_from_github.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/metrics/get_workflow_runs_from_github.go b/pkg/metrics/get_workflow_runs_from_github.go index 9cda6a8..e00d5ce 100644 --- a/pkg/metrics/get_workflow_runs_from_github.go +++ b/pkg/metrics/get_workflow_runs_from_github.go @@ -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 "" } From 3bb8e6e56531d8b3c2f1591b7dd6db0e822dd7b4 Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Mon, 19 Jul 2021 13:28:02 +0300 Subject: [PATCH 3/7] update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a9e772..42c89fa 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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.** @@ -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 From 67a3c9ce8cbb7bc76fe2fb47f2daa67d96f42161 Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Wed, 21 Jul 2021 11:39:58 +0300 Subject: [PATCH 4/7] remove id from enterprise runner metrics --- pkg/metrics/get_runners_enterprise_from_github.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/metrics/get_runners_enterprise_from_github.go b/pkg/metrics/get_runners_enterprise_from_github.go index 2a91238..866b6ed 100644 --- a/pkg/metrics/get_runners_enterprise_from_github.go +++ b/pkg/metrics/get_runners_enterprise_from_github.go @@ -4,7 +4,6 @@ import ( "context" "github-actions-exporter/pkg/config" "log" - "strconv" "time" "github.com/prometheus/client_golang/prometheus" @@ -16,7 +15,7 @@ var ( Name: "github_runner_enterprise_status", Help: "runner status", }, - []string{"os", "name", "id", "status"}, + []string{"os", "name", "status"}, ) ) @@ -35,7 +34,7 @@ func getRunnersEnterpriseFromGithub() { if status = "idle"; *runner.Busy == true { status = "busy" } - runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10), status).Set(integerStatus) + runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, status).Set(integerStatus) } } time.Sleep(time.Duration(config.Github.Refresh) * time.Second) From 2c5a10108b4c9d44ba511c40bc1d71afff9de137 Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Thu, 22 Jul 2021 11:47:27 +0300 Subject: [PATCH 5/7] update go.mod --- go.mod | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index d46bb1a..9eb9350 100644 --- a/go.mod +++ b/go.mod @@ -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 ) From 7fbee1589049c92f3e4955c70d8e772f9b4d2e5d Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Thu, 22 Jul 2021 14:42:40 +0300 Subject: [PATCH 6/7] reset runners gauge --- pkg/metrics/get_runners_enterprise_from_github.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/metrics/get_runners_enterprise_from_github.go b/pkg/metrics/get_runners_enterprise_from_github.go index 866b6ed..c71d081 100644 --- a/pkg/metrics/get_runners_enterprise_from_github.go +++ b/pkg/metrics/get_runners_enterprise_from_github.go @@ -20,6 +20,7 @@ var ( ) func getRunnersEnterpriseFromGithub() { + runnersEnterpriseGauge.Reset() for { runners, _, err := client.Enterprise.ListRunners(context.Background(), config.EnterpriseName, nil) if err != nil { From 212f4a8252d40100dce3b7aeeb35a63a11e7bf86 Mon Sep 17 00:00:00 2001 From: Ruslan Savcenko Date: Thu, 22 Jul 2021 16:13:05 +0300 Subject: [PATCH 7/7] move reset inside cycle --- pkg/metrics/get_runners_enterprise_from_github.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/metrics/get_runners_enterprise_from_github.go b/pkg/metrics/get_runners_enterprise_from_github.go index c71d081..a883b52 100644 --- a/pkg/metrics/get_runners_enterprise_from_github.go +++ b/pkg/metrics/get_runners_enterprise_from_github.go @@ -20,8 +20,8 @@ var ( ) func getRunnersEnterpriseFromGithub() { - runnersEnterpriseGauge.Reset() for { + runnersEnterpriseGauge.Reset() runners, _, err := client.Enterprise.ListRunners(context.Background(), config.EnterpriseName, nil) if err != nil { log.Printf("Enterprise.ListRunners error: %s", err.Error())