DevOps and System Administration Forum
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Monitoring SAP Cloud Foundry Applications with Prometheus and Python

Yogananda
Product and Topic Expert
Product and Topic Expert
0 Likes
83

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.

Why Prometheus?

Prometheus provides:

  • Real-time monitoring
  • Application health insights
  • Custom business metrics
  • Alerting integration
  • Grafana dashboard support

For SAP Cloud Foundry applications, exposing a /metrics endpoint allows Prometheus to scrape key runtime statistics.

 

Battery
pip install flask prometheus-client

 Sample 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)
Requirements File 
flask
prometheus-client
gunicorn

 Manifest

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"
Deploy to Cloud Foundry 
cf login --sso

cf push

cf apps

 

Best Practices for SAP Cloud Foundry

  1. Expose only the /metrics endpoint.
  2. Avoid exposing sensitive business data.
  3. Use HTTPS routes.
  4. Monitor memory and instance count.
  5. Add custom metrics for business KPIs.
  6. Integrate Prometheus with Grafana dashboards.
  7. Use alerting rules for application failures.

Conclusion

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.

Why Prometheus?

Prometheus provides:

  • Real-time monitoring
  • Application health insights
  • Custom business metrics
  • Alerting integration
  • Grafana dashboard support

For SAP Cloud Foundry applications, exposing a /metrics endpoint allows Prometheus to scrape key runtime statistics.

 

Battery
pip install flask prometheus-client

 Sample 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)
Requirements File 
flask
prometheus-client
gunicorn

 Manifest

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"
Deploy to Cloud Foundry 
cf login --sso

cf push

cf apps

 

Best Practices for SAP Cloud Foundry

  1. Expose only the /metrics endpoint.
  2. Avoid exposing sensitive business data.
  3. Use HTTPS routes.
  4. Monitor memory and instance count.
  5. Add custom metrics for business KPIs.
  6. Integrate Prometheus with Grafana dashboards.
  7. Use alerting rules for application failures.

Conclusion

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.

0 REPLIES 0