All Projects β†’ muatik β†’ Flask Profiler

muatik / Flask Profiler

Licence: mit
a flask profiler which watches endpoint calls and tries to make some analysis.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Flask Profiler

Flask Monitoringdashboard
Automatically monitor the evolving performance of Flask/Python web services.
Stars: ✭ 483 (-22.35%)
Mutual labels:  flask, monitoring, profiler, dashboard
Sing App
πŸ’₯Free and open-source admin dashboard template built with Bootstrap 4.5 πŸ’₯
Stars: ✭ 1,187 (+90.84%)
Mutual labels:  analytics, dashboard, admin
Grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
Stars: ✭ 45,930 (+7284.24%)
Mutual labels:  analytics, monitoring, dashboard
Netdata
Real-time performance monitoring, done right! https://www.netdata.cloud
Stars: ✭ 57,056 (+9072.99%)
Mutual labels:  analytics, monitoring, dashboard
Goaccess
GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.
Stars: ✭ 14,096 (+2166.24%)
Mutual labels:  analytics, monitoring, dashboard
Kube Opex Analytics
🎨 Kubernetes Cost Allocation and Capacity Planning Analytics Tool. Hourly, daily, monthly reports - Prometheus exporter - Built-in & Grafana dashboard.
Stars: ✭ 232 (-62.7%)
Mutual labels:  analytics, monitoring, dashboard
Vudash
Powerful, Flexible, Open Source dashboards for anything
Stars: ✭ 363 (-41.64%)
Mutual labels:  analytics, monitoring, dashboard
Ceph Dash
Flask based api / dashboard for viewing a ceph clusters overall health status
Stars: ✭ 398 (-36.01%)
Mutual labels:  monitoring, dashboard
Kongdash
An elegant desktop client for Kong Admin API
Stars: ✭ 449 (-27.81%)
Mutual labels:  dashboard, admin
Goappmonitor
Golang application performance data monitoring.
Stars: ✭ 478 (-23.15%)
Mutual labels:  monitoring, profiler
Countly Server
Countly helps you get insights from your application. Available self-hosted or on private cloud.
Stars: ✭ 4,857 (+680.87%)
Mutual labels:  analytics, dashboard
Tautulli
A Python based monitoring and tracking tool for Plex Media Server.
Stars: ✭ 4,152 (+567.52%)
Mutual labels:  analytics, monitoring
Redash
Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.
Stars: ✭ 20,147 (+3139.07%)
Mutual labels:  analytics, dashboard
Applicationinsights Js
Microsoft Application Insights SDK for JavaScript
Stars: ✭ 462 (-25.72%)
Mutual labels:  analytics, monitoring
Leaa
Leaa is a monorepo restful CMS / Admin built with Nest.js (@nestjsx/crud, node.js) and Ant Design.
Stars: ✭ 375 (-39.71%)
Mutual labels:  dashboard, admin
Shards Dashboard Vue
A free Vue admin dashboard template pack featuring a modern design system and lots of custom templates and components.
Stars: ✭ 363 (-41.64%)
Mutual labels:  dashboard, admin
Sail
Sail is a lightweight Rails engine that brings an admin panel for managing configuration settings on a live Rails app
Stars: ✭ 484 (-22.19%)
Mutual labels:  dashboard, admin
Kaffy
Powerfully simple admin package for phoenix applications
Stars: ✭ 617 (-0.8%)
Mutual labels:  dashboard, admin
Ngx Admin
Customizable admin dashboard template based on Angular 10+
Stars: ✭ 23,286 (+3643.73%)
Mutual labels:  dashboard, admin
Abixen Platform
Abixen Platform
Stars: ✭ 530 (-14.79%)
Mutual labels:  analytics, dashboard

Flask-profiler

version: 1.8 Build Status

Flask-profiler measures endpoints defined in your flask application; and provides you fine-grained report through a web interface.

It gives answers to these questions:

  • Where are the bottlenecks in my application?
  • Which endpoints are the slowest in my application?
  • Which are the most frequently called endpoints?
  • What causes my slow endpoints? In which context, with what args and kwargs are they slow?
  • How much time did a specific request take?

In short, if you are curious about what your endpoints are doing and what requests they are receiving, give a try to flask-profiler.

With flask-profiler's web interface, you can monitor all your endpoints' performance and investigate endpoints and received requests by drilling down through filters.

Screenshots

Dashboard view displays a summary.

Alt text

You can create filters to investigate certain type requests.

Alt text

Alt text

You can see all the details of a request. Alt text

Quick Start

It is easy to understand flask-profiler going through an example. Let's dive in.

Install flask-profiler by pip.

pip install flask_profiler

Edit your code where you are creating Flask app.

# your app.py
from flask import Flask
import flask_profiler

app = Flask(__name__)
app.config["DEBUG"] = True

# You need to declare necessary configuration to initialize
# flask-profiler as follows:
app.config["flask_profiler"] = {
    "enabled": app.config["DEBUG"],
    "storage": {
        "engine": "sqlite"
    },
    "basicAuth":{
        "enabled": True,
        "username": "admin",
        "password": "admin"
    },
    "ignore": [
	    "^/static/.*"
	]
}


@app.route('/product/<id>', methods=['GET'])
def getProduct(id):
    return "product id is " + str(id)


