...

Source file src/edge-infra.dev/pkg/f8n/devinfra/github-actions-exporter/metrics/get_runners_from_github.go

Documentation: edge-infra.dev/pkg/f8n/devinfra/github-actions-exporter/metrics

     1  package metrics
     2  
     3  import (
     4  	"context"
     5  	"log"
     6  	"strconv"
     7  
     8  	"github.com/google/go-github/v47/github"
     9  	"github.com/prometheus/client_golang/prometheus"
    10  )
    11  
    12  // getRunnersFromGithub - return information about runners and their status for a specific repo
    13  func getRunnersFromGithub(gauge *prometheus.GaugeVec) {
    14  	for {
    15  		opts := github.ListOptions{}
    16  		resp, _, err := client.Actions.ListRunners(context.Background(), org, repo, &opts)
    17  		if err != nil {
    18  			log.Printf("ListRunners error for %s: %s", repo, err.Error())
    19  		} else {
    20  			for _, runner := range resp.Runners {
    21  				if runner.GetStatus() == "online" {
    22  					gauge.WithLabelValues(repo, *runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10), strconv.FormatBool(runner.GetBusy())).Set(1)
    23  				} else {
    24  					gauge.WithLabelValues(repo, *runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10), strconv.FormatBool(runner.GetBusy())).Set(0)
    25  				}
    26  			}
    27  		}
    28  	}
    29  }
    30  

View as plain text