Skip to main content

Working with Prometheus Queries

Hands-On Lab

 

Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content

Length

00:30:00

Difficulty

Intermediate

Once you have begun collecting metric data in Prometheus, you will need to be able to work with that data in order to obtain information you can act upon. Prometheus provides a specialized query language known as Prometheus Query Language (PromQL) that allows you to write both simple and complex queries in order to retrieve and view your metric data in a useful way. In this hands-on lab, you will have the opportunity to work with Prometheus queries by writing and executing some simple queries.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Prometheus Queries

Introduction

Once you have begun collecting metric data in Prometheus, you will need to be able to work with that data in order to obtain information you can act upon. Prometheus provides a specialized query language known as Prometheus Query Language (PromQL) that allows you to write both simple and complex queries in order to retrieve and view your metric data in a useful way. In this hands-on lab, you will have the opportunity to work with Prometheus queries by writing and executing some simple queries.

Solution

Log in to the server using the credentials provided:

ssh cloud_user@<PUBLIC_IP_ADDRESS>

Get the Current Memory Usage for the LimeDrop Authentication Service

  1. Access the Prometheus expression browser in a web browser (replacing <PROMETHEUS_SERVER_PUBLIC_IP> with the public IP address of the Prometheus server):

    http://<PROMETHEUS_SERVER_PUBLIC_IP>:9090
  2. Run a query to obtain the available memory amount, supplying a label to search specifically for metrics for the limedrop-auth:4455 instance:

    mem_available_total{instance="limedrop-auth:4455"}
  3. Click Execute.

  4. Note down the returned value.

  5. In the terminal, open the output file:

    vi auth_service_data.md
  6. Enter the current available memory (the value you copied from the query) on the mem_available_total line:

    mem_available_total: <AVAILABLE_MEMORY_VALUE>

Get the Available Memory Range Data Over a Five-Minute Period Three Minutes Ago

  1. Run a query in the expression browser to obtain the data:

    mem_available_total{instance="limedrop-auth:4455"}[5m] offset 3m
  2. Click Execute.

  3. Note down the output, including the timestamps.

  4. On the Prometheus server, still in the auth_service_data.md file, paste in the data at the end of the file.

  5. Save and exit the file by pressing Escape followed by :wq.

Conclusion

Congratulations on successfully completing this hands-on lab!