Using the Prometheus HTTP API

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Tools such as the Prometheus expression browser can provide an easy way to execute queries and interact with Prometheus data. However, Prometheus also provides an HTTP API that can allow you to integrate Prometheus with your own custom tools. In this lesson, you will perform some simple queries using the Prometheus HTTP API, allowing you to gain hands-on experience with using that API.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Get the Current Number of Threads
  1. Log in to the Prometheus server.

  2. Make an HTTP request to the Prometheus server to retrieve the data and save it to a file:

    curl localhost:9090/api/v1/query?query=num_threads > /home/cloud_user/num_threads.txt
  3. If you want, you can view the file to verify the output is there:

    cat /home/cloud_user/num_threads.txt
Get the `num_threads` Data Over the Last Five Minutes
  1. Make an HTTP request to retrieve the data and save it to a file:

    start=$(date --date '-5 min' +'%Y-%m-%dT%H:%M:%SZ')
    end=$(date +'%Y-%m-%dT%H:%M:%SZ')
    curl "localhost:9090/api/v1/query_range?query=num_threads&start=$start&end=$end&step=15s" > /home/cloud_user/num_threads_5_minutes.txt
  2. View the file to verify the output is there.

    cat /home/cloud_user/num_threads_5_minutes.txt

Additional Resources

Your company, LimeDrop, has a Prometheus server that collects metrics for a variety of applications and components. The developers would like to build some custom applications that pull data from Prometheus, but they are not sure how to do this.

You have been asked to pull some data from Prometheus using the HTTP API in order to demonstrate how this can be done. Use HTTP requests to execute the requested queries and save the resulting output to a file.

  • Get the current number of open threads in use by the LimeDrop web API. You can find this information by querying the num_threads metric. Save the result to a file located at /home/cloud_user/num_threads.txt.
  • Get the time-series data for the num_threads over the last five minutes. Note that the Prometheus HTTP API uses a separate endpoint for time-range queries. Save the result to a file located at /home/cloud_user/num_threads_5_minutes.txt.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?