diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ec8ad55..11960cf 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -34,8 +34,6 @@ jobs: type=ref,event=pr type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 diff --git a/jibri-exporter b/jibri-exporter new file mode 100755 index 0000000..cb071f7 Binary files /dev/null and b/jibri-exporter differ diff --git a/main.go b/main.go index b84d339..8ae72c9 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,17 @@ type jibriStats struct { } `json:"status"` } +// this is a workaround since prometheus is unable to parse IDLE. it is showing error in targets +// error: strconv.ParseFloat: parsing "IDLE": invalid syntax. +type newjibriStats struct { + Status struct { + BusyStatus int `json:"busyStatus"` + Health struct { + HealthStatus int `json:"healthStatus"` + } `json:"health"` + } `json:"status"` +} + var tpl = template.Must(template.New("stats").Parse(`# HELP jibri_busystatus It check the status of the jibri whether BUSY, IDLE. # TYPE jibri_busystatus gauge jibri_busystatus {{.Status.BusyStatus}} @@ -44,13 +55,31 @@ func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { defer resp.Body.Close() var stats jibriStats + var newstats newjibriStats + if err := json.NewDecoder(resp.Body).Decode(&stats); err != nil { log.Printf("json decoding error: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) return } + + // Replacing IDLE with 0, BUSY with 1 and EXPIRED with 2 + // HEALTHY 1 and UNHEALTHY 0 + if stats.Status.BusyStatus == "IDLE" { + newstats.Status.BusyStatus = 0 + } else if stats.Status.BusyStatus == "BUSY" { + newstats.Status.BusyStatus = 1 + } else if stats.Status.BusyStatus == "EXPIRED" { + newstats.Status.BusyStatus = 2 + } + if stats.Status.Health.HealthStatus == "HEALTHY" { + newstats.Status.Health.HealthStatus = 1 + } else if stats.Status.Health.HealthStatus == "UNHEALTHY" { + newstats.Status.Health.HealthStatus = 0 + } + w.Header().Set("Content-Type", "text/plain") - _ = tpl.Execute(w, &stats) + _ = tpl.Execute(w, &newstats) } func main() { diff --git a/main_test.go b/main_test.go index 5427bb3..0322626 100644 --- a/main_test.go +++ b/main_test.go @@ -25,32 +25,32 @@ func TestGetMetrics(t *testing.T) { statsJson string expected string }{ - { + { // IDLE 0, BUSY 1, EXPIRED 2, HEALTHY 1, UNHEALTHY 0 statsJson: `{"status": {"busyStatus": "IDLE", "health": {"healthStatus": "HEALTHY"}}}`, expected: `# HELP jibri_busystatus It check the status of the jibri whether BUSY, IDLE. # TYPE jibri_busystatus gauge -jibri_busystatus IDLE +jibri_busystatus 0 # HELP jibri_healthstatus It check the health status of the jibri whether HEALTHY or not. # TYPE jibri_healthstatus gauge -jibri_healthstatus HEALTHY`, +jibri_healthstatus 1`, }, - { + { // IDLE 0, BUSY 1, EXPIRED 2, HEALTHY 1, UNHEALTHY 0 statsJson: `{"status": {"busyStatus": "BUSY", "health": {"healthStatus": "HEALTHY"}}}`, expected: `# HELP jibri_busystatus It check the status of the jibri whether BUSY, IDLE. # TYPE jibri_busystatus gauge -jibri_busystatus BUSY +jibri_busystatus 1 # HELP jibri_healthstatus It check the health status of the jibri whether HEALTHY or not. # TYPE jibri_healthstatus gauge -jibri_healthstatus HEALTHY`, +jibri_healthstatus 1`, }, - { + { // IDLE 0, BUSY 1, EXPIRED 2, HEALTHY 1, UNHEALTHY 0 statsJson: `{"status": {"busyStatus": "EXPIRED", "health": {"healthStatus": "UNHEALTHY"}}}`, expected: `# HELP jibri_busystatus It check the status of the jibri whether BUSY, IDLE. # TYPE jibri_busystatus gauge -jibri_busystatus EXPIRED +jibri_busystatus 2 # HELP jibri_healthstatus It check the health status of the jibri whether HEALTHY or not. # TYPE jibri_healthstatus gauge -jibri_healthstatus UNHEALTHY`, +jibri_healthstatus 0`, }, }