Git Product home page Git Product logo

flask-prometheus's Introduction

Flask-Prometheus

About

Out of the box, this flask extension makes it extremely easy to monitor your application using SoundCloud's Prometheus. For more on Prometheus, see their website.

This extension instruments every flask route and exports the following metrics:

  • Histogram: <flask_request_latency_seconds> {'endpoint', 'method'}
  • Summary: <flask_request_count> {'endpoint','method','http_status'}

Installation

pip install flask_prometheus

Basic Usage

Type the following into an interpreter:

from flask import Flask
from flask_prometheus import monitor 

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello'

monitor(app, port=8000)
app.run()

Now, naviagate localhost:5000 a few times and then view metrics on localhost:8000 which should look like:

# HELP flask_request_count Flask Request Count
# TYPE flask_request_count counter
flask_request_count{endpoint="/",http_status="200",method="GET"} 4.0
# HELP flask_request_latency_seconds Flask Request Latency
# TYPE flask_request_latency_seconds histogram
flask_request_latency_seconds_bucket{endpoint="/",le="0.005",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.01",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.025",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.05",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.075",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.1",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.25",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.5",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="0.75",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="1.0",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="2.5",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="5.0",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="7.5",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="10.0",method="GET"} 4.0
flask_request_latency_seconds_bucket{endpoint="/",le="+Inf",method="GET"} 4.0
flask_request_latency_seconds_count{endpoint="/",method="GET"} 4.0
flask_request_latency_seconds_sum{endpoint="/",method="GET"} 0.0010027885437011719

Beware, this seems to not work when the app is run in debug mode.

WSGI Wrapper

You may also use the WSGI wrapper to expose the metrics, like so:

from flask import Flask
from flask_prometheus import monitor_app

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello'

app = monitor_app(app)
app.run()

flask-prometheus's People

Contributors

sbarratt avatar ritesh avatar ant1441 avatar nrmitchi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.