0

How can I get metrics on requests per seconds with the metrics exposed by the starlette exporter (link here). I have a Grafana instance, and have metrics like starlette_requests_total and starlette_requests_in_progress.

My scrape_interval in my prometheus.yaml config file is 15s. However, I am only able to get data when I use

rate(starlette_requests_total{method="GET"}[4m])

Any interval less than 4m returns no data. I sent requests to the server but there seems to be no impact on the metrics.

I'm new to coding and observability. Any help would be much appreciated!

1
  • This shouldn't be: rate requires at least to samples, so in your case [30s] should be enough. Check if you have problems on scraping.
    – markalex
    Commented May 22 at 9:56

1 Answer 1

0

Based on @markalex's advice on needing multiple samples, here is what worked for me in the end. Would definitely welcome suggestions to improve the configuration and/or remove unnecessary configurations.

created a rules.yaml file:

groups:
  - name: starlette
    interval: 5s
    rules:
    - record: starlette_requests_per_second
      expr: |
        rate(starlette_requests_total{method=~"GET"}[5s])

in the prometheus.yaml file:

rule_files:
  - rules.yaml

scrape_config:
  - job_name: myapp_name
    scrape_interval: 1s
    static_configs:
      - targets: ['<endpoint that I send the GET request to>']

My rationale - and I would really appreciate confirmation whether my understanding is accurate - is that since multiple samples are needed, if my scrape_interval is 1s and my recording rule computes the query at 5s intervals, I will get 5 samples for each 5 seconds, which gives a relatively accurate approximation of requests per second.

Not the answer you're looking for? Browse other questions tagged or ask your own question.