DEV Community

Cover image for Request Prometheus API from Robot Framework
Antoine
Antoine

Posted on

Request Prometheus API from Robot Framework

Photo by Ildefonso Polo on Unsplash

Having Prometheus to use for local test is great. It can be achieved using Prometheus in a docker-compose.

But it could be cool to use it along with integration testing. So let's request Prometheus at the end of the tests.

Prometheus exposes a REST API that can be queried.

Query

Prometheus has at least 2 API that can be queried :
/api/v1/query and /api/v1/query_range .

Using the sample project from previous blog, we can make this call
http://localhost:9090/api/v1/query?query=delta(dotnet_total_memory_bytes[2h]) that will gives us this response:

{"status":"success","data":{"resultType":"vector","result":[{"metric":{"instance":"app:80","job":"application"},"value":[1604065760.49,"14929036.50833937"]}]}}
Enter fullscreen mode Exit fullscreen mode

Request

Robot Framework has a library that can be leveraged to request REST API and consumes response.

*** Settings ***
Library           RequestsLibrary
Library           SeleniumLibrary


*** Test Cases ***
GET the delta of total memory
    Create Session  prometheus  http://localhost:9090   
    ${resp}=    Get Request     prometheus  /api/v1/query?query=delta(dotnet_total_memory_bytes[2h])
    Should Be Equal As Strings  ${resp.status_code}     200
    Should Be True  ${resp.json()['data']['result']['result'][0]['value'][0]} < 2000000000
    [Teardown]
Enter fullscreen mode Exit fullscreen mode

Hope this helps !

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay