交互页面:https://plot.ly/~raywill/0/
做负载均衡的调优,需要把负载画出来看效果,使用了 plot.ly,实乃神器!
plot.ly 最大的特色是会把数据发到服务器,通过 web 完成渲染,形成可交互的图表。利用 plot.ly 写代码非常简单:
import MySQLdb
import plotly.plotly as py
from plotly.graph_objs import *
import pandas as pd
conn = MySQLdb.connect(host="127.0.0.1",port=3306,user="root", passwd="", db="oceanbase")
cursor = conn.cursor()
units = []
for unit_id in [1001, 1002, 1003, 1004, 1005, 1006]:
cursor.execute('select gmt_create time, `load`, `disk_weight`, `disk_usage_rate` from __all_unit_load_history where unit_id = %d order by gmt_create limit 10000000' % (unit_id));
rows = cursor.fetchall()
df = pd.DataFrame( [[ij for ij in i] for i in rows] )
df.rename(columns={0: 'time', 1: 'load', 2: 'disk_weight', 3: 'disk_usage_rate'}, inplace=True);
unit0 = Scatter(
x=df['time'],
y=df['load'],
)
unit1 = Scatter(
x = df['time'],
y = df['disk_weight'],
)
unit2 = Scatter(
x = df['time'],
y = df['disk_usage_rate'],
)
units.append(unit0)
layout = Layout(
xaxis=XAxis( title='time'),
yaxis=YAxis( title='value', range=[0,1] )
)
data = Data(units)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='world')
print plot_url
note: 因为数据需要发往服务器,可以衍生出各种收费模式。