flask-profiler源代码下载

  • Git URL:

    复制代码
    git://www.github.com/muatik/flask-profiler.git
  • Git Clone代码到本地:
    复制代码
    git clone http://www.github.com/muatik/flask-profiler
  • Subversion代码到本地:
    复制代码
    $ svn co --depth empty http://www.github.com/muatik/flask-profiler
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
 
烧瓶分析器

版本:1.6

使用 profiler测量在你的Flask 应用程序中定义的端点;并通过web界面提供细粒度的报告。

它给出了这些问题的答案:

  • 应用程序中的瓶颈在哪里?
  • 应用程序中最慢的终结点?
  • 哪些是最常被调用的终结点?
  • 什么导致我的慢速端点? 在哪个上下文中,什么是 ARGS 和 kwargs?
  • 特定请求花费了多少时间?

简而言之,如果你对端点正在做什么和接收的请求进行了了解,请尝试打瓶探查器。

通过使用烧瓶分析器接口,你可以监视所有端点的性能,并通过向下钻取过滤器来调查端点和接收的请求。

屏幕截图

指示板视图显示摘要。

你可以创建过滤器来调查某些类型的请求。 [ alt text](/resources/filtering_all_screen。pngraw=true"按端点筛选")?

你可以看到请求的所有细节。

快速启动

通过例子可以很容易理解烧瓶的轮廓。 让我们来。

按pip安装烧瓶探查器。

复制代码
pip install flask_profiler

在创建 Flask 应用程序时编辑你的代码。

复制代码
# your app.pyfrom flask import Flaskimport 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'])defgetProduct(id):
return"product id is "+str(id)@app.route('/product/<id>', methods=['PUT'])defupdateProduct(id):
return"product {} is being updated".format(id)@app.route('/products', methods=['GET'])deflistProducts():
return"suppose I send you product list..."@app.route('/static/something/', methods=['GET'])deflistProducts():
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'])defdoSomething():
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()defdoSomethingImportant():
return"flask-profiler will measure this request."if__name__=='__main__':
app.run(host="127.0.0.1", port=5000)

现在运行你的app.py

复制代码
 
python app.py

并发出一些请求:

复制代码
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

如果一切正常烧瓶探查器将测量这些请求。 在 http://127.0.0.1 :5000/flask-profiler/ 中可以看到结果,或者将结果作为 JSON http://127.0.0.1 :5000/flask-profiler/api/measurements?sort=elapsed,desc。

如果你想在其他文件或者使用工厂应用程序 Pattern 初始化扩展,也可以创建 Profiler 类的实例,这将在首次运行应用程序时将你的所有端点设置为 register。 例如

复制代码
from flask import Flaskfrom 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 moduleprofiler.init_app(app)# Or just Profiler(app)@app.route('/product/<id>', methods=['GET'])defgetProduct(id):
return"product id is "+str(id)

使用不同数据库系统的

你可以使用 flaskprofiler SqlLite MongoDB MongoDB 或者MongoDB数据库系统。 但是,它很容易支持其他数据库系统。 如果你希望拥有其他人,请访问捐赠文档。 ( 这很简单)

SQLite

为了使用 SQLite,只需将它指定为 storage.engine 指令的值,如下。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "sqlite",
}
}

下面列出了其他选项。

筛选键说明默认值

 
storage.FILE SQLite数据库文件 NAME flask_profiler.sql
storage.TABLE 分析数据将驻留在其中的表 NAME 度量

为了使用 MongoDB,只需将它指定为 storage.engine 指令的值,如下所示。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "mongodb",
}
}

SQLAchemy

使用 SQLAchemy,只需将它的指定为 storage.engine 指令的值,如下所示。 还首先使用 NAME"flask_profiler"创建一个空数据库。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "sqlalchemy",
"db_url": "postgresql://user:pass@localhost:5432/flask_profiler"# optional, if no db_url specified then sqlite will be used. }
}

自定义数据库引擎

将引擎指定为字符串 MODULE 和类路径。

复制代码
app.config["flask_profiler"] = {
"storage": {
"engine": "custom.project.flask_profiler.mysql.MysqlStorage",
"MYSQL": "mysql://user:password@localhost/flask_profiler" }
}

下面列出了其他选项。

筛选键说明默认值

 
storage.MONGO_URL mongodb连接字符串 mongodb://localhost
storage.DATABASE 数据库名 flask_profiler
storage.COLLECTION 收藏集名称 度量

采样

控制烧瓶探查器取样的数量

你将希望控制 Flask 分析器在生产模式下运行时需要取样的次数。 你可以根据业务逻辑提供一个函数并控制抽样。

示例 1: 100时间的样本 1,随机数

复制代码
app.config["flask_profiler"] = {
"sampling_function": lambda: Trueif random.sample(list(range(1, 101)), 1) == [42] elseFalse}

示例 2: 特定用户的示例

复制代码
app.config["flask_profiler"] = {
"sampling_function": lambda: Trueif user is'divyendu'elseFalse}

如果不存在采样函数,将对所有请求进行采样。

更换烧瓶分析器端点 root

默认情况下,我们可以访问/烧瓶分析器中的烧瓶探查器

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

