Flask Web应用程序的Prometheus度量
flask-prometheus-metrics的Python项目详细描述
量度瓶普罗米修斯
Prometheus Flask Web应用程序的度量导出器。
flask_prometheus_metrics
使用官方Prometheus Python Client
提供有关流程资源使用、应用程序请求度量和信息的基本度量。
安装
pip install -U flask_prometheus_metrics
您需要Flask
来运行下面的示例:
pip install -U 'flask_prometheus_metrics[flask]'
用法
在python shell中运行以下最小示例:
fromflaskimportFlaskfromprometheus_clientimportmake_wsgi_appfromwerkzeug.middleware.dispatcherimportDispatcherMiddlewarefromwerkzeug.servingimportrun_simplefromflask_prometheus_metricsimportregister_metricsapp=Flask(__name__)@app.route("/")defindex():return"Test"# provide app's version and deploy environment/config name to set a gauge metricregister_metrics(app,app_version="v0.1.2",app_config="staging")# Plug metrics WSGI app to your main app with dispatcherdispatcher=DispatcherMiddleware(app.wsgi_app,{"/metrics":make_wsgi_app()})run_simple(hostname="localhost",port=5000,application=dispatcher)
然后浏览http://localhost:5000/
,刷新页面几次并检查
应用程序在http://localhost:5000/metrics
的度量。
另见example.py 在实际烧瓶应用程序中使用库的更详细示例。
指标
flask_prometheus_metrics
公开以下应用程序度量:
app_request_latency_seconds
(直方图)-应用程序请求延迟app_request_count_total
(计数器)-应用程序请求计数app_version_info
(仪表)-应用程序版本
库还提供了一些关于所使用的python解释器和进程的度量 资源使用:
python_gc_objects_collected_total
(counter)-在gc期间收集的对象python_gc_objects_uncollectable_total
(counter)-在gc期间发现无法收集的对象python_gc_collections_total
(counter)-收集此生成的次数python_info
(规范)-python平台信息process_virtual_memory_bytes
(规范)-虚拟内存大小(字节)process_resident_memory_bytes
(规范)-常驻内存大小(字节)process_start_time_seconds
(gauge)-自unix纪元以来进程的开始时间(秒)process_cpu_seconds_total
(counter)-总用户和系统CPU时间(秒)process_open_fds
(gauge)-打开的文件描述符数
Grafana仪表板
由flask_prometheus_metrics
导出的度量可以由
Prometheus监视系统,然后在
Grafana。
您可以下载专门为flask_prometheus_metrics
设计的grafana仪表板。
默认度量值here。
测试
使用DispatcherMiddleware
测试烧瓶应用程序时(请参阅上面的使用示例)
您可能需要使用little hack
为了使烧瓶的test_client()
正常工作。
历史记录
v1.0.0(2019-06-06)
- 库已准备好生产
- 次要setup.py修复(12)
V0.7.0(2019-06-06)
- readme.md已调整为在github和pypi上都能工作(11)
V0.6.2(2019-06-06)
- 添加了codeChimate集成
V0.6.1(2019-06-06)
- Travis CI配置已修复
v0.6.0(2019-06-06)
- 添加了详细说明的自述文件和更改日志
V0.5.0(2019-06-06)
- 添加changelog.md
V0.4.0(2019-06-06)
- 导入简化的度量值注册功能
V0.3.1(2019-06-05)
- 次要CI配置修复程序
V0.3.0(2019-06-05)
- 添加了依赖项版本和安全检查
V0.2.1(2019-06-01)
- 更新自述文件中的安装示例
V0.2.0(2019-06-01)
- 添加了自述文件,一些代码重构
V0.1.2(2019-06-01)
- 版本碰撞
V0.1.1(2019-06-01)
- 包版本控制修复程序
V0.1.0(2019-06-01)
- MVP