Grafana Guide: Stat, Gauge and Bar Gauge

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-11 against Grafana 13.3.x.

What you build

You add three panels to the dashboard Bookshelf (guides). A stat named Error ratio shows the share of failed requests as one big number with a sparkline, and shows the text No errors while the ratio is zero. A gauge named Connection pool usage shows how much of the database connection pool is in use. A bar gauge named Requests per second by URI draws one bar per route of the Bookshelf service. The three panels read a number where the time series of the earlier guides draws a history, which is what a dashboard header needs.

The finished dashboard in view mode: three panels in a row, the stat Error ratio showing No errors, the gauge Connection pool usage at 20 percent and the bar gauge Requests per second by URI with one bar per route, above the time series panel Requests per second by status

Before you start

  • Start the Grafana profile of the hands-on lab and wait about a minute:

    cd lab
    docker compose --profile grafana up -d
  • Open http://localhost:3000, sign in as admin with the password admin, and click Skip when Grafana 13.3 asks you to update the default password.

  • Do the previous guide, Time series panels, or at least the first-dashboard guide: this guide adds panels to the dashboard Bookshelf (guides) in the folder Guides that those guides create. The screens of the dashboard in edit mode and of the panel editor are described by the two screen maps of the first-dashboard guide.

  • The data source Prometheus is provisioned by the lab and is the default data source. The load generator sends traffic to the Bookshelf service in its default mode, which gives the queries something to draw. The service answers with the statuses 200 and 404 in that mode, so the error ratio is zero until you force failures in the check at the end.

  • The guide was checked on Grafana Enterprise 13.3.0 (the free image, no licence key). Editing dashboards needs the Editor or Admin role of the organization; admin has it.

  • The figures are drawings of the Grafana 13.3 user interface, not screenshots, so small details can differ from your screen. A highlighted box with a number marks the control of the step with the same number. The options pane has more categories than the figures draw; they are collapsed where a step does not need them.

Steps

Each of the three panels follows the same path: add a panel, write the query, pick the visualization from the Suggestions list, then set the options in the pane at the right of the panel editor. The categories that matter here are Value options (how a series is reduced to one value), the visualization’s own category (Stat styles, Gauge or Bar gauge), Standard options (unit), Thresholds and Value mappings.

Open the dashboard and add a panel

  1. In the left navigation, click Dashboards, open the folder Guides and click Bookshelf (guides).

  2. Click Edit at the top right of the toolbar.

    Dashboard Bookshelf (guides) in view mode with its time series panel Requests per second by status; callout 2 marks the Edit button of the toolbar
  3. Click Add at the top left of the toolbar. The right sidebar opens on the Add pane.

  4. Click the Panel tile ("Drag or click to add a panel").

    Dashboard in edit mode with the Add pane of the right sidebar open: callout 3 marks the Add button of the toolbar and callout 4 marks the Panel tile of the pane
  5. In the Panel pane that replaces the Add pane, click Edit visualization.

Show the error ratio as a stat

  1. In query A, click Code in the Builder / Code switch.

  2. Click inside the query editor first, so that it has the focus, then type the query. It divides the rate of the answers with a status from 500 to 599 by the rate of all answers, and or vector(0) gives zero instead of No data when no request has failed:

    sum(rate(http_server_requests_seconds_count{application="bookshelf",status=~"5.."}[1m])) / sum(rate(http_server_requests_seconds_count{application="bookshelf"}[1m])) or vector(0)
  3. Click Run queries.

    Panel editor with query A in Code mode: callout 6 marks the Code option, callout 7 marks the editor with the error ratio query typed over three lines, and callout 8 marks the Run queries button
  4. Under Suggestions, click Stat.

    Panel editor after Run queries for the error ratio: the preview draws a line at zero and the Suggestions list on the right shows Time series, Stat, Gauge and Bar gauge; callout 9 marks Stat
  5. The right column becomes the options pane headed Stat. Under Panel options, type Error ratio in Title.

  6. Open Standard options, click the Unit picker, type percent in its search box and choose the entry for a percentage of a ratio between 0 and 1 (a value of 0.05 shows as 5%).

    Panel editor with the Stat options pane: callout 10 marks the Title field holding Error ratio and callout 11 marks the Unit picker holding the percent unit for a ratio between 0 and 1; the preview shows the value 0
  7. Open Value options. The panel gets one value per series by reducing its points. In Calculation, choose Max to show the worst value of the time range; the default shows the last one.

  8. Open Stat styles. For Graph mode, click Area. The panel draws a sparkline behind the number.

    Panel editor with the Stat options pane: callout 12 marks the Calculation list of Value options, set to Max, and callout 13 marks the Area choice of Graph mode in Stat styles; the preview shows the value 0% with a sparkline
  9. Open Thresholds. The list has a base step in green and a second step in red with the value 80. Replace 80 with 0.05, so that the panel turns red when more than 5% of the requests fail.

    Panel editor with the Thresholds section of the Stat options pane open: the list has the base step in green and a red step whose value is 0.05, marked by callout 14, above the Add threshold button
  10. Open Value mappings and open the editor of the mappings. Add a mapping of the type value: for the value 0 show the text No errors. Confirm the editor. The panel now shows the text instead of 0%.

    The value mappings editor opened over the panel editor: a mapping of the value 0 to the display text No errors, marked by callout 15
  11. Click Back in the header of the editor. The panel is on the dashboard, which is still in edit mode.

