prometheus 数据生成报表输出到 docx
文章目录
1. 环境依赖
首先
npm install -g phantomjs-prebuilt
笔者 python 2.7.15 的环境,python requirements 如下:
jinja2>=2.8
future
lml>=0.0.2
jupyter-echarts-pypkg>=0.1.1
pyecharts-javascripthon
pyecharts-snapshot==0.1.10 # > 0.1.10 以上版本仅支持python 3+
pyecharts==0.5.10 # pyecharts v1 版本仅支持python 3.6+
2. 了解 docx 的结构
推荐两篇文章:
- https://www.cnblogs.com/zhanghongfeng/p/7043412.html
- https://blog.csdn.net/qwe125698420/article/details/70622289?locationNum=3&fps=1
研究发现docx与xml关系密切,所以我们以xml为模板,最后从xml转换为docx文件
3. 我的模板
使用docx文件创建模板,另存为xml文件
4. 获取 prometheus 数据
利用 prometheus 提供的 http 查询方式获取一组待分析数据。
def get_prom_data():
url = ("http://{host}:{port}/api/v1/query_range?query=ping_delay<peer='{peer}',"
"source='{source}'>&start={start_time}&end={end_time}&step=14")
end_time = time.time()
start_time = end_time - 3600 # 取 1小时数据
qyery_url = url.format(host="xx", port="xx", peer=