Creating Metrics Dashboards in Grafana

After you’ve integrated your Thriftly APIs with Prometheus (as described in the Analyzing Metrics Using Prometheus section), you can create comprehensive, visually-pleasing metrics dashboards by importing your Prometheus metrics into Grafana.

An example Grafana dashboard

To create dashboards in Grafana, you must:

  • Install, configure, and launch Grafana.

  • Import your Prometheus metrics into Grafana.

  • Create a Grafana dashboard to show API metrics.

Installing and Launching Grafana

  1. Download Grafana from the company’s website.

  2. Navigate to your downloads folder and extract the files from the grafana-version.number.windows-x64.zip folder.

  3. After the grafana-version.number.windows-x64 folder appears, follow the path grafana-version.number.windows-x64\grafana-version.number\conf.

  4. In the conf folder, copy the sample.ini file. Name your copy custom.ini.

  5. Open custom.ini (using Notepad ++ or your text editor of choice). Then, use CTRL + F to search for http_port.

  6. Remove the semi-colon that appears at the beginning of the line containing http_port. Then, set the local port on which you want to use Grafana.

The http_port setting within the custom file
  1. From the conf folder, navigate back to the grafana-version.number folder. Then, go to the bin folder.

  2. Right-click grafana-server and run the program as an administrator. A command line window should appear to confirm the application is running.

  3. Right-click grafana-cli to run the program as an administrator.

  4. Open your web browser and navigate to the localhost port you specified in step 6. The Grafana login page should appear. Enter both a username and password of admin to log in.

The Grafana login screen

You’ve now successfully installed and launched Grafana. Next, we’ll walk you through importing your Prometheus metrics into Grafana.

Importing Prometheus Metrics into Grafana

  1. From the Grafana sidebar, select Configuration > Data Sources.

The Data Sources configuration option in Grafana
  1. When the Configuration page appears, select Add data source. The Data Sources page appears.

  2. On the Data Sources page:

    1. In the Name field, enter a name for this data source (such as Prometheus).

    2. Select the Default checkbox to make Prometheus your default data source.

    3. In the Type field, select Prometheus.

    4. In the URL field, enter the localhost port on which you’ve configured Prometheus to operate. If you’re using our default configuration, you should enter http://localhost:9090.

    5. Adjust any of the other, optional settings on this page as you desire. Then, scroll down and select Save & Test. A message should appear to confirm you added a data source.

You’ve now connected Prometheus to Grafana, which means you can begin monitoring your Thriftly API using Grafana’s comprehensive graphing and analysis tools. Below, we’ll walk you through creating a very simple Grafana dashboard that contains one graph element and one table element. Then, we’ll provide some resources to help you create your own robust API metrics dashboards.

Creating a Grafana Dashboard

  1. From the Grafana sidebar, select Dashboards > Manage.

The Manage Dashboards button in the Grafana sidebar
  1. From the Dashboards page, select the +Dashboard button to create a new dashboard.

  2. Before we start adding elements to this dashboard, let’s give our dashboard a name. Select the Settings button found in the upper right-hand corner of the dashboard.

  3. The General form appears:

    1. In the Name field, enter a name for your dashboard (such as Thriftly API Monitoring).

    2. In the Description field, enter a description for your dashboard.

  4. Select the Save button. When the Save changes window appears, enter a description of the changes you made and then select Save.

  5. You’re returned to your dashboard. Now, select the Add panel button.

  6. When the options for what type of panel to add appear, select Graph.

  7. A new graph element appears in your dashboard. To edit this graph, select Panel Title from the top of the graph, and then select Edit.

The graph element appears full-screen within your web browser. In the following example, we’re going to create a graph that shows the total amount of data sent to and from your API within a certain time period, which is an important metric you’ll likely want to monitor.

Creating a Grafana Graph

  1. Within the graph configuration screen, select the General tab.

  2. In the Title field, enter a title for your graph, such as Request and Response Data Total.

  3. In the Description field, enter a description such as “This graph shows the amount of data sent to and from our APIs.”

  4. Select the Metrics tab.

  5. In the Data Source field, select Prometheus (or whatever you named the data source you added above).

  6. In the A, B, etc. fields, enter the metrics you want to show on this graph:

    1. In the A field, enter the thriftly_runtime_request_bytes_total metric. Then, in the Legend format field, enter Total Bytes Requested.

    2. Select the Add Query button that appears next to the B button. Then, in the field that appears, enter the thriftly_runtime_response_bytes_total metric. In the Legend format field, enter Total Bytes Responded.

    3. Optionally, to combine multiple calls into one metric, you can use the sum() function, sum(thriftly_runtime_request_bytes_total) and sum(thriftly_runtime_response_bytes_total).

  7. Select the Save button that appears in the upper right-hand side of the dashboard. Then, select the Back to Dashboard button to return to your dashboard and view your graph.

An example Grafana graph

You’ve now added a basic graph to your dashboard. In the next section, we’ll add a basic table.

Creating a Grafana Table

  1. From the upper right-hand side of the dashboard, select the Add panel button.

  2. When the options for what type of panel to add appear, select Table.

  3. A new table element appears in your dashboard. To edit this table, select Panel Title from the table, and then select Edit.

The table element appears full-screen within your web browser. In the following example, we’re going to create a table that shows the total number of calls made to your API, broken out into five minute intervals:

  1. Within the table configuration screen, select the General tab.

  2. In the Title field, enter a title for your table, such as Total Calls (5 Min Interval).

  3. In the Description field, enter a description such as “Shows the total number of API calls, broken out into five minute intervals”.

  4. Select the Metrics tab.

  5. In the Data Source field, select Prometheus (or whatever you named your data source).

  6. In the A field, enter the thriftly_runtime_calls_total metric.

  7. In the Min Step field, enter 5m.

  8. Select the Save button that appears in the upper right-hand side of the dashboard. Then, select the Back to Dashboard button to return to your dashboard.

Now you can see the total number of calls made to your API and trace that number backward through five minute intervals, to see the amount of traffic your API received within any given five minute time period.

An example Grafana dashboard

Of course, there’s a lot more you can do with Grafana, including combining metrics queries and creating additional types of dashboard elements. To learn more, click over to Grafana’s own documentation on creating and managing dashboards.

After you’ve learned all you need to know and configured your dashboard how you like it, read on for a simple example of creating and receiving metrics-based alerts using Grafana, in the Creating Grafana Email Alerts section.