Last active
August 3, 2026 09:16
-
-
Save bartolootrit/76845f3608184a1747e53e4f9c2a0ffd to your computer and use it in GitHub Desktop.
Getting recent changes from VictoriaMetrics (single-node version) for testing purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from random import randint | |
| from time import sleep | |
| from urllib.parse import urljoin | |
| val = randint(1, 100) | |
| requests.post( | |
| urljoin(host, '/api/v1/import/prometheus'), | |
| data=f'requests_per_second{{method="post"}} {val}' | |
| ) | |
| # Three steps must be taken to get the recent changes | |
| # Step 1: Flush the buffer: /internal/force_flush. | |
| # See https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#forced-flush | |
| # See https://docs.victoriametrics.com/victoriametrics/keyconcepts/#query-latency | |
| requests.get( | |
| urljoin(host, '/internal/force_flush') | |
| ) | |
| # Step 2: Sleep. There is a lag even after flushing the buffer | |
| sleep(1) | |
| # Step 3: Disable the query cache: nocache=1 | |
| # See https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#rollup-result-cache | |
| resp = requests.get( | |
| urljoin(host, '/api/v1/query'), | |
| params={ | |
| 'query': 'requests_per_second', | |
| 'nocache': '1' | |
| } | |
| ) | |
| _, ret_val = resp.json()['data']['result'][0]['value'] | |
| assert int(ret_val) == val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment