How to combine multiple http status code into one?

Grafana v6.0.1 (0c44a04)

Hello people!

I am trying to figure out how I can display given http status code (200/404/301 should be displayed as successful). and all other status should be displayed as failed.

Instead of having multiple legends per http status code, instead I would like to know how to combine (200/404/301) into one successful legend?

Successful: scraper_request_count_total{http_status=~“200|404|301”}
Failed: scraper_request_count_total{http_status!~“200|404|301”}

Bumping and hoping anyone here could help me :smiley:

I you want just one query, you can use label_replace to add a new label, based on the status label, e.g something like this:

sum by(success) (label_replace(scraper_request_count_total, "success", "true", "http_status", "200|404|301"))

If you keep them as two separate queries, you can just sum them, something like this:

sum without(http_status) (scraper_request_count_total{http_status=~"200|404|301"})

You are awesome! That worked exactly how I wanted! Thank you so so so much!

1 Like