flask-profiler, 监视端点调用并尝试进行某些分析的Flask 事件探查器
- 源代码名称:flask-profiler
- 源代码网址:http://www.github.com/muatik/flask-profiler
- flask-profiler源代码文档
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 事件探查器的更多相关文章
- 【转】SQL Server 2008 事件探查器(SQL SERVER Profiler)
跟踪数据库sql语句的执行情况.例:一个系统,用到了sql server 数据库,这个系统共有500张表,当用户在前台页面做某一个操作时,比如插入,登录等等,我们想知道此刻是在对哪一张表操作,打开事件 ...
- SQL Server 2008 事件探查器(SQL SERVER Profiler)
要想很好地优化ERP系统,可以从客户端.服务器.网络等入手,对于我们M1系统的优化来说,SQL 语句的优化就起到很重要的作用了.为此,我们展开,学习了SQL SERVER 2008的事件探查器(SQL ...
- SQL Server 2008 R2 找不到 Install SQL Server Profiler 找不到 事件探查器 解决
摘自: http://blog.csdn.net/yuxuac/article/details/8992893 SQL Server 2008 R2 Express Edition - Install ...
- Flask框架 (四)—— 请求上下文源码分析、g对象、第三方插件(flask_session、flask_script、wtforms)、信号
Flask框架 (四)—— 请求上下文源码分析.g对象.第三方插件(flask_session.flask_script.wtforms).信号 目录 请求上下文源码分析.g对象.第三方插件(flas ...
- 除了信号触发线程与接收者线程相同的情况能直接调用到slot,其它情况都依赖事件机制(解决上面代码收不到信号的问题其实很简单,在线程的run();函数中添加一个事件循环就可以了,即加入一句exec();),信号槽不就是一个回调函数嘛
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { pThreadCon = new CSerialThread ...
- Unity-自定义事件派发器的两次尝试
一.前言: 在游戏开发的很多时候,需要引用其他类的方法,但是一旦类多起来了,相互引用会导致引用关系混乱,极其难以阅读. 以前初次做抖音小游戏时,和一位经验老道的cocos程序员合作,看到我写的代码他不 ...
- SQL server Profiler 监视数据库活动
做网站后台开始时需要考虑后台对数据库的一些操作,比如尽量减少查询次数,尽快释放连接,只选取必须的字段等等.如果是用三层开发,复杂的项目中直接拼装SQL语句多一点,拼装的SQL语句可以直接在SQL se ...
- Tools-->SQL Server Profiler监视数据库
http://www.cnblogs.com/lorking/p/4062787.html https://docs.microsoft.com/en-us/sql/tools/sql-server- ...
- SQL2005 : 如何在SQL Server Profiler (事件查看器)中 跟踪查看死锁恢复
SQL Profiler 通过 SQL Profiler 工具程序,可监控应用程序如何访问数据库引擎.普通来说,当系统性能需要优化或是应用程序对数据库访问的结果不合预期,都可以使用该工具确认视图问题所 ...
随机推荐
- CentOS7 minimal安装初始化配置
个人喜好最小化安装系统,需要配置的如下信息 1.更改网络配置为固定ip #vi /etc/sysconfig/network-scripts/ifcfg-eth0BOOTPROTO="sta ...
- Q1:spring-boot中Controller路径无法被访问的问题
在学习spring-boot入门的第一个例子就是spring-boot-web的一个在页面上输出hello-world的例子,在运行这个例子的时候我遇到了下面这个简单的问题,但是第一次解决还是花了我很 ...
- linux shell鼠标键盘快捷键
- CentOS 7安装MySQL 8——萌新超详细教程
1.配置MySQL 8.0的安装源: sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.n ...
- http.sys_DDos攻击(ms15-043)
远程执行代码漏洞存在于HTTP协议堆栈(HTTP.sys)中,当HTTP.sys未正确分析经特殊设计的HTTP请求时会导致该漏洞.该漏洞利用成功可使目标机器蓝屏. 微软官方说明: https://do ...
- Console Add Item –Java使用eBay API SDK刊登商品 详解
准备工作: 1. 运行Eclipse (或其他Java IDE) 2.创建一个ConsoleAddItem工程(项目) 选JDK 1.5.1.6.1.8等版本,已测试1.6.1.8版本. 3.下载JA ...
- ZROI 19.08.10模拟赛
传送门 写在前面:为了保护正睿题目版权,这里不放题面,只写题解. A \(20pts:\) 枚举操作序列然后暴力跑,复杂度\(O(6^n)\). \([50,80]pts:\) 枚举改成dfs,每层操 ...
- 轻松获取LAMP,LNMP环境编译参数配置
轻松获取LAMP,LNMP环境编译参数配置 作者:Mr.Xiong /分类:系统管理 字号:L M S 大家是否遇到过去了新公司,公司内的LAMP,LNMP等所有的环境都是配置好的(已经在提 ...
- Hive 中的 LEFT SEMI JOIN 与 JOIN ON
hive 的 join 类型有好几种,其实都是把 MR 中的几种方式都封装实现了,其中 join on.left semi join 算是里边具有代表性,且使用频率较高的 join 方式. 1.联系 ...
- HBase 权限控制
HBase的权限管理依赖协协处理器.所以我们需要配置hbase.security.authorization=true,以及hbase.coprocessor.master.classes和hbase ...