搬运内容
编写 exporter
如 Locust 的官方文档所介绍的 Extending Locust 我们可以扩展 web 端的接口,比如添加一个 /export/prometheus 接口,这样 Prometheus 根据配置定时来拉取 Metric 信息就可以为 Grafana 所用了。这里需要使用 Prometheus 官方提供的 client 库,prometheus_client,来生成符合 Prometheus 规范的 metrics 信息。
在 boomer 原文件的基础上我做了一些修改和优化,在 Readme 中添加了 Exporter 的说明,并提交 Pull Request。由于篇幅原因这里不展示代码了,完整代码(基于 Locust 1.x 版本)可以查看这里prometheus_exporter
转化成自己的理解:
- 在locust项目中,添加prometheus_exporter.py,内容详见上面git
- 查看 http://localhost:8089/export/prometheus
- 普罗米修斯配置文件中添加:
- job_name: locust
metrics_path: '/export/prometheus'
static_configs:
- targets: ['***.***.***.***:8089']
labels:
instance: locust
4.grafana数据源添加
5.导入12081模版
6.模版选择刚添加的数据源
即可
遇到的问题: