烧瓶框架的api端点分析器

flask_profiler的Python项目详细描述


#烧瓶轮廓仪


**版本:1.8**[![构建状态](https://travis-ci.org/muatik/flask-profiler.svg?branch=master)(https://travis ci.org/muatik/flask profiler)


flask profiler测量烧瓶应用程序中定义的端点;并通过Web界面为您提供细粒度的报告。

它回答了这些问题:
*我的应用程序中的瓶颈在哪里?
*哪些端点是我的应用程序中最慢的端点?
*哪些是最常用的端点?
*是什么导致我的端点速度慢?在哪种情况下,他们用什么参数和夸尔格来慢?
*一个特定的请求需要多长时间?

简而言之,如果您对端点正在执行的操作和它们正在接收的请求感到好奇,请尝试使用Flask Profiler。

通过深入筛选,您可以监视所有终结点的性能并调查终结点和接收到的请求。


[alt text](resources/dashboard_screen.png?raw=true"仪表板视图")


您可以创建筛选器来调查特定类型的请求。

![替换文本](resources/filtering_all_screen.png?raw=true"按端点筛选")

![alt text](resources/filtering_method_screen.png?raw=true"按方法筛选")

您可以查看请求的所有详细信息。
![alt text](resources/filtering_detail_screen.png?raw=true"请求详细信息")

\quick start
通过一个示例可以很容易理解烧瓶轮廓仪。让我们开始吧。

pip安装烧瓶分析器。
``sh
pip安装烧瓶分析器
````



=烧瓶(烧瓶名称
app.config["debug"]=true


"basicauth":{
"enabled":true,
"username":"admin",
"password":"admin"
},
"ignore":[
"^/static/*"
]
}



@app.route('/product/<;id>;',methods=['get'])
def getproduct(id):
return"产品id"是"+str(id)


@app.route('/product/<;id>;',methods=['put'])
def updateproduct(id):
return"正在更新产品{}"。format(id)



@app.route('/products',methods=['get'])
def listproducts():
返回"假设我向您发送了产品列表…"

@app.route('/static/something/',methods=['get'])
def listproducts():
返回"不应跟踪…"

必须将flask
app作为参数传递给flask profiler。
烧瓶轮廓仪。
@app.route('/dosomething',methods=['get'])
def dosomething():
return"烧瓶轮廓仪不会测量这个。"




方法=['get'])
@flask\u profiler.profile()
def dosomethingimportant():
返回"flask profiler将测量此请求。"

端口=5000)


````


put-d arg1=val1 http://127.0.0.1:5000/product/123
````

如果一切正常,Flask Profiler将测量这些请求。您可以看到结果标题http://127.0.0.1:5000/flask profiler/或以json http://127.0.0.1:5000/flask profiler/api/measurements获得结果?sort=elapsed,desc

例如:

`` python
from flask import flask
from flask廑profiler import profiler



app.config["debug"]=true

如下:
app.config["烧瓶档案器"]={
"已启用":app.config["调试"],
"存储":{
"引擎":"sqlite"
},
"basicauth":{
"已启用":true,
"用户名":"admin",
"密码":"admin"

"ignore":[
"^/static/*"
]
}


profiler=profiler();您可以在另一个模块中使用此功能
profiler.init廑app(app)
;或者仅在profiler(app)

@app.route('/product/<;id>;',methods=['get'])
def getproduct(id):
return"产品id"是"+str(id)

```


但是,它很容易支持其他数据库系统。如果你想有其他人,请去捐款文件。(这很简单。)


\sqlite
要使用sqlite,只需将其指定为"storage.engine"指令的值,如下所示。

``json
app.config["flask\u profiler"]={
"storage":{
"engine":"sqlite",
}
}
````

下面列出了其他选项。


reside measurements


}
}
````

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

``python
app.config["flask_profiler"]={
"storage":{
"engine":"sqlalchemy",
"db_url":"postgresql://user:pass@localhost:5432/flask_profiler"可选,如果未指定数据库URL,则将使用sqlite。
}
}
}
````

```json
``app.config["flask\u profiler"]={
"storage":{
"engine":"custom.project.flask_profiler.mysql.mysqlstorage",
"mysql":"mysql://user:password@localhost/flask戋profiler"
}
}
````

>下面列出了其他选项。

|mongodb://localhost
storage.database database name flask_profiler
storage.collection collection name measurements

sampling
控制flask profiler采集的样本数

在生产模式下运行时采样。
您可以提供一个函数,并根据您的业务逻辑控制采样。

随机数
`` python
app.config["flask_profiler"]={
"sampling_function":lambda:true if random.sample(list(range(1,101)),1)=[42]else false
}
```


示例2:特定用户的示例
``python
app.config["flask_profiler"]={
"sampling_function":lambda:如果用户是'divyendu',则为true else false
```

将对所有请求进行采样。

更改烧瓶探查器终结根
默认情况下,我们可以在<;您的应用程序>;访问烧瓶探查器;/烧瓶探查器

`` python
app.config["烧瓶探查器"]={
"endpointroot":"秘密烧瓶探查器"
}
````

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

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




查看[贡献指南](https://github.com/muatik/flask-profiler/wiki/development)了解如何:

*提交问题
*为现有挑战添加解决方案
*添加新挑战

ATik](https://www.linkedin.com/in/muatik)
*fatih sucu
*[safa yasin yildirim](https://www.linkedin.com/in/safayasinyildirim)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JPanel不会对键绑定做出反应   当时间大于零时,不得在UI线程上调用java Await   JTextArea的java线程安全。追加   Java用户输入的字和行计数器   java以spreedsheat格式将数据保存到文件中   java构造函数的意义是什么?   java findViewById返回null,尽管组件的ID存在   java如何向按钮添加图像   java如何中断ExecutorService的线程   java如何将属性(例如枚举)绑定到不同类型的组件属性(例如每个枚举的映像)?   随机森林分类器的java实现   html使用java连接到一个站点并发布,HTTP状态代码200   从类访问属性时发生java编译错误   Java自动填充ArrayList,搜索更好的选项