当前位置:网站首页>Prometheus Flask exporter使用示例
Prometheus Flask exporter使用示例
2022-06-21 10:24:00 【rs勿忘初心】
1、基本介绍
prometheus-flask-exporter该库提供flask应用的http请求度量,可以导出数据到Prometheus,它还可以使用方便的函数跟踪方法调用。
2、安装
参考官网说明:prometheus-flask-exporter · PyPI
pip3 install prometheus-flask-exporter3、完整的示例
如果直接看官网说明,你可能会觉得一下子不太好理解,下面我们基于一个完整的示例来看下,效果图:

代码完整示例参考:(prometheus_flask_exporter/examples/sample-signals/)prometheus_flask_exporter/examples/sample-signals at master · rycus86/prometheus_flask_exporter · GitHubPrometheus exporter for Flask applications. Contribute to rycus86/prometheus_flask_exporter development by creating an account on GitHub.
https://github.com/rycus86/prometheus_flask_exporter/tree/master/examples/sample-signals
进入对应代码目录:
cd ./prometheus_flask_exporter-master/examples/sample-signals看下目录结构,其实也比较清晰。
$ tree
.
├── README.md
├── app # flask的在线服务
│ ├── Dockerfile
│ ├── app.py
│ └── requirements.txt
├── dashboard.png
├── docker-compose.yml # docker-compose启动文件
├── generator # 模拟访问flask在线服务接口
│ ├── Dockerfile
│ ├── generate_events.py
│ └── requirements.txt
├── grafana # grafana可视化配置
│ ├── config.ini
│ ├── dashboard.yaml
│ ├── dashboards
│ │ └── example.json
│ └── datasource.yaml
└── prometheus # prometheus配置(推拉数据配置)
└── config.yml废话不多说 ,我们直接启动所有的服务,为了方便,我们直接使用Mac笔记本本地的docker启动:
# 在./examples/sample-signals目录,执行如下命令
docker-compose up -d正常情况下,我们从启动日志可以看到,先通过本地对应目录的Dockerfile制作了2个镜像:sample-signals_app、sample-signals_generator,然后从远程拉取了2个官方镜像:grafana/grafana、prom/prometheus,从docker images命令其实也可以看到这4个镜像:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
......
sample-signals_generator latest 3b6b2676efdf 53 minutes ago 54.4MB
sample-signals_app latest 65762cc8002b 54 minutes ago 56.7MB
......
grafana/grafana 5.1.0 ed6c9eb28b01 4 years ago 238MB
prom/prometheus v2.2.1 cc866859f8df 4 years ago 113MB
......接下来,我们看看这几个镜像的运行状态情况:

最后通过本地浏览器打开:http://localhost:3000/d/_eX4mpl3,预期效果如上文的示例图,主要统计了9种场景的数据(./sample-signals/grafana/dashboards/example.json),指标详细说明参考:README.md

到这里,只能说有一个感官的认识,具体的细节还需要下面多花时间研究 。
边栏推荐
猜你喜欢

Xidian AI ranked higher than Qingbei in terms of AI major, and Nantah ranked first in China in terms of Software Science in 2022

程序員新人周一優化一行代碼,周三被勸退?
![leetcode:715. Range module [brainless segmenttree]](/img/70/6cfb071bb08b30945c31c4947d2cef.png)
leetcode:715. Range module [brainless segmenttree]

Optimisation des performances - compression, chargement et formatage des images

New programmers optimize a line of code on Monday and are discouraged on Wednesday?

Starting a prairie fire, Alibaba cloud database "hundred cities gather together" to help small and medium-sized enterprises' digital intelligence transformation

还在直接用localStorage么?全网最细:本地存储二次封装(含加密、解密、过期处理)

One line of code accelerates sklearn operations thousands of times

性能优化——图片压缩、加载和格式选择

Where is the cow in Shannon's information theory?
随机推荐
Uni app advanced creation component / native rendering [Day9]
New programmers optimize a line of code on Monday and are discouraged on Wednesday?
Es composite query workload evaluation
异常
About Alipay - my savings plan - interest rate calculation instructions
WCF RestFul+JWT身份验证
Talk about the multimodal project of fire
110. JS event loop and setimmediate, process.nexttick
K-means introduction
Ccs7.3 how to erase only part of the flash sector when burning DSP on-chip flash (two projects of on-chip flash burning of a DSP chip)
国金证券开户安全吗?
115. secondary packaging of table components
Unity VUFORIA 推荐设备
DSP online upgrade (3) -- how to burn two projects in the on-chip flash of a DSP chip
Unity vuforia recommended equipment
Matplotlib 绘制圆环图的两种方法!
【云驻共创】企业数字化加速“新智造”
Underlying principle of Concurrency: thread, resource sharing, volatile keyword
嵌入式远程岗位、兼职、接单、众包平台
Eureka的TimedSupervisorTask类(自动调节间隔的周期性任务)