Show the connection pool usage as a gauge

  1. Add another panel with the button Add panel under the panels. The Add pane with its Panel tile, as in steps 3 and 4, does the same.

  2. In the Panel pane, click Edit visualization.

  3. In query A, click Code.

  4. Click inside the query editor first, then type the query. It is the share of the pool in use, from 0 to 100, from the metrics hikaricp_connections_active and hikaricp_connections_max:

    100 * sum(hikaricp_connections_active) / sum(hikaricp_connections_max)
  5. Click Run queries.

    Panel editor of a new panel with query A in Code mode: callout 19 marks the Code option, callout 20 marks the editor with the connection pool usage query and callout 21 marks the Run queries button
  6. Under Suggestions, click Gauge.

    Panel editor after Run queries for the connection pool usage: the preview draws a line around 20 and the Suggestions list on the right shows Time series, Stat, Gauge and Bar gauge; callout 22 marks Gauge
  7. Under Panel options, type Connection pool usage in Title.

  8. Open Standard options, click the Unit picker, type percent and choose the entry for a percentage on a scale from 0 to 100. With that unit the gauge runs from 0 to 100 and the default red step at 80 is right as it is.

  9. Open Gauge. For Style, click Arc. Grafana 13 offers Circle and Arc; the same category has Orientation, Bar width factor, Segments, Bar Style, Text mode, Show sparkline, Show thresholds and Show labels.

    Panel editor with the Gauge options pane: callout 23 marks the Title field holding Connection pool usage, callout 24 marks the Unit picker holding the percent unit for a 0 to 100 scale and callout 25 marks the Arc choice of Style; the preview shows a gauge at 20 percent
  10. Click Back.

Show the request rate by URI as a bar gauge

  1. Click Add panel under the panels.

  2. In the Panel pane, click Edit visualization.

  3. In query A, click Code.

  4. Click inside the query editor first, then type the query. It returns one series per route, /api/books, /api/books/{id}, /api/loans and /api/search:

    sum by (uri) (rate(http_server_requests_seconds_count{application="bookshelf"}[1m]))
  5. Click Run queries.

    Panel editor of a new panel with query A in Code mode: callout 29 marks the Code option, callout 30 marks the editor with the request rate by URI query and callout 31 marks the Run queries button
  6. Under Suggestions, click Bar gauge.

    Panel editor after Run queries for the request rate by URI: the preview draws four lines and the Suggestions list on the right shows Time series, Stat, Gauge and Bar gauge; callout 32 marks Bar gauge
  7. Under Panel options, type Requests per second by URI in Title.

  8. Open Value options. In Calculation, choose Mean, so that each bar shows the average of its series over the time range.

  9. Open Bar gauge. For Display mode, click Basic. The other modes are Gradient and Retro LCD; the category also sets Orientation, Value display, Name placement and Show unfilled area.

  10. Click Save in the header of the editor. The 13.3 panel editor has no Apply button; Save saves the whole dashboard and Back returns to it.

    Panel editor with the Bar gauge options pane: callout 33 marks the Title field holding Requests per second by URI, callout 34 marks the Calculation list set to Mean, callout 35 marks the Basic choice of Display mode and callout 36 marks the Save button of the header; the preview shows one bar per URI
  11. In the Save dashboard drawer, optionally type a note in Message and click Save.

  12. Click Back.

  13. Click Exit edit. If Grafana 13.3.0 shows the dialog Unsaved changes ("Do you want to save your changes?"), which it does even right after a save, click Save, and click Save again in the drawer that opens.

Check the result

Open Dashboards → Guides → Bookshelf (guides). The dashboard must show the stat Error ratio with the text No errors on a green background, the gauge Connection pool usage with an arc in green, and the bar gauge Requests per second by URI with one bar for each of the four routes.

To see the stat react, force errors and press Refresh after a minute: the text gives way to a percentage, and the stat turns red when it passes 5%. Restore normal traffic afterwards:

curl -X POST localhost:8090/mode/failing
curl -X POST localhost:8090/mode/normal

curl localhost:8090/ shows the current mode.

Variations

  • Set Text mode in Stat styles to show only the value or only the name, and Color mode to colour the value instead of the background.

  • In Gauge, turn on Show thresholds to draw the threshold steps on the scale, and Show sparkline to add a history under the value.

  • Set Orientation in Bar gauge to vertical, and Name placement to Top when the route names are long.

  • Use Percentage instead of Absolute in Thresholds mode so that the steps follow the minimum and maximum of the panel.

What can go wrong

Symptom Cause Fix

The stat shows No data

The query has no or vector(0) and no request has failed, so the division returns nothing.

Retype the query of step 7 with its last part or vector(0), and run it again.

The stat shows 0% instead of No errors

The value mapping is missing or maps another value, or the calculation does not give exactly 0.

Open Value mappings and check that the mapping is of the type value, for 0, with the text No errors.

The gauge shows a huge number or stays empty

The unit is the percentage of a ratio from 0 to 1 while the query already multiplies by 100, or the metrics have no samples yet.

Choose the percent unit for a 0 to 100 scale, and wait a minute after the lab starts.

The bar gauge shows one bar per sample instead of per route

Show in Value options is All values instead of Calculate.

Set Show to Calculate and choose a Calculation.

Exit edit keeps showing Unsaved changes

Grafana 13.3.0 raises the dialog even after a save.

Click Save, and Save again in the drawer; the dialog does not return once edit mode has closed.

Clean up

Keep the dashboard: the following guides in this series use it. Send curl -X POST localhost:8090/mode/normal if you changed the mode of the load generator. To remove everything the lab stores, stop the profile with docker compose --profile grafana down -v, which also deletes the volumes and therefore the dashboard.

Where to go next