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. 四、Signalr手持令牌验证

    一.JWT 服务端在respose中设置好cookie,浏览器发请求都会自动带上,不需要做额外设置 但是如果客户端是非浏览器,或者要兼容多种客户端,这个方法就不行了 Js端 @{ Layout = n ...

  2. 009-通过jmx监控tomcat

    前言想理解怎么监控tomcat,必需识下图(图片源出网络) zabbix-Web前端界面,它通过数据库里数据展示.和其它组件不直接关联zabbix-server运行在10051端口,Zabbix-se ...

  3. linux 下shell中if的“-e,-d,-f”的用法

    文件表达式-e filename 如果 filename存在,则为真-d filename 如果 filename为目录,则为真 -f filename 如果 filename为常规文件,则为真-L ...

  4. JS获取当前日期和时间的方法,并按照YYYY-MM-DD格式化

    Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear(); ...

  5. pikachu-xss和csrf

    简介 XSS是一种发生在Web前端的漏洞,所以其危害的对象也主要是前端用户 XSS漏洞可以用来进行钓鱼攻击.前端js挖矿.盗取用户cookie,甚至对主机进行远程控制 攻击流程 假设存在漏洞的是一个论 ...

  6. Python 3标准库第四章

    第四章日期和时间-----------------    不同于int.float和str,Python没有包含对应日期和时间的原生类型,不过提供了3个相应的模块,可以采用多种表示来管理日期和时间值. ...

  7. F12谷歌开发者工具preserve log

    谷歌开发者工具里面这个preserve log :保留请求日志,跳转页面的时候勾选上,可以看到跳转前的请求,也可适用于chrome开发者工具抓包的问题

  8. layui 源码解读(部分)

    <!DOCTYPE html> <head> </head> <body> <input type="button" id=& ...

  9. mysql 普通用户与权限

    1.创建用户 mysql> create user 'myself'@'%' identified by 'Myself'; Query OK, 0 rows affected mysql> ...

  10. Codeforces 962D Merge Equals ( 模拟 )

    题意 : 给出一个序列,然后每次将重复出现的元素进行求和合并(若有多个,则优先取最小的进行合并),若某重复元素有很多,那么取最左边的那两个进行合并且合并后元素位于原来右边元素的位置,例如 3 2 6 ...