标签:统计 count 查看 文档 如何 sql art 数据采集 nginx
阿里云日志服务是针对日志类数据的一站式服务,您只需要将精力集中在日志分析上,过程中数据采集、对接各种存储计算、数据索引和查询等其他工作都可以通过配置日志服务来自动完成。cd /var/lib/grafana/plugins/
git clone https://github.com/aliyun/aliyun-log-grafana-datasource-plugin
systemctl restart grafana-server
? | select approx_distinct(client_ip) as uv, count(1) as pv, __time__ - __time__% 60 as time group by time order by time limit 1000
Y - column输入:pv,uv
X - column [time]输入:time
这块日志服务SQL语句,先确保能在阿里日志查询分析控制台能查询通过,有数据输出,无语法错误,否则在Grafana无数据图形显示。
说明:
approx_distinct(client_ip):估算 client_ip 列的唯一值的个数。__time__
:日志服务每条日志中内置的时间类型。灵活的时间维度统计,数学取模方法分组。__time_ - __time_ % 60
表示按1分钟进行取模,即1分钟跨度显示。
d. 在 Visualization 中,Grafana可以支持多重类型的视图。对于PV,UV数据,在标签栏中单击Graph,创建一个Graph视图。
e. General中Title修改该Panel的名称,这里统计PV、UV,相应的名称修改为PV、UV。
f. 最后一项Alert,暂时不设置报警通知,如果要设置报警通知,在该Panel中单击Create Alert。在Notifications配置报警通知。
4.2 配置出入网带宽
参考4.1 配置PV、UV,使用同样的方法添加出入网带宽的流量。
? | select sum(size) as net_out, sum(request_length) as net_in, __time__ -__time__% 60 as time group by time order by time limit 1000
Y - column输入:net_in,net_out
X - column [time]输入:time
4.3 不同HTTP方法的占比
? | select count(1) as pv, split_part(request,‘ ‘,1) as request group by request
Y - column输入:request,pv
X - column [time]输入:pie
4.4 不同HTTP状态码占比
? | select count(1) as pv, status group by status
Y - column输入:status,pv
X - column [time]输入:pie
4.5 热门来源页面
? | select count(1) as pv, referer group by referer order by pv desc limit 10
Y - column输入:referer,pv
X - column [time]输入:pie
4.6 延时最高页面
? | select split_part(request,‘ ‘,2) as top_latency_url, request_time group by top_latency_url,request_time order by request_time desc limit 20
Y - column输入:top_latency_url, request_time
X - column [time]保持为空。
4.7 热门页面
? | select count(1) as pv, split_part(request,‘ ‘,2) as path group by path order by pv desc limit 10
Y - column输入:path,pv
X - column [time]保持为空。
4.8 前后端平均延时
? | select avg(request_time) as response_time, avg(upstream_time) as upstream_response_time, __time__ -__time__% 60 as time group by time order by time limit 1000
Y - column输入:upstream_response_time,response_time
X - column [time]输入:time
4.9 客户端统计
? | select count(1) as pv, case when regexp_like(agent , ‘okhttp‘) then ‘okhttp‘ when regexp_like(agent , ‘iPhone‘) then ‘iPhone‘ when regexp_like(agent , ‘Android‘) then ‘Android‘ else ‘unKnown‘ end as agent group by agent order by pv desc limit 10
Y - column输入:agent,pv
X - column [time]输入:pie
4.10 各省份占比统计
? | select ip_to_province(client_ip) as province, count(1) as pv group by province HAVING ip_to_province(client_ip) <> ‘-1‘ order by pv desc limit 10
日志IP地理函数 ip_to_province(client_ip) 对无效IP,会返回”-1“。针对这块用 HAVING 过滤掉。
Y - column输入:province,pv
X - column [time]输入:pie
4.11 各城市占比统计
? | select ip_to_city(client_ip) as city, count(1) as pv group by city HAVING ip_to_city(client_ip) <> ‘-1‘ and ip_to_city(client_ip) <> ‘内网IP‘ order by pv desc limit 10
Y - column输入:city,pv
X - column [time]输入:pie
4.12 保存和发布Dashboard
单击页面上方的保存按钮,发布Dashboard。
标签:统计 count 查看 文档 如何 sql art 数据采集 nginx
原文地址:https://blog.51cto.com/10874766/2493451