Skip to content

tigpt/docker-flask-postgres

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monitor Flask Postgres with Elastic APM

This project is based on https://github.com/Azure-Samples/docker-flask-postgres

The objective was to get a very simple project in Flask PostgreSQL, and inset Elastic APM to take a look at what is happening with each request to the app, specially what queries are made to the database.

I've created some bad routes to have interesting data on Elastic APM dashboard

# bad query
@APP.route('/bad_query')
def view_registered_guests_bad_query():
    for _ in range(20):
        guests = Guest.query.all()
    return render_template('guest_list.html', guests=guests)
    
# error message
@APP.route('/hello')
def apm_message_hello():
    apm.capture_message('hello, world!')
    return render_template('apm_hello.html')

# Error
@APP.route('/error')
def apm_error():
    try:
        1 / 0
    except ZeroDivisionError:
        apm.capture_exception()
    return render_template('apm_error.html')

# Unhandled error
@APP.route('/fatal_error')
def apm_fatal_error():
    1 / 0
    return render_template('apm_error.html')

Using a HTTP load generator I've generated some load on the server and Elastic APM quickly showed me where to look, I attach some screenshots

General Overview

Screenshot 2021-06-11 at 13 08 23

GET to / (simple query)

Screenshot 2021-06-11 at 13 08 36

GET to /bad_query (bad query)

Screenshot 2021-06-11 at 13 08 58

GET to /fatal_error (Unhandled division by zero)

Screenshot 2021-06-11 at 13 09 30

Auto generated Service Map

Screenshot 2021-06-11 at 13 10 22

About

A Flask application that demonstrates how to build data-driven Python apps in Azure App Service.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 61.8%
  • HTML 31.6%
  • Mako 4.5%
  • Dockerfile 2.1%