Saturday
Running applications on SAP BTP Cloud Foundry is easy, but operating them efficiently requires good observability. One of the most popular approaches is exposing application metrics using Prometheus and visualizing them with tools such as Grafana.
In this blog, we'll build a simple Python application that exposes Prometheus metrics and deploy it to SAP Cloud Foundry using a manifest.yml.
Prometheus provides:
For SAP Cloud Foundry applications, exposing a /metrics endpoint allows Prometheus to scrape key runtime statistics.
Battery
pip install flask prometheus-clientSample Application
from flask import Flask
from prometheus_client import Counter, generate_latest
app = Flask(__name__)
request_counter = Counter(
"app_requests_total",
"Total number of requests"
)
@app.route("/")
def home():
request_counter.inc()
return "Hello SAP Cloud Foundry!"
@app.route("/metrics")
def metrics():
return generate_latest(), 200, {
"Content-Type": "text/plain"
}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)flask
prometheus-client
gunicornManifest
applications:
- name: prometheus-python-demo
memory: 256M
disk_quota: 512M
instances: 1
buildpacks:
- python_buildpack
command: gunicorn app:app
routes:
- route: prometheus-python-demo.cfapps.eu10.hana.ondemand.com
health-check-type: port
env:
PYTHONUNBUFFERED: "true"cf login --sso
cf push
cf apps
/metrics endpoint.By combining Python, Prometheus, and SAP Cloud Foundry, you can quickly establish a lightweight monitoring solution. Exposing application metrics through a /metrics endpoint and deploying with a simple Cloud Foundry manifest.yml provides a solid foundation for operational visibility and proactive monitoring on SAP BTP.
Running applications on SAP BTP Cloud Foundry is easy, but operating them efficiently requires good observability. One of the most popular approaches is exposing application metrics using Prometheus and visualizing them with tools such as Grafana.
In this blog, we'll build a simple Python application that exposes Prometheus metrics and deploy it to SAP Cloud Foundry using a manifest.yml.
Prometheus provides:
For SAP Cloud Foundry applications, exposing a /metrics endpoint allows Prometheus to scrape key runtime statistics.
Battery
pip install flask prometheus-clientSample Application
from flask import Flask
from prometheus_client import Counter, generate_latest
app = Flask(__name__)
request_counter = Counter(
"app_requests_total",
"Total number of requests"
)
@app.route("/")
def home():
request_counter.inc()
return "Hello SAP Cloud Foundry!"
@app.route("/metrics")
def metrics():
return generate_latest(), 200, {
"Content-Type": "text/plain"
}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)flask
prometheus-client
gunicornManifest
applications:
- name: prometheus-python-demo
memory: 256M
disk_quota: 512M
instances: 1
buildpacks:
- python_buildpack
command: gunicorn app:app
routes:
- route: prometheus-python-demo.cfapps.eu10.hana.ondemand.com
health-check-type: port
env:
PYTHONUNBUFFERED: "true"cf login --sso
cf push
cf apps
/metrics endpoint.By combining Python, Prometheus, and SAP Cloud Foundry, you can quickly establish a lightweight monitoring solution. Exposing application metrics through a /metrics endpoint and deploying with a simple Cloud Foundry manifest.yml provides a solid foundation for operational visibility and proactive monitoring on SAP BTP.