<jupyter_start><jupyter_text>**扩展Jupyter访问阿里云日志服务**  配置日志服务Jupyter扩展 - 安装配置请参考：https://yq.aliyun.com/articles/689911<jupyter_code>%reload_ext aliyun.log.ext.jupyter_magic
%manage_log cn-hangzhou.log.aliyuncs.com a b dashboard-demo ddos-access-log
%manage_log<jupyter_output><empty_output><jupyter_text>%log查询，默认过去15分钟<jupyter_code>%log host: www.aa.mock-domain.com | select ip_to_province(real_client_ip) as province, count(1) as pv group by province order by pv desc

type(log_df)
log_df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 18 entries, 0 to 17
Data columns (total 2 columns):
province    18 non-null object
pv          18 non-null object
dtypes: object(2)
memory usage: 368.0+ bytes<jupyter_text>%%log查询，配置时间<jupyter_code>%%log -1day ~ now
* | 
select date_format(date_trunc('hour', __time__), '%H:%i') as dt,  
        count(1)%100 as pv, 
        round(sum(if(status < 400, 1, 0))*100.0/count(1), 1) AS ratio
        group by date_trunc('hour', __time__) 
        order by dt limit 1000
%log host: www.aa.mock-domain.com<jupyter_output>变量名：log_df<jupyter_text>%fetch全量拉取<jupyter_code>%fetch 2019-1-31 10:0:0+8:00 ~ 2019-1-31 10:00:10+8:00<jupyter_output>变量名：log_df<jupyter_text>返回Dataframe，无缝衔接PyData计算<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (12, 9)
import seaborn as sns
%log host: www.a?.mock* | select body_bytes_sent, host limit 100000
log_df['body_bytes_sent'] = log_df['body_bytes_sent'].astype(int)
sns.boxenplot(x='host', y='body_bytes_sent', data=log_df);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13639220615964803, 'fraction_numerical': 0.05216844751728473, 'mean_word_length': 6.203619909502263, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '565934', 'license': 'MIT', 'n_tokens_mistral': 746, 'n_tokens_neox': 700, 'n_words': 114, 'path': 'tests/jupyter_magic_test/magic_ext_usage_demo.ipynb', 'repo_name': 'lichengseu/aliyun-log-python-sdk', 'size': '1591'}