-
-
Save konradkonrad/62ff7fa9c99fc18552e79329b81f0fa4 to your computer and use it in GitHub Desktop.
prometheus backfill test
This file contains 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
version: "2.1" | |
services: | |
prom: | |
image: prom/prometheus | |
environment: | |
- TZ=$TZ | |
volumes: | |
- ./prom.yml:/etc/prometheus/prometheus.yml | |
ports: | |
- 9090:9090 | |
source: | |
image: python:3.6 | |
environment: | |
- TX=$TZ | |
volumes: | |
- .:/app | |
ports: | |
- 5000:5000 | |
command: bash -c 'pip install flask pendulum && python -u /app/main.py' |
This file contains 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
from random import randint | |
from textwrap import dedent | |
import sys | |
from flask import Flask | |
import pendulum | |
app = Flask(__name__) | |
NOW = pendulum.now() | |
START_COUNTER = int((NOW - pendulum.Interval(hours=2)).timestamp()) | |
COUNTER = (c for c in range(START_COUNTER, int(NOW.timestamp()), 15)) | |
result = "" | |
result_tmpl = dedent( | |
""" | |
# HELP test_total Testmetric | |
# TYPE test_total gauge | |
test_total {0} {1} | |
""") | |
TIMESTAMP = None | |
@app.route('/metrics') | |
def metrics(): | |
now = None | |
global COUNTER | |
global TIMESTAMP | |
global result | |
try: | |
TIMESTAMP = next(COUNTER) | |
except StopIteration: | |
now = int(pendulum.now().timestamp()) | |
if now and now != TIMESTAMP: | |
TIMESTAMP = now | |
result = result_tmpl.format(randint(1, 50), TIMESTAMP * 1000) | |
elif now is None: | |
result = result_tmpl.format(randint(1, 50), TIMESTAMP * 1000) | |
print(TIMESTAMP, file=sys.stderr) | |
return result | |
if __name__ == '__main__': | |
app.run(debug=True, host="0.0.0.0") |
This file contains 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
global: | |
scrape_interval: 75ms | |
scrape_configs: | |
- job_name: 'test' | |
static_configs: | |
- targets: ['source:5000'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment