Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ansible/roles/prometheus/templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ global:
evaluation_interval: 15s

scrape_configs:
- job_name: "node"
- job_name: "node-exporter"
static_configs:
- targets:
- "{{ hostvars['monitoring-1'].ansible_host }}:9100"
- "{{ hostvars['app-1'].ansible_host }}:9100"

- job_name: "flask_app"
metrics_path: /metrics
static_configs:
- targets:
- "{{ hostvars['app-1'].ansible_host }}:80"

1 change: 1 addition & 0 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
flask==3.0.0
gunicorn==21.2.0
prometheus-client

24 changes: 18 additions & 6 deletions app/src/routes/metrics.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import random
import time

from flask import Blueprint, jsonify
from flask import Blueprint
from prometheus_client import CONTENT_TYPE_LATEST, Gauge, generate_latest

metrics_bp = Blueprint("metrics", __name__)

start_time = time.time()

uptime_gauge = Gauge("app_uptime_seconds", "App uptime in seconds")
random_gauge = Gauge("app_random_value", "Random value")

@metrics_bp.route("/metrics/custom")
start_time = time.time()


@metrics_bp.route("/metrics")
def metrics():
uptime = time.time() - start_time
random_value = random.randint(1, 100)
return jsonify({"uptime_seconds": uptime, "random_value": random_value}), 200
uptime_gauge.set(time.time() - start_time)
# random_gauge.set(...)
return generate_latest(), 200, {"Content-Type": CONTENT_TYPE_LATEST}


# @metrics_bp.route("/metrics/custom")
# def metrics_custom():
# uptime = time.time() - start_time
# random_value = random.randint(1, 100)
# return jsonify({"uptime_seconds": uptime, "random_value": random_value}), 200