python tornado使用流生成图片
来源:互联网 发布:谁搞过自己的妈妈知乎 编辑:程序博客网 时间:2024/05/19 18:38
监控中,通常要使用图片更直观的看出集群的运行状况。
以下是一个简单的demo,通过rrdtool生成动态的图片。Python3, tornado.
web.py
templates/index.html
import tornado.ioloopimport tornado.webimport osimport ioimport osfrom PIL import Imagefrom tornado.options import define, options, parse_command_linefrom tornado.web import RequestHandlerclass PicHandles(RequestHandler): def get(self): id = self.get_argument('id') pic = open('F:/soft_bak/'+id+'.png', 'rb') pics = pic.read() self.write(pics) self.set_header("Content-type", "image/png")class GetPicHandles(RequestHandler): def get(self): self.render("index.html")def create_rrdtool_pic(): # os.system("/usr/bin/rrdtool graph /tmp/a.png --start '-3600s' --end now --width 400 --height 100 --title ' Grid Grid last hour last hour' --vertical-label load_one --slope-mode DEF:'sum'='/var/lib/ganglia/rrds/cluster/__SummaryInfo__/load_one.rrd:sum':AVERAGE AREA:'sum'#555555:' ' CDEF:sum_pos=sum,0,LT,0,sum,IF VDEF:sum_last=sum_pos,LAST VDEF:sum_min=sum_pos,MINIMUM VDEF:sum_avg=sum_pos,AVERAGE VDEF:sum_max=sum_pos,MAXIMUM GPRINT:'sum_last':'Now\:%7.2lf%s' GPRINT:'sum_min':'Min\:%7.2lf%s' GPRINT:'sum_avg':'Avg\:%7.2lf%s' GPRINT:'sum_max':'Max\:%7.2lf%s\l' ") img = Image.open("F:/soft_bak/a.png") return img, ""class GenPicHandler(tornado.web.RequestHandler): def get(self, *args, **kwargs): imgio=io.BytesIO() img,code=create_rrdtool_pic() img.save(imgio,'PNG') self.set_header('Content-Type', 'image/png') self.write(imgio.getvalue())define('port', default = 9900, type = int,)def main(): parse_command_line() app = tornado.web.Application( [ (r"/pic", PicHandles), (r"/getPic", GetPicHandles), (r"/getGenPic", GenPicHandler), ], debug=True, default_host="0.0.0.0", template_path=os.path.join(os.path.dirname(__file__), "templates") ) app.listen(options.port) tornado.ioloop.IOLoop.instance().start()if __name__ =='__main__': main()
<!DOCTYPE html><html> <head><title>Poem Maker Pro</title></head> <body> <a href="./pic?id=aa"> <img src="./pic?id=a" alt="{$source.name} NETWORK" border="0" /> </a> </body></html>
阅读全文
0 0
- python tornado使用流生成图片
- Python Tornado 使用经验
- python tornado模板使用
- 使用Python生成Excel格式的图片
- python tornado
- Python tornado
- python3用pillow生成验证码,tornado中输出图片
- Tornado使用
- 使用python构建httpserver,python+tornado+pika+rabbitmq
- Python生成数字图片
- python 生成字符图片
- Python--Python Tornado 介绍
- Python下使用qrcode模块生成vCard电子名片二维码图片
- 使用python生成excel格式的图片
- 使用python调用zxing库生成二维码图片
- Python中使用Threads和Queue给tornado添加客户端
- [零基础学python]使用tornado表单和模板
- [零基础学python]使用tornado表单和模板
- XXX cannot be resolved to a type
- ffmpeg录制usb摄像头和alsa音频出现ALSA buffer xrun.
- 第十一周 项目4 — 利用遍历思想求解图问题(7)
- spring boot 打包从jar转换成war
- __new__ 实例化子类
- python tornado使用流生成图片
- 思维导图之鱼骨图的实际应用
- 解读flow-guided feature aggregation for video object detection
- iphoneX兼容记录
- 关于--Error: User Command terminated, Exit-Code = 1解决办法
- 检查Logic Java 课程最近一次考试。如果全部没有通过考试(60分及格),则认为本次考试偏难,计算该次考试平均分加5分。
- SpringBoot的文件下载
- VR
- dreamweaver CC 快捷键