A bar chart for http status codes per endpoint

Hi all,

I have a prometheus summary metrics that looks like this:
http_response{method: <get/post>, endpoint: <endpoint>, httpStatusCode: <200/400/etc>}

I would like to create a diagram in grafana, that looks something like this:

where different colors represent different groups of response codes: 2xx, 5xx, 4xx

Where should I start from or maybe some steps or tutorials that would help me do that?

I have everything configured I only need to make the dashboard.

Thanks in advance.

Hi,

after you execute your query, you need to present only a single value from that query - bar chart does not support plots in time, so you need to know if you want to present last value, max value, min value, etc.

To do the chart you have to:

  1. Reduce the time series data to a single value as I mentioned before, using Reduce transformation:

  2. To get the “GET: endpoint1” label, you need to either do that in your query (I’m not sure if it’s possible in vanilla PromQL) or use transformation Add field from calculation where you will add the two text fields.

  3. Group the data to matrix (data format that bar chart requires), where the rows will be the data on X axis (in your case - endpoint) and the columns represent the data on the bars (in your case - statuses). Use Grouping to Matrix transformation (notice that in my screen I had route == endpoint and status == httpStatusCode):

  4. In bar chart options, use stacking set to normal. For colors, use overrides like those:

1 Like

Hi @dawiddebowski thank you.

It all worked perfectly.
As for the “GET:endpoint” label, I managed to do it with prometheus query:

  label_join(
    http_response_time_count,
    "endpoint",
    ":",
    "method",
    "path"
  )

In the end, I rotated the chart 90 degrees because endpoint names are quite long and not readable on X axis:

How can i specify the order of endpoint labels on Y axis?

Thank you again so much for your help.

I think that by default they’re sorted by the name (e.g. DELETE…) - what would you like to sort by?

I was just wondering if there is a way to control it. I looked through bar chart options and couldn’t find it.