@app.route('/product/<id>', methods=['PUT'])
def updateProduct(id):
    return "product {} is being updated".format(id)


@app.route('/products', methods=['GET'])
def listProducts():
    return "suppose I send you product list..."

@app.route('/static/something/', methods=['GET'])
def staticSomething():
    return "this should not be tracked..."

# In order to active flask-profiler, you have to pass flask
# app as an argument to flask-profiler.
# All the endpoints declared so far will be tracked by flask-profiler.
flask_profiler.init_app(app)


# endpoint declarations after flask_profiler.init_app() will be
# hidden to flask_profiler.
@app.route('/doSomething', methods=['GET'])
def doSomething():
    return "flask-profiler will not measure this."


# But in case you want an endpoint to be measured by flask-profiler,
# you can specify this explicitly by using profile() decorator
@app.route('/doSomethingImportant', methods=['GET'])
@flask_profiler.profile()
def doSomethingImportant():
    return "flask-profiler will measure this request."

if __name__ == '__main__':
    app.run(host="127.0.0.1", port=5000)


Now run your app.py

python app.py

And make some requests like:

curl http://127.0.0.1:5000/products
curl http://127.0.0.1:5000/product/123
curl -X PUT -d arg1=val1 http://127.0.0.1:5000/product/123

If everything is okay, Flask-profiler will measure these requests. You can see the result heading to http://127.0.0.1:5000/flask-profiler/ or get results as JSON http://127.0.0.1:5000/flask-profiler/api/measurements?sort=elapsed,desc

If you like to initialize your extensions in other files or use factory apps pattern, you can also create a instance of the Profiler class, this will register all your endpoints once you app run by first time. E.g:

from flask import Flask
from flask_profiler import Profiler

profiler = Profiler()

app = Flask(__name__)

app.config["DEBUG"] = True

# You need to declare necessary configuration to initialize
# flask-profiler as follows:
app.config["flask_profiler"] = {
    "enabled": app.config["DEBUG"],
    "storage": {
        "engine": "sqlite"
    },
    "basicAuth":{
        "enabled": True,
        "username": "admin",
        "password": "admin"
    },
    "ignore": [
        "^/static/.*"
    ]
}

profiler = Profiler()  # You can have this in another module
profiler.init_app(app)
# Or just Profiler(app)

@app.route('/product/<id>', methods=['GET'])
def getProduct(id):
    return "product id is " + str(id)

Using with different database system

You can use flaskprofiler with SqlLite, MongoDB, Postgresql, Mysql or MongoDB database systems. However, it is easy to support other database systems. If you would like to have others, please go to contribution documentation. (It is really easy.)

SQLite

In order to use SQLite, just specify it as the value of storage.engine directive as follows.

app.config["flask_profiler"] = {
    "storage": {
        "engine": "sqlite",
    }
}

Below the other options are listed.

Filter key Description Default
storage.FILE SQLite database file name flask_profiler.sql
storage.TABLE table name in which profiling data will reside measurements

MongoDB

In order to use MongoDB, just specify it as the value of storage.engine directive as follows.

app.config["flask_profiler"] = {
    "storage": {
        "engine": "mongodb",
    }
}

SQLAchemy

In order to use SQLAchemy, just specify it as the value of storage.engine directive as follows. Also first create an empty database with the name "flask_profiler".

app.config["flask_profiler"] = {
    "storage": {
        "engine": "sqlalchemy",
        "db_url": "postgresql://user:[email protected]:5432/flask_profiler"  # optional, if no db_url specified then sqlite will be used.
    }
}

Custom database engine

Specify engine as string module and class path.

app.config["flask_profiler"] = {
    "storage": {
        "engine": "custom.project.flask_profiler.mysql.MysqlStorage",
        "MYSQL": "mysql://user:[email protected]/flask_profiler"
    }
}

The other options are listed below.

Filter key Description Default
storage.MONGO_URL mongodb connection string mongodb://localhost
storage.DATABASE database name flask_profiler
storage.COLLECTION collection name measurements

Sampling

Control the number of samples taken by flask-profiler

You would want control over how many times should the flask profiler take samples while running in production mode. You can supply a function and control the sampling according to your business logic.

Example 1: Sample 1 in 100 times with random numbers

app.config["flask_profiler"] = {
    "sampling_function": lambda: True if random.sample(list(range(1, 101)), 1) == [42] else False
}

Example 2: Sample for specific users

app.config["flask_profiler"] = {
    "sampling_function": lambda: True if user is 'divyendu' else False
}

If sampling function is not present, all requests will be sampled.

Changing flask-profiler endpoint root

By default, we can access flask-profiler at /flask-profiler

app.config["flask_profiler"] = {
        "endpointRoot": "secret-flask-profiler"
}

Ignored endpoints

Flask-profiler will try to track every endpoint defined so far when init_app() is invoked. If you want to exclude some of the endpoints, you can define matching regex for them as follows:

app.config["flask_profiler"] = {
        "ignore": [
	        "^/static/.*",
	        "/api/users/\w+/password"
        ]
}

Contributing

Contributions are welcome!

Review the Contributing Guidelines for details on how to:

  • Submit issues
  • Add solutions to existing challenges
  • Add new challenges

Authors

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].