忽略终结点

烧瓶探查器将尝试跟踪在调用 init_app() 时定义的每个端点。 如果要排除某些终结点,则可以为它们定义匹配的正规表达式,如下所示:

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

flask-profiler, 监视端点调用并尝试进行某些分析的Flask 事件探查器的更多相关文章

  1. 【转】SQL Server 2008 事件探查器(SQL SERVER Profiler)

    跟踪数据库sql语句的执行情况.例:一个系统,用到了sql server 数据库,这个系统共有500张表,当用户在前台页面做某一个操作时,比如插入,登录等等,我们想知道此刻是在对哪一张表操作,打开事件 ...

  2. SQL Server 2008 事件探查器(SQL SERVER Profiler)

    要想很好地优化ERP系统,可以从客户端.服务器.网络等入手,对于我们M1系统的优化来说,SQL 语句的优化就起到很重要的作用了.为此,我们展开,学习了SQL SERVER 2008的事件探查器(SQL ...

  3. SQL Server 2008 R2 找不到 Install SQL Server Profiler 找不到 事件探查器 解决

    摘自: http://blog.csdn.net/yuxuac/article/details/8992893 SQL Server 2008 R2 Express Edition - Install ...

  4. Flask框架 (四)—— 请求上下文源码分析、g对象、第三方插件(flask_session、flask_script、wtforms)、信号

    Flask框架 (四)—— 请求上下文源码分析.g对象.第三方插件(flask_session.flask_script.wtforms).信号 目录 请求上下文源码分析.g对象.第三方插件(flas ...

  5. 除了信号触发线程与接收者线程相同的情况能直接调用到slot,其它情况都依赖事件机制(解决上面代码收不到信号的问题其实很简单,在线程的run();函数中添加一个事件循环就可以了,即加入一句exec();),信号槽不就是一个回调函数嘛

    MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent)   {   pThreadCon = new CSerialThread ...

  6. Unity-自定义事件派发器的两次尝试

    一.前言: 在游戏开发的很多时候,需要引用其他类的方法,但是一旦类多起来了,相互引用会导致引用关系混乱,极其难以阅读. 以前初次做抖音小游戏时,和一位经验老道的cocos程序员合作,看到我写的代码他不 ...

  7. SQL server Profiler 监视数据库活动

    做网站后台开始时需要考虑后台对数据库的一些操作,比如尽量减少查询次数,尽快释放连接,只选取必须的字段等等.如果是用三层开发,复杂的项目中直接拼装SQL语句多一点,拼装的SQL语句可以直接在SQL se ...

  8. Tools-->SQL Server Profiler监视数据库

    http://www.cnblogs.com/lorking/p/4062787.html https://docs.microsoft.com/en-us/sql/tools/sql-server- ...

  9. SQL2005 : 如何在SQL Server Profiler (事件查看器)中 跟踪查看死锁恢复

    SQL Profiler 通过 SQL Profiler 工具程序,可监控应用程序如何访问数据库引擎.普通来说,当系统性能需要优化或是应用程序对数据库访问的结果不合预期,都可以使用该工具确认视图问题所 ...

随机推荐

  1. Big Data(七)MapReduce计算框架(PPT截图)

    一.为什么叫MapReduce? Map是以一条记录为单位映射 Reduce是分组计算

  2. open函数的打开标志所在文件

    /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h

  3. [易学易懂系列|rustlang语言|零基础|快速入门|(10)|Vectors容器]

    [易学易懂系列|rustlang语言|零基础|快速入门|(10)] 有意思的基础知识 Vectors 我们之前知道array数组是定长,只可我保存相同类型的数据的数据类型. 如果,我们想用不定长的数组 ...

  4. 七、设备驱动中的阻塞与非阻塞 IO(二)

    7.2 轮询 7.2.1 介绍 在用户程序中的 select() 和 poll() 函数最终会使设备驱动中的 poll() 函数被执行. 设备驱动程序中的轮询函数原型: /** 用于询问设备是否可以非 ...

  5. NJU 操作系统实验三

    实验描述: 代码实现: 链接:https://pan.baidu.com/s/1so3-XsvWBY9ZDbINob6qCw 提取码:8hhe

  6. SSM三大框架详细整合流程

    1.基本概念 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One  ...

  7. vue 无缝滚动文字

    前言 用vue做无缝滚动,字体弹幕 就上代码吧 <head> <meta charset="UTF-8"> <style> div, ul, l ...

  8. 【UOJ#450】[集训队作业2018] 复读机

    题目链接 题目描述 群里有\(k\)个不同的复读机.为了庆祝平安夜的到来,在接下来的\(n\)秒内,它们每秒钟都会选出一位优秀的复读机进行复读.非常滑稽的是,一个复读机只有总共复读了\(d\)的倍数次 ...

  9. python导入包失败ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

    最近在看 python,在使用matplotlib进行绘图时,提示:ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplot ...

  10. vue学习-day05 -- 案例:名字合并(监听data数据的改变)

    1.案例:名字合并(监听data数据的改变) 使用keyup事件监听data数据的改变 <!DOCTYPE html> <html> <head> <titl ...