Skip to content

Commit

Permalink
Merge pull request #3 from prayagsingh/develop
Browse files Browse the repository at this point in the history
Adding a workaround when IDLE is not parsed
  • Loading branch information
prayagsingh authored Apr 17, 2021
2 parents 75ed7e4 + 4b0ce7b commit 3e3eb0b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added jibri-exporter
Binary file not shown.
31 changes: 30 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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() {
Expand Down
18 changes: 9 additions & 9 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
}

Expand Down

0 comments on commit 3e3eb0b

Please sign in to